Skip to content

Commit

Permalink
Prerelease Functionaility (#35)
Browse files Browse the repository at this point in the history
* ci.yml: Added branch rules, added prerelease deployment job

* Renamed deploy.yml -> cd.yml: Now triggered on push to main, autotagging of release, workflow undeploys prereleases

* ci.yml: Updated method for checking out number of commits on branch

* ci.yml: dorny/paths-filter action now uses hash instead of version
  • Loading branch information
CodeGat authored Feb 6, 2024
1 parent 2696fcb commit 9026a58
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 14 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: CD
on:
push:
branches:
- main

jobs:
generate-tag:
name: Generate Tag Name
# Get the tag name from the branch that was merged into main, which
# is of the form `pre-<version>`.
# We assume that this will always be the most recent merged PR, as
# this workflow kicks off immediately after the merge completes.
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
name: ${{ steps.tag.outputs.name }}
steps:
- uses: actions/checkout@v4

- name: Generate Tag
id: tag
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
# We use the `gh` utility as it offers much easier traversal of GitHub-
# related things (prs, issues, etc...).
# The `cut` command splits the `pre-<version>` branch into just `<version>`,
# which will be the new tag.
run: |
merged_branch=$(gh pr list \
--state merged \
--limit 1 \
--json 'headRefName' \
--jq '.[].headRefName')
echo "name=$(cut --delimiter '-' --fields 2 <<< '$merged_branch')" >> $GITHUB_OUTPUT
undeploy-prereleases:
name: Undeploy Prereleases
needs:
- generate-tag
uses: access-nri/build-cd/.github/workflows/undeploy-1-setup.yml@main
with:
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:
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
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
34 changes: 33 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: CI
on:
pull_request:
branches:
# Branches that modify spack.yaml must be of the form: pre-*.*.* (ex: pre-2024.01.1)
# in order for the PR to access the '* Prerelease' GitHub Environments.
- 'pre-*.*.*'
paths:
- 'config/*.json'
- 'spack.yaml'
Expand All @@ -13,7 +17,7 @@ jobs:
json-changed: ${{ steps.filter.outputs.json }}
versions-json-changed: ${{ steps.filter.outputs.versions-json }}
steps:
- uses: dorny/paths-filter@v2.9.3
- uses: dorny/paths-filter@ad1ae68cd06927a8731fe67e877a2351c7a09691 #v2.9.3
id: filter
with:
filters: |
Expand Down Expand Up @@ -112,3 +116,31 @@ jobs:
If this is not what was expected, commit changes to `config/versions.json`.
run: gh pr comment --body '${{ env.BODY }}'

prerelease-deploy-version:
name: Get Prerelease Number
runs-on: ubuntu-latest
outputs:
number: ${{ steps.history.outputs.commits }}
steps:
- uses: actions/checkout@v4

- name: Get Number of Commits on ${{ github.head_ref }}
id: history
run: echo "commits=$(git rev-list --count main..HEAD)" >> $GITHUB_OUTPUT

prerelease-deploy:
name: Deploy to Prerelease
# This will create a `spack` environment with the name `access-om2-<version>-<commit number>`
# For example, `access-om2-2024.01.1-3` for the deployment based on the third commit on this
# `pre-2024.01.1` PR branch.
needs:
- prerelease-deploy-version
- spack-yaml-checks
- validate
- check-versions-exist
uses: access-nri/build-cd/.github/workflows/deploy-1-setup.yml@main
with:
type: prerelease
version: ${{ github.head_ref }}-${{ needs.prerelease-deploy-version.outputs.number }}
secrets: inherit
13 changes: 0 additions & 13 deletions .github/workflows/deploy.yml

This file was deleted.

0 comments on commit 9026a58

Please sign in to comment.