Skip to content

Commit aabb186

Browse files
authored
CI/CD Consolidation (#47)
* Added consolidated CI/CD workflows * Updated comments
1 parent b7f2346 commit aabb186

File tree

4 files changed

+421
-0
lines changed

4 files changed

+421
-0
lines changed

.github/workflows/cd.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: CD
2+
run-name: ${{ inputs.model }} CD
3+
# NOTE: This workflow requires:
4+
# permissions.contents:write
5+
# secrets:inherit with an appropriate GitHub Environment for deployment in the caller
6+
on:
7+
workflow_call:
8+
inputs:
9+
model:
10+
type: string
11+
required: true
12+
description: The model that is being tested and deployed
13+
# Callers usually have the trigger:
14+
# push:
15+
# branches:
16+
# - main
17+
# - backport/*.*
18+
# paths:
19+
# - config/**
20+
# - spack.yaml
21+
22+
env:
23+
SPACK_YAML_MODEL_YQ: .spack.specs[0]
24+
jobs:
25+
push-tag:
26+
name: Tag Deployment
27+
runs-on: ubuntu-latest
28+
permissions:
29+
contents: write
30+
outputs:
31+
name: ${{ steps.tag.outputs.name }}
32+
steps:
33+
- uses: actions/checkout@v4
34+
35+
- name: Generate Tag
36+
id: tag
37+
# Get the tag name from the `spack.yaml` that was merged into main, which
38+
# is of the form `<model>@git.<version>`.
39+
run: echo "name=$(yq '${{ env.SPACK_YAML_MODEL_YQ }} | split("@git.") | .[1]' spack.yaml)" >> $GITHUB_OUTPUT
40+
41+
- name: Push Tag
42+
# NOTE: Regarding the config user.name/user.email, see https://github.com/actions/checkout/pull/1184
43+
run: |
44+
git config user.name ${{ vars.GH_ACTIONS_BOT_GIT_USER_NAME }}
45+
git config user.email ${{ vars.GH_ACTIONS_BOT_GIT_USER_EMAIL }}
46+
git tag ${{ steps.tag.outputs.name }} --force
47+
git push --tags --force
48+
49+
deploy-release:
50+
name: Deploy Release
51+
needs:
52+
- push-tag
53+
uses: access-nri/build-cd/.github/workflows/deploy-1-setup.yml@main
54+
with:
55+
ref: ${{ github.ref_name }}
56+
version: ${{ needs.push-tag.outputs.name }}
57+
secrets: inherit
58+
permissions:
59+
contents: write

.github/workflows/ci-closed.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: PR Closed Cleanup
2+
run-name: ${{ inputs.model }} PR Closed Cleanup
3+
# Remove prereleases that were part of a closed PR, so we save space
4+
# on our deployment targets. If needed, one can still get the
5+
# spack.yaml as part of the closed PR and revive it themselves.
6+
7+
# NOTE: the caller requires the following permissions:
8+
# secrets:inherit
9+
on:
10+
workflow_call:
11+
inputs:
12+
model:
13+
type: string
14+
required: true
15+
description: The model that is being tested and deployed
16+
# Callers usually have the trigger:
17+
# pull_request:
18+
# types:
19+
# - closed
20+
# branches:
21+
# - main
22+
# - backport/*.*
23+
# paths:
24+
# - config/**
25+
# - spack.yaml
26+
jobs:
27+
setup:
28+
name: Setup
29+
runs-on: ubuntu-latest
30+
outputs:
31+
version-pattern: ${{ steps.version.outputs.pattern }}
32+
steps:
33+
- name: Version Pattern
34+
id: version
35+
# For example, `access-om3-pr12-*`
36+
run: |
37+
repo_name_lower=$(echo ${{ github.event.repository.name }} | tr [:upper:] [:lower:])
38+
echo "pattern=${repo_name_lower}-pr${{ github.event.pull_request.number }}-*" >> $GITHUB_OUTPUT
39+
40+
undeploy-prereleases:
41+
name: Undeploy Prereleases Matching ${{ needs.setup.outputs.version-pattern }}
42+
needs:
43+
- setup
44+
uses: access-nri/build-cd/.github/workflows/undeploy-1-setup.yml@main
45+
with:
46+
version-pattern: ${{ needs.setup.outputs.version-pattern }}
47+
secrets: inherit

.github/workflows/ci-comment.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: Comment Command
2+
run-name: ${{ inputs.model }} Comment Command
3+
# NOTE: This workflow requires:
4+
# permissions.contents:write
5+
on:
6+
workflow_call:
7+
inputs:
8+
model:
9+
type: string
10+
required: true
11+
description: The model that is being tested and deployed
12+
root-sbd:
13+
type: string
14+
required: false
15+
default: ${{ inputs.model }}
16+
description: |
17+
The name of the root Spack Bundle Definition, if it is different from the model name.
18+
This is often a package named similarly in ACCESS-NRI/spack-packages.
19+
# Callers usually have the trigger:
20+
# issue_comment:
21+
# types:
22+
# - created
23+
# - edited
24+
env:
25+
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
26+
SPACK_YAML_MODEL_YQ: .spack.specs[0]
27+
SPACK_YAML_MODEL_PROJECTION_YQ: .spack.modules.default.tcl.projections.${{ inputs.root-sbd }}
28+
jobs:
29+
bump-version:
30+
name: Bump spack.yaml
31+
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '!bump')
32+
runs-on: ubuntu-latest
33+
permissions:
34+
pull-requests: write
35+
env:
36+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
steps:
38+
- uses: actions/checkout@v4
39+
with:
40+
fetch-depth: 0
41+
fetch-tags: true
42+
token: ${{ secrets.GH_COMMIT_CHECK_TOKEN }}
43+
44+
- name: Setup
45+
id: setup
46+
# outputs:
47+
# original-version: The version contained within the spack.yaml
48+
# version: The version that will be bumped (could be latest tag instead of original-version)
49+
# bump: The bump type (major, minor or current as specified in the bump-version action)
50+
run: |
51+
# Get the version of ${{ inputs.root-sbd }} from the spack.yaml in the PR the comment was written in
52+
gh pr checkout ${{ github.event.issue.number }}
53+
original_version=$(yq e '${{ env.SPACK_YAML_MODEL_YQ }} | split("@git.") | .[1]' spack.yaml)
54+
echo "original-version=${original_version}" >> $GITHUB_OUTPUT
55+
56+
# Validate the comment
57+
if [[ "${{ contains(github.event.comment.body, 'major') }}" == "true" ]]; then
58+
# Compare the current date (year-month) with the latest git tag (year-month)
59+
# to determine the next valid tag. We do this because especially feature-rich
60+
# months might increment the date part beyond the current date.
61+
62+
d="$(date +%Y-%m)-01"
63+
d_s=$(date --date "$d" +%s)
64+
65+
latest_tag=$(git describe --tags --abbrev=0 | tr '.' '-')
66+
tag_date=${latest_tag%-*}-01
67+
tag_date_s=$(date --date "$tag_date" +%s)
68+
69+
echo "Comparing current date ${d} with ${tag_date} (tag looks like ${latest_tag})"
70+
71+
if (( d_s <= tag_date_s )); then
72+
echo "version=${tag_date}" >> $GITHUB_OUTPUT
73+
echo "bump=major" >> $GITHUB_OUTPUT
74+
else
75+
echo "version=${original_version}" >> $GITHUB_OUTPUT
76+
echo "bump=current" >> $GITHUB_OUTPUT
77+
fi
78+
elif [[ "${{ contains(github.event.comment.body, 'minor')}}" == "true" ]]; then
79+
echo "version=${original_version}" >> $GITHUB_OUTPUT
80+
echo "bump=minor" >> $GITHUB_OUTPUT
81+
else
82+
echo "::warning::Usage: `!bump [major|minor]`, got `${{ github.event.comment.body }}`"
83+
exit 1
84+
fi
85+
86+
- name: Bump Version
87+
id: bump
88+
uses: access-nri/actions/.github/actions/bump-version@main
89+
with:
90+
version: ${{ steps.setup.outputs.version }}
91+
versioning-scheme: calver-minor
92+
bump-type: ${{ steps.setup.outputs.bump }}
93+
94+
- name: Update, Commit and Push the Bump
95+
run: |
96+
git config user.name ${{ vars.GH_ACTIONS_BOT_GIT_USER_NAME }}
97+
git config user.email ${{ vars.GH_ACTIONS_BOT_GIT_USER_EMAIL }}
98+
99+
yq -i '${{ env.SPACK_YAML_MODEL_YQ }} = "${{ inputs.root-sbd }}@git.${{ steps.bump.outputs.after }}"' spack.yaml
100+
yq -i '${{ env.SPACK_YAML_MODEL_PROJECTION_YQ }} = "{name}/${{ steps.bump.outputs.after }}"' spack.yaml
101+
git add spack.yaml
102+
git commit -m "spack.yaml: Updated ${{ inputs.root-sbd }} package version from ${{ steps.setup.outputs.original-version }} to ${{ steps.bump.outputs.after }}"
103+
git push
104+
105+
- name: Success Notifier
106+
uses: access-nri/actions/.github/actions/pr-comment@main
107+
with:
108+
comment: |
109+
:white_check_mark: Version bumped from `${{ steps.setup.outputs.original-version }}` to `${{ steps.bump.outputs.after }}` :white_check_mark:
110+
111+
- name: Failure Notifier
112+
if: failure()
113+
uses: access-nri/actions/.github/actions/pr-comment@main
114+
with:
115+
comment: |
116+
:x: Failed to bump version or commit changes, see ${{ env.RUN_URL }} :x:

0 commit comments

Comments
 (0)