From a0cee2c79e69925286891ebe827b377bb90c5309 Mon Sep 17 00:00:00 2001 From: "Le Gall, Benoit" Date: Thu, 15 Aug 2024 22:02:28 +0200 Subject: [PATCH] [workflows] separated workflows for push and prerelease/release --- .github/workflows/build.yml | 39 +++++++++++++++++++ .github/workflows/{ci_cd.yml => publish.yml} | 23 ++--------- ...ent.jreleaser.deploy-convention.gradle.kts | 7 ++-- 3 files changed, 47 insertions(+), 22 deletions(-) create mode 100755 .github/workflows/build.yml rename .github/workflows/{ci_cd.yml => publish.yml} (61%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100755 index 0000000..71b75be --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,39 @@ +name: Build and test code source + +env: + CI: true + +on: + push: + branches: [ "**" ] + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + checks: write + pull-requests: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: '21' + distribution: 'temurin' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3.1.0 + + - name: Compile & Test + run: ./gradlew test + + - name: Publish Unit Test Results + uses: EnricoMi/publish-unit-test-result-action@v2 + if: always() + with: + files: '**/test-results/**/*.xml' diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/publish.yml similarity index 61% rename from .github/workflows/ci_cd.yml rename to .github/workflows/publish.yml index 6e0bd96..41c245c 100755 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/publish.yml @@ -1,23 +1,18 @@ -name: Java CI with Gradle +name: Publish artifacts into Maven Central env: CI: true on: - push: - branches: [ "**" ] release: - types: [ created ] + types: [ prereleased, released ] jobs: - build: + publish: runs-on: ubuntu-latest permissions: contents: read - packages: write - checks: write - pull-requests: write steps: - name: Checkout @@ -32,23 +27,13 @@ jobs: - name: Setup Gradle uses: gradle/actions/setup-gradle@v3.1.0 - - name: Compile & Test - run: ./gradlew test - - - name: Publish Unit Test Results - uses: EnricoMi/publish-unit-test-result-action@v2 - if: always() - with: - files: '**/test-results/**/*.xml' - - name: Generate package - if: startsWith(github.ref, 'refs/heads/release/') || startsWith(github.ref, 'refs/tags/') run: ./gradlew publish - name: Deploy released package in MavenCentral - if: startsWith(github.ref, 'refs/heads/release/') || startsWith(github.ref, 'refs/tags/') run: ./gradlew jreleaserDeploy env: + DRY_RUN: ${{ github.event.release.prerelease }} JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.MAVENCENTRAL_USERNAME }} JRELEASER_MAVENCENTRAL_PASSWORD: ${{ secrets.MAVENCENTRAL_PASSWORD }} JRELEASER_GPG_PASSPHRASE: ${{ secrets.GNUPG_PASSPHRASE }} diff --git a/buildSrc/src/main/kotlin/com.frogdevelopment.jreleaser.deploy-convention.gradle.kts b/buildSrc/src/main/kotlin/com.frogdevelopment.jreleaser.deploy-convention.gradle.kts index 6cea4fc..d49448d 100644 --- a/buildSrc/src/main/kotlin/com.frogdevelopment.jreleaser.deploy-convention.gradle.kts +++ b/buildSrc/src/main/kotlin/com.frogdevelopment.jreleaser.deploy-convention.gradle.kts @@ -5,12 +5,12 @@ plugins { id("org.jreleaser") } -val releaseRegex = """^\d+\.\d+\.\d+$""".toRegex() - jreleaser { gitRootSearch = true dependsOnAssemble = true - dryrun = provider { !releaseRegex.matches(version.toString()) } + dryrun = providers.environmentVariable("DRY_RUN") + .map(String::toBoolean) + .orElse(true) project { copyright.set("FrogDevelopment") @@ -52,4 +52,5 @@ tasks { jreleaserSign { childProjects.forEach { child -> dependsOn(child.value.tasks.named("publish")) } } + }