From 3d5aa62d36ef247460bbe85a90c4fc6510df9195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Panuszewski?= Date: Mon, 25 Nov 2024 08:59:34 +0100 Subject: [PATCH] Allow regex patterns in releaseBranchNames (#864) --- .github/workflows/ci.yml | 11 ++++++++++- .github/workflows/publish.yml | 2 -- build.gradle.kts | 2 +- docs/configuration/overview.md | 4 ++-- docs/configuration/version.md | 4 ++-- .../tech/build/axion/release/ReleasePlugin.groovy | 3 ++- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a496c948..fda29cc5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,6 @@ name: Build -on: +on: pull_request: workflow_dispatch: push: @@ -31,3 +31,12 @@ jobs: uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} + + - name: Publish to staging repository + run: ./gradlew publishToSonatype currentVersion + env: + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }} + GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} + GPG_PRIVATE_KEY_PASSWORD: ${{ secrets.GPG_PRIVATE_KEY_PASSWORD }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index eb76d97d..d0f74f2c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -9,8 +9,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - with: - fetch-depth: 0 - name: Set up JDK uses: actions/setup-java@v4 with: diff --git a/build.gradle.kts b/build.gradle.kts index 9a24abd9..35a57728 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,7 +13,7 @@ plugins { } scmVersion { - versionCreator("versionWithBranch") + unshallowRepoOnCI.set(true) } group = "pl.allegro.tech.build" diff --git a/docs/configuration/overview.md b/docs/configuration/overview.md index 0e74261e..f0b4e793 100644 --- a/docs/configuration/overview.md +++ b/docs/configuration/overview.md @@ -76,7 +76,7 @@ All `axion-release-plugin` configuration options: // doc: Version / releaseOnlyOnReleaseBranches releaseOnlyOnReleaseBranches = false - releaseBranchNames = ['master', 'main'] + releaseBranchNames = ['master', 'main', 'release/.*'] } All `axion-release-plugin` configuration flags: @@ -117,4 +117,4 @@ All `axion-release-plugin` configuration flags: - only perform a release on branches that match the `releaseBranchNames` - release.releaseBranchNames - default: `['master', 'main']` - - a list of branch names that are considered release branches + - a list of regex patterns for release branch names diff --git a/docs/configuration/version.md b/docs/configuration/version.md index 9f524b90..d15ce14d 100644 --- a/docs/configuration/version.md +++ b/docs/configuration/version.md @@ -295,12 +295,12 @@ And works well in combination with `releaseBranchNames` option scmVersion { releaseOnlyOnReleaseBranches = true - releaseBranchNames = ['main', 'master'] + releaseBranchNames = ['main', 'master', 'release/.*'] } or as command line - ./gradlew release -Prelease.releaseOnlyOnReleaseBranches -Prelease.releaseBranchNames=main,release + ./gradlew release -Prelease.releaseOnlyOnReleaseBranches -Prelease.releaseBranchNames="main,master,release/.*" ## Decorating diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/ReleasePlugin.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/ReleasePlugin.groovy index f600320e..54160d68 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/ReleasePlugin.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/ReleasePlugin.groovy @@ -99,8 +99,9 @@ abstract class ReleasePlugin implements Plugin { def releaseOnlyOnReleaseBranches = context.scmService().isReleaseOnlyOnReleaseBranches() def releaseBranchNames = context.scmService().getReleaseBranchNames() def currentBranch = context.repository().currentPosition().getBranch() + def onReleaseBranch = releaseBranchNames.any { pattern -> currentBranch.matches(pattern) } - def shouldSkipRelease = releaseOnlyOnReleaseBranches && !releaseBranchNames.contains(currentBranch) + def shouldSkipRelease = releaseOnlyOnReleaseBranches && !onReleaseBranch if (shouldSkipRelease) { disableReleaseTasks(currentBranch, releaseBranchNames, project)