From 32eb7cc8b67824ea8ef59a17fa0f48af8a6abab3 Mon Sep 17 00:00:00 2001 From: Calum Calder Date: Tue, 18 Feb 2025 15:39:26 +0000 Subject: [PATCH] ci: release without committing to main branch (#1434) Committing to the master branch isn't allowed from github actions because of our branch protection rules. There's no easy way to allow github actions to bypass this. As a workaround, skip all the parts of the release that needed to commit to the repo. This means moving the version config to an environment variable, which shouldn't be an issue, and using git tags as the source of truth. --------- Co-authored-by: Jonathan Zacsh --- .cz.toml | 5 +---- .github/workflows/release.yml | 22 +++++++++++++------ Documentation/Publishing.md | 7 +++--- build.gradle | 36 +------------------------------ gradle.properties | 1 - portability-transfer/build.gradle | 2 +- 6 files changed, 21 insertions(+), 52 deletions(-) diff --git a/.cz.toml b/.cz.toml index ea08c5770..9e77ea31d 100644 --- a/.cz.toml +++ b/.cz.toml @@ -3,8 +3,5 @@ name = "cz_conventional_commits" tag_format = "v$version" version_scheme = "semver" version_provider = "scm" -update_changelog_on_bump = true -version_files = [ - "gradle.properties:projectVersion=" -] +update_changelog_on_bump = false changelog_start_rev = "v1.0.0" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1a7f66aa7..f86b7cbaf 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,17 +17,24 @@ jobs: runs-on: ubuntu-latest name: "Bump version" outputs: - version: ${{ steps.cz.outputs.version }} + version: ${{ steps.tag.outputs.version }} steps: - uses: actions/checkout@v4 with: fetch-depth: 0 # Fetch tags, which are required to calculate the new version token: "${{ secrets.GITHUB_TOKEN }}" - - id: cz - name: "Generate Changelog and Tag" - uses: commitizen-tools/commitizen-action@master - with: - github_token: ${{ secrets.GITHUB_TOKEN }} + - name: "Install commitizen" + run: | + pip install --user -U commitizen && + cz version --verbose + - id: tag + name: "Release: Publish new semver Git Tag" + run: | + NEW_VERSION=$(cz bump --get-next) || exit 1 + TAG="v${NEW_VERSION}" + git tag "${TAG}" && + git push origin "${TAG}" --tags && + echo "version=${NEW_VERSION}" | tee -a "$GITHUB_OUTPUT" release: needs: bump_version runs-on: ubuntu-latest @@ -35,7 +42,7 @@ jobs: steps: - uses: actions/checkout@v4 with: - ref: ${{ needs.bump_version.outputs.version }} + ref: "v${{ needs.bump_version.outputs.version }}" - name: "Set up JDK" uses: actions/setup-java@v4 with: @@ -48,5 +55,6 @@ jobs: GRADLE_SIGNING_PASSWORD: "${{ secrets.GRADLE_SIGNING_PASSWORD }}" OSSRH_USERNAME: "${{ secrets.OSSRH_USERNAME }}" OSSRH_PASSWORD: "${{ secrets.OSSRH_PASSWORD }}" + RELEASE_VERSION: "${{ needs.bump_version.outputs.version }}" # Exclude client-rest as it's not part of the java release run: ./gradlew clean build sign uploadArchives --exclude-task :client-rest:uploadArchives diff --git a/Documentation/Publishing.md b/Documentation/Publishing.md index ae08d0360..d75e0fa26 100644 --- a/Documentation/Publishing.md +++ b/Documentation/Publishing.md @@ -14,7 +14,7 @@ The action contains two jobs; one to bump the version number of the DTP packages DTP uses [Semantic Versioning](https://semver.org/) for published packages. We also enforce [Conventional Commits](https://conventionalcommits.org/) on the `master` branch through the `.github/workflows/commitlint.yml` Github action, which lets us automatically calculate version numbers. -Commitizen is a tool that supports automatically incrementing SemVer version numbers based on git commit history. Our usage of Commitizen is configured in `.cz.toml`, and uses the `commitizen-tools/commitizen-action` Github action to automatically bump the package version number and to tag the new version in git. +Commitizen is a tool that supports automatically incrementing SemVer version numbers based on git commit history. Our usage of Commitizen is configured in `.cz.toml`, and is used in a Github action to automatically tag the new version in git and publish to maven (per "automated publishing" section of this doc). ### Automated Publishing @@ -38,7 +38,6 @@ If for some reason you need to publish manually, the steps are detailed below. ### 1. Setting properties First you must set the necessary properties in [gradle.properties](../gradle.properties). These are: - - `projectVersion` - this is the new version you wish to publish. - `ossrhUsername` & `ossrhPassword` - These are your Sonatype [User Token](https://central.sonatype.org/publish/generate-token/#generate-a-token-on-ossrh-sonatype-nexus-repository-manager-servers) credentials. Your account must have been granted publishing permissions. Permissions are managed manually by Sonatype - see [Sonatype's documentation](https://central.sonatype.org/register/legacy/) for details. - `signing.keyId` - The GPG key being used for signing the artifacts. (More information about setting up GPG keys can be found [here](https://central.sonatype.org/publish/requirements/gpg/)) - `signing.password` - The password for that GPG private key. @@ -48,10 +47,10 @@ If for some reason you need to publish manually, the steps are detailed below. Make sure that the artifacts are building and running correctly. For example run the worker in the Docker container, see [Running Locally](RunningLocally.md) for instructions. ### 3. Sign and upload -To sign and publish the artifacts run the following Gradle command: +To sign and publish the artifacts run the following Gradle command, replacing `` with the new version number: ``` -./gradlew sign uploadArchives --exclude-task :client-rest:uploadArchives +RELEASE_VERSION= ./gradlew sign uploadArchives --exclude-task :client-rest:uploadArchives ``` We exclude the client-rest archives as these are not a Java package. diff --git a/build.gradle b/build.gradle index 0ba989a05..98d486d06 100644 --- a/build.gradle +++ b/build.gradle @@ -75,7 +75,7 @@ configure(sourceProjects()) { apply plugin: 'idea' group = "${projectGroup}" - version = "${projectVersion}" + version = System.getenv('RELEASE_VERSION') sourceCompatibility = 11 @@ -111,40 +111,6 @@ configure(sourceProjects()) { } } -task bumpPatchVersion { - doLast { - println "Current version: ${projectVersion}" - def (major, minor, patch) = projectVersion.tokenize(['.-']) - setSnapshotVersion(major, minor, patch.toInteger() + 1) - } -} - -task bumpMinorVersion { - doLast { - println "Current version: ${projectVersion}" - def (major, minor, patch) = projectVersion.tokenize(['.-']) - setSnapshotVersion(major, minor.toInteger() + 1, patch) - } -} - -task bumpMajorVersion { - doLast { - println "Current version: ${projectVersion}" - def (major, minor, patch) = projectVersion.tokenize(['.-']) - setSnapshotVersion(major.toInteger() + 1, minor, patch) - } -} - -def setSnapshotVersion(major, minor, patch) { - def newVersion = "$major.$minor.$patch-SNAPSHOT" - - println "New version: ${newVersion}" - ant.propertyfile( - file: "gradle.properties") { - entry(key: "projectVersion", value: newVersion) - } -} - def addCloudExtensionDependency(proj) { proj.dependencies { compile project(":extensions:cloud:portability-cloud-${proj.rootProject.ext.cloudType}") } } diff --git a/gradle.properties b/gradle.properties index 384377511..d7ed9cdd0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,4 @@ projectGroup=org.datatransferproject -projectVersion=1.0.4 annotationApiVersion=1.2 autoValueVersion=1.9 commonsLangVersion=3.4 diff --git a/portability-transfer/build.gradle b/portability-transfer/build.gradle index 9a2dab8d2..bb113b8a7 100644 --- a/portability-transfer/build.gradle +++ b/portability-transfer/build.gradle @@ -21,7 +21,7 @@ plugins { } group = "${projectGroup}" -version = "${projectVersion}" +version = System.getenv("RELEASE_VERSION") description = """Portability Worker"""