From b88138334d75704702cdf066d70cc8fcba33e17d Mon Sep 17 00:00:00 2001 From: Katherine Chen Date: Tue, 27 Feb 2024 15:15:48 +1100 Subject: [PATCH] UID2-2558 Use new commit and push workflow (#56) --- .github/workflows/release.yml | 50 ++++++++++++++++++++++++++++++-- scripts/get_snapshot_versions.sh | 20 +++++++++++++ scripts/release.sh | 42 --------------------------- 3 files changed, 67 insertions(+), 45 deletions(-) create mode 100755 scripts/get_snapshot_versions.sh delete mode 100755 scripts/release.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b6d3aeb..f37111f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,5 @@ name: Release +run-name: ${{ format('Release version {0}', inputs.version)}} by @${{ github.actor }} on: workflow_dispatch: @@ -17,11 +18,14 @@ jobs: runs-on: ubuntu-latest permissions: + pull-requests: write contents: write + security-events: write + packages: write steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up JDK 17 uses: actions/setup-java@v3 @@ -29,6 +33,13 @@ jobs: java-version: '17' distribution: 'temurin' + - name: Fail if Release and not on Default branch + if: ${{ github.event.repository.default_branch != github.ref_name }} + uses: actions/github-script@v7 + with: + script: | + core.setFailed('Releases can not be created on a feature branch. Branch: ${{ github.ref_name }}') + - name: Update Git user run: | git config --local user.name "IABTechLab" @@ -42,14 +53,47 @@ jobs: # Disable writing to cache. Don't want to spoil the main cache cache-read-only: true - - name: Release - run: ./scripts/release.sh ${{ inputs.version }} ${{ inputs.snapshot }} + - name: Get Snaptshot versions + id: snapshotVersions + run: ./scripts/get_snapshot_versions.sh ${{ inputs.snapshot }} + + - name: Prepare for release metadata + shell: bash + run: | + sed -i.bak "s/${{ steps.snapshotVersions.outputs.cur_snapshot_version }}/${{ inputs.version }}/g" gradle.properties + + - name: Commit gradle.properties and set tag for v${{ inputs.version }} + uses: IABTechLab/uid2-shared-actions/actions/commit_pr_and_merge@v2 + with: + add: 'gradle.properties' + message: 'Prepare for release: ${{ inputs.version }}' + tag: v${{ inputs.version }} + + - name: Deploy v${{ inputs.version }} + run: ./gradlew publish env: ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_REPO_USERNAME }} ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_REPO_PASSWORD }} ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEY }} ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_PASSPHRASE }} + - name: Prepare next Snapshot version ${{ steps.snapshotVersions.outputs.new_snapshot_version }} + shell: bash + run: | + echo "Setting next snapshot version ${{ steps.snapshotVersions.outputs.new_snapshot_version }}" + sed -i.bak "s/${{ inputs.version }}/${{ steps.snapshotVersions.outputs.new_snapshot_version }}/g" gradle.properties + + - name: Commit gradle.properties for Snapshot version ${{ steps.snapshotVersions.outputs.new_snapshot_version }} + uses: IABTechLab/uid2-shared-actions/actions/commit_pr_and_merge@v2 + with: + add: 'gradle.properties' + message: 'Prepare next development version: ${{ steps.snapshotVersions.outputs.new_snapshot_version }}' + + - name: Remove the backup file from sed edits + shell: bash + run: | + rm gradle.properties.bak + - name: GitHub Release uses: softprops/action-gh-release@v1 with: diff --git a/scripts/get_snapshot_versions.sh b/scripts/get_snapshot_versions.sh new file mode 100755 index 0000000..d33ed56 --- /dev/null +++ b/scripts/get_snapshot_versions.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +set -exo pipefail + +# Gets a property out of a .properties file +# usage: getProperty $key $filename +function getProperty() { + grep "${1}" "$2" | cut -d'=' -f2 +} + +NEW_SNAPSHOT_VERSION=$1 +CUR_SNAPSHOT_VERSION=$(getProperty 'VERSION_NAME' gradle.properties) + +if [ -z "$NEW_SNAPSHOT_VERSION" ]; then + # If no snapshot version was provided, use the current value + NEW_SNAPSHOT_VERSION=$CUR_SNAPSHOT_VERSION +fi + +echo "new_snapshot_version=$NEW_SNAPSHOT_VERSION" >> $GITHUB_OUTPUT +echo "cur_snapshot_version=$CUR_SNAPSHOT_VERSION" >> $GITHUB_OUTPUT diff --git a/scripts/release.sh b/scripts/release.sh deleted file mode 100755 index 243a09c..0000000 --- a/scripts/release.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env bash - -set -exo pipefail - -# Gets a property out of a .properties file -# usage: getProperty $key $filename -function getProperty() { - grep "${1}" "$2" | cut -d'=' -f2 -} - -NEW_VERSION=$1 -NEW_SNAPSHOT_VERSION=$2 -CUR_SNAPSHOT_VERSION=$(getProperty 'VERSION_NAME' gradle.properties) - -if [ -z "$NEW_SNAPSHOT_VERSION" ]; then - # If no snapshot version was provided, use the current value - NEW_SNAPSHOT_VERSION=$CUR_SNAPSHOT_VERSION -fi - -echo "Publishing $NEW_VERSION" - -# Prepare release -sed -i.bak "s/${CUR_SNAPSHOT_VERSION}/${NEW_VERSION}/g" gradle.properties -git add gradle.properties -git commit -m "Prepare for release $NEW_VERSION" - -# Publish -./gradlew publish - -# Add git tag -git tag "v$NEW_VERSION" -# Prepare next snapshot -echo "Setting next snapshot version $NEW_SNAPSHOT_VERSION" -sed -i.bak "s/${NEW_VERSION}/${NEW_SNAPSHOT_VERSION}/g" gradle.properties -git add gradle.properties -git commit -m "Prepare next development version" - -# Remove the backup file from sed edits -rm gradle.properties.bak - -# Push it all up -git push && git push --tags