From 129865a0b3227eeec37e93a972d1a3a5d04dfff0 Mon Sep 17 00:00:00 2001 From: Tommy Gatti Date: Tue, 27 Feb 2024 09:32:12 +1100 Subject: [PATCH] 'Rolling Tag' logic for pre/release builds (#47) * cd.yml: Moved tagging logic to before deployment * ci.yml: Added tagging logic to before prerelease deployment * git user.email now uses github-actions userid See https://github.com/ACCESS-NRI/reproducibility/issues/19 * Updated to use the organisational vars for GH_ACTIONS_BOT_GIT_USER_{NAME,EMAIL} --- .github/workflows/cd.yml | 35 ++++++++++++++++++----------------- .github/workflows/ci.yml | 37 ++++++++++++++++++++++++++++++++----- 2 files changed, 50 insertions(+), 22 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 63d1fce..4e1442b 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -50,23 +50,10 @@ jobs: version-pattern: ${{ needs.generate-tag.outputs.name }}-* secrets: inherit - deploy-release: - name: Deploy Release - needs: - - generate-tag - uses: access-nri/build-cd/.github/workflows/deploy-1-setup.yml@main - with: - ref: ${{ github.ref_name }} - version: ${{ needs.generate-tag.outputs.name }} - secrets: inherit - permissions: - contents: write - push-tag: name: Tag Deployment needs: - generate-tag - - deploy-release runs-on: ubuntu-latest permissions: contents: write @@ -74,8 +61,22 @@ jobs: - uses: actions/checkout@v4 - name: Push Tag + # NOTE: Regarding the config user.name/user.email, see https://github.com/actions/checkout/pull/1184 run: | - git config user.name github-actions - git config user.email github-actions@github.com - git tag ${{ needs.generate-tag.outputs.name }} - git push --tags + git config user.name ${{ vars.GH_ACTIONS_BOT_GIT_USER_NAME }} + git config user.email ${{ vars.GH_ACTIONS_BOT_GIT_USER_EMAIL }} + git tag ${{ needs.generate-tag.outputs.name }} --force + git push --tags --force + + deploy-release: + name: Deploy Release + needs: + - generate-tag + - push-tag + uses: access-nri/build-cd/.github/workflows/deploy-1-setup.yml@main + with: + ref: ${{ github.ref_name }} + version: ${{ needs.generate-tag.outputs.name }} + secrets: inherit + permissions: + contents: write diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ffed97..b94101c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -139,7 +139,8 @@ jobs: needs: - branch-check outputs: - number: ${{ steps.get-version.outputs.number }} + version: ${{ steps.get-version.outputs.version-name }} + version-build: ${{ steps.get-version-build.outputs.version-build-name }} steps: - uses: actions/checkout@v4 with: @@ -148,13 +149,39 @@ jobs: - name: Generate Version Number id: get-version + # The step generates a general version number from the branch name, looking the + # same as a regular release build. + # Ex. 'pre-2024.01.1' -> '2024.01.1' + run: version-name=$(cut --delimiter '-' --field 2 <<< "${{ github.head_ref }}") + + - name: Generate Version-Build String + id: get-version-build # This step generates the version number for prereleases, which given a branch # like `pre-`, looks like: `-`. # Ex. `pre-2024.10.1` with 2 commits on branch -> `2024.10.1-2`. run: | - number_of_commits=$(git rev-list --count origin/main..HEAD) - no_pre_version=$(cut --delimiter '-' --field 2 <<< "${{ github.head_ref }}") - echo "number=${no_pre_version}-${number_of_commits}" >> $GITHUB_OUTPUT + number-of-commits=$(git rev-list --count origin/main..HEAD) + echo "version-build-name=${{ steps.get-version.outputs.version-name }}-${number-of-commits}" >> $GITHUB_OUTPUT + + update-prerelease-tag: + name: Update Prerelease Tag ${{ needs.prerelease-deploy-version.outputs.version }} + needs: + - prerelease-deploy-version + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + + - name: Push + # NOTE: Regarding the config user.name/user.email, see https://github.com/actions/checkout/pull/1184 + run: | + git config user.name ${{ vars.GH_ACTIONS_BOT_GIT_USER_NAME }} + git config user.email ${{ vars.GH_ACTIONS_BOT_GIT_USER_EMAIL }} + git tag ${{ needs.prerelease-deploy-version.outputs.version }} --force + git push --tags --force prerelease-deploy: @@ -178,5 +205,5 @@ jobs: with: type: prerelease ref: ${{ github.head_ref }} - version: ${{ needs.prerelease-deploy-version.outputs.number }} + version: ${{ needs.prerelease-deploy-version.outputs.version-build }} secrets: inherit