Make release and beta workflows idempotent (#3132)

This commit is contained in:
Rushmore Mushambi 2023-12-12 14:45:17 +02:00 committed by GitHub
parent 28e3547fca
commit fc66e2f4ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 11 deletions

View file

@ -2,7 +2,7 @@
name: Beta release name: Beta release
run-name: "Beta release (publish: ${{ inputs.publish }})" run-name: "Beta release (publish: ${{ inputs.publish }}, bump version: ${{ inputs.bump-version }})"
on: on:
workflow_dispatch: workflow_dispatch:
@ -12,6 +12,11 @@ on:
type: boolean type: boolean
default: false default: false
description: "Publish the beta release" 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: defaults:
run: run:
@ -48,6 +53,7 @@ jobs:
with: with:
environment: beta environment: beta
git-ref: ${{ needs.checks.outputs.branch }} git-ref: ${{ needs.checks.outputs.branch }}
bump-version: ${{ inputs.bump-version }}
publish: ${{ inputs.publish }} publish: ${{ inputs.publish }}
create-release: ${{ inputs.publish }} create-release: ${{ inputs.publish }}
secrets: inherit secrets: inherit

View file

@ -84,6 +84,12 @@ jobs:
run: | run: |
set -x 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 # Retrieve just released version
version=$(/home/runner/.cargo/bin/taplo get -f lib/Cargo.toml "package.version") version=$(/home/runner/.cargo/bin/taplo get -f lib/Cargo.toml "package.version")
echo "version=${version}" >> $GITHUB_OUTPUT echo "version=${version}" >> $GITHUB_OUTPUT
@ -135,4 +141,7 @@ jobs:
- name: Delete the release branch - name: Delete the release branch
if: ${{ inputs.publish }} 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

View file

@ -9,6 +9,11 @@ on:
required: true required: true
type: string type: string
description: "The git ref of this release version. All 'actions/checkout' steps will use it" 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: latest:
required: false required: false
type: boolean type: boolean
@ -64,6 +69,8 @@ jobs:
currentVersion=$(/home/runner/.cargo/bin/taplo get -f lib/Cargo.toml "package.version") currentVersion=$(/home/runner/.cargo/bin/taplo get -f lib/Cargo.toml "package.version")
if [[ $currentVersion == *"-beta"* ]]; then if [[ $currentVersion == *"-beta"* ]]; then
git push origin --delete releases/stable || true
git checkout -b releases/stable
major=$(echo $currentVersion | tr "." "\n" | sed -n 1p) major=$(echo $currentVersion | tr "." "\n" | sed -n 1p)
minor=$(echo $currentVersion | tr "." "\n" | sed -n 2p) minor=$(echo $currentVersion | tr "." "\n" | sed -n 2p)
betaNum=$(echo $currentVersion | tr "." "\n" | sed -n 4p) betaNum=$(echo $currentVersion | tr "." "\n" | sed -n 4p)
@ -83,7 +90,7 @@ jobs:
fi fi
# Create the tag # 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 - name: Create or patch beta branch
if: ${{ inputs.environment == 'beta' }} if: ${{ inputs.environment == 'beta' }}
@ -93,11 +100,15 @@ jobs:
currentVersion=$(/home/runner/.cargo/bin/taplo get -f lib/Cargo.toml "package.version") currentVersion=$(/home/runner/.cargo/bin/taplo get -f lib/Cargo.toml "package.version")
if [[ $currentVersion == *"-beta"* ]]; then if [[ $currentVersion == *"-beta"* ]]; then
if [[ "${{ inputs.bump-version }}" == "true" ]]; then
major=$(echo $currentVersion | tr "." "\n" | sed -n 1p) major=$(echo $currentVersion | tr "." "\n" | sed -n 1p)
minor=$(echo $currentVersion | tr "." "\n" | sed -n 2p) minor=$(echo $currentVersion | tr "." "\n" | sed -n 2p)
patchAndMeta=$(echo $currentVersion | tr "." "\n" | sed -n 3p) patchAndMeta=$(echo $currentVersion | tr "." "\n" | sed -n 3p)
betaNum=$(echo $currentVersion | tr "." "\n" | sed -n 4p) betaNum=$(echo $currentVersion | tr "." "\n" | sed -n 4p)
betaVersion=${major}.${minor}.${patchAndMeta}.$(($betaNum + 1)) betaVersion=${major}.${minor}.${patchAndMeta}.$(($betaNum + 1))
else
betaVersion=$currentVersion
fi
else else
git checkout -b releases/beta git checkout -b releases/beta
major=$(echo $currentVersion | tr "." "\n" | sed -n 1p) major=$(echo $currentVersion | tr "." "\n" | sed -n 1p)
@ -113,10 +124,10 @@ jobs:
cargo check --no-default-features --features storage-mem cargo check --no-default-features --features storage-mem
# Commit changes # Commit changes
git commit -am "Prepare v${betaVersion} release" git commit -am "Prepare v${betaVersion} release" || true
# Create the tag # Create the tag
git tag -a v${betaVersion} -m "Release ${betaVersion}" git tag -a v${betaVersion} -m "Release ${betaVersion}" || true
- name: Push changes - name: Push changes
if: ${{ inputs.publish && (inputs.environment == 'beta' || inputs.environment == 'release') }} if: ${{ inputs.publish && (inputs.environment == 'beta' || inputs.environment == 'release') }}
@ -126,7 +137,7 @@ jobs:
if: ${{ inputs.publish && (inputs.environment == 'beta' || inputs.environment == 'release') }} if: ${{ inputs.publish && (inputs.environment == 'beta' || inputs.environment == 'release') }}
env: env:
GITHUB_TOKEN: ${{ secrets.RELEASE_PLZ_TOKEN }} # Need the custom user token here so we can push the tag 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 - name: Set outputs
id: outputs id: outputs
@ -135,6 +146,8 @@ jobs:
if [[ "${{ inputs.environment }}" == "beta" && "${{ inputs.publish }}" == "true" ]]; then if [[ "${{ inputs.environment }}" == "beta" && "${{ inputs.publish }}" == "true" ]]; then
echo "git-ref=releases/beta" >> $GITHUB_OUTPUT 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 else
echo "git-ref=${{ inputs.git-ref || github.ref_name }}" >> $GITHUB_OUTPUT echo "git-ref=${{ inputs.git-ref || github.ref_name }}" >> $GITHUB_OUTPUT
fi fi