Skip to content

Commit

Permalink
'Rolling Tag' logic for pre/release builds (#47)
Browse files Browse the repository at this point in the history
* 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 ACCESS-NRI/reproducibility#19

* Updated to use the organisational vars for GH_ACTIONS_BOT_GIT_USER_{NAME,EMAIL}
  • Loading branch information
CodeGat committed Feb 26, 2024
1 parent 0f37d7f commit 129865a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 22 deletions.
35 changes: 18 additions & 17 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,33 @@ 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
steps:
- 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
37 changes: 32 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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-<version>`, looks like: `<version>-<number of commits on this branch>`.
# 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:
Expand All @@ -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

0 comments on commit 129865a

Please sign in to comment.