From fc66e2f4ea7acf678d8f28136a6be3631a1100b1 Mon Sep 17 00:00:00 2001 From: Rushmore Mushambi Date: Tue, 12 Dec 2023 14:45:17 +0200 Subject: [PATCH] Make release and beta workflows idempotent (#3132) --- .github/workflows/beta.yml | 8 ++++- .github/workflows/release.yml | 11 ++++++- .../workflows/reusable_publish_version.yml | 31 +++++++++++++------ 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/.github/workflows/beta.yml b/.github/workflows/beta.yml index 9798df5f..0714acc6 100644 --- a/.github/workflows/beta.yml +++ b/.github/workflows/beta.yml @@ -2,7 +2,7 @@ name: Beta release -run-name: "Beta release (publish: ${{ inputs.publish }})" +run-name: "Beta release (publish: ${{ inputs.publish }}, bump version: ${{ inputs.bump-version }})" on: workflow_dispatch: @@ -12,6 +12,11 @@ on: type: boolean default: false description: "Publish the beta release" + bump-version: + required: false + type: boolean + default: false + description: "Bump the version of the current beta if this is not the initial one" defaults: run: @@ -48,6 +53,7 @@ jobs: with: environment: beta git-ref: ${{ needs.checks.outputs.branch }} + bump-version: ${{ inputs.bump-version }} publish: ${{ inputs.publish }} create-release: ${{ inputs.publish }} secrets: inherit diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8389bb21..b9709a4b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -84,6 +84,12 @@ jobs: run: | set -x + # When moving from beta we are going to pull the version from the stable branch + if [[ "${{ inputs.branch }}" == "releases/beta" ]]; then + git fetch origin releases/stable + git checkout releases/stable + fi + # Retrieve just released version version=$(/home/runner/.cargo/bin/taplo get -f lib/Cargo.toml "package.version") echo "version=${version}" >> $GITHUB_OUTPUT @@ -135,4 +141,7 @@ jobs: - name: Delete the release branch if: ${{ inputs.publish }} - run: git push origin --delete ${{ inputs.branch }} + run: | + set -x + git push origin --delete ${{ inputs.branch }} || true + git push origin --delete releases/stable || true diff --git a/.github/workflows/reusable_publish_version.yml b/.github/workflows/reusable_publish_version.yml index 26dd0f73..9a2950ea 100644 --- a/.github/workflows/reusable_publish_version.yml +++ b/.github/workflows/reusable_publish_version.yml @@ -9,6 +9,11 @@ on: required: true type: string description: "The git ref of this release version. All 'actions/checkout' steps will use it" + bump-version: + required: false + type: boolean + default: false + description: "Bump the version of the current beta if this is not the initial one" latest: required: false type: boolean @@ -64,6 +69,8 @@ jobs: currentVersion=$(/home/runner/.cargo/bin/taplo get -f lib/Cargo.toml "package.version") if [[ $currentVersion == *"-beta"* ]]; then + git push origin --delete releases/stable || true + git checkout -b releases/stable major=$(echo $currentVersion | tr "." "\n" | sed -n 1p) minor=$(echo $currentVersion | tr "." "\n" | sed -n 2p) betaNum=$(echo $currentVersion | tr "." "\n" | sed -n 4p) @@ -83,7 +90,7 @@ jobs: fi # Create the tag - git tag -a v${version} -m "Release ${version}" + git tag -a v${version} -m "Release ${version}" || true - name: Create or patch beta branch if: ${{ inputs.environment == 'beta' }} @@ -93,11 +100,15 @@ jobs: currentVersion=$(/home/runner/.cargo/bin/taplo get -f lib/Cargo.toml "package.version") if [[ $currentVersion == *"-beta"* ]]; then - major=$(echo $currentVersion | tr "." "\n" | sed -n 1p) - minor=$(echo $currentVersion | tr "." "\n" | sed -n 2p) - patchAndMeta=$(echo $currentVersion | tr "." "\n" | sed -n 3p) - betaNum=$(echo $currentVersion | tr "." "\n" | sed -n 4p) - betaVersion=${major}.${minor}.${patchAndMeta}.$(($betaNum + 1)) + if [[ "${{ inputs.bump-version }}" == "true" ]]; then + major=$(echo $currentVersion | tr "." "\n" | sed -n 1p) + minor=$(echo $currentVersion | tr "." "\n" | sed -n 2p) + patchAndMeta=$(echo $currentVersion | tr "." "\n" | sed -n 3p) + betaNum=$(echo $currentVersion | tr "." "\n" | sed -n 4p) + betaVersion=${major}.${minor}.${patchAndMeta}.$(($betaNum + 1)) + else + betaVersion=$currentVersion + fi else git checkout -b releases/beta major=$(echo $currentVersion | tr "." "\n" | sed -n 1p) @@ -113,10 +124,10 @@ jobs: cargo check --no-default-features --features storage-mem # Commit changes - git commit -am "Prepare v${betaVersion} release" + git commit -am "Prepare v${betaVersion} release" || true # Create the tag - git tag -a v${betaVersion} -m "Release ${betaVersion}" + git tag -a v${betaVersion} -m "Release ${betaVersion}" || true - name: Push changes if: ${{ inputs.publish && (inputs.environment == 'beta' || inputs.environment == 'release') }} @@ -126,7 +137,7 @@ jobs: if: ${{ inputs.publish && (inputs.environment == 'beta' || inputs.environment == 'release') }} env: GITHUB_TOKEN: ${{ secrets.RELEASE_PLZ_TOKEN }} # Need the custom user token here so we can push the tag - run: git push --tags + run: git push --tags || true - name: Set outputs id: outputs @@ -135,6 +146,8 @@ jobs: if [[ "${{ inputs.environment }}" == "beta" && "${{ inputs.publish }}" == "true" ]]; then echo "git-ref=releases/beta" >> $GITHUB_OUTPUT + elif [[ "${{ inputs.environment }}" == "release" && "${{ inputs.git-ref }}" == "releases/beta" && "${{ inputs.publish }}" == "true" ]]; then + echo "git-ref=releases/stable" >> $GITHUB_OUTPUT else echo "git-ref=${{ inputs.git-ref || github.ref_name }}" >> $GITHUB_OUTPUT fi