Skip to content

Commit fef7ff4

Browse files
CodeGatharshula
authored andcommitted
Add build-ci (#5)
* Add build-ci workflow for upstream-spack-packages * Get exclude matrix from access-spack-packages, rename matrix to package rather than manifest
1 parent 2bdde15 commit fef7ff4

1 file changed

Lines changed: 143 additions & 0 deletions

File tree

.github/workflows/build-ci.yml

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
name: CI
2+
on:
3+
pull_request:
4+
branches:
5+
# We only want to run our CI on pull requests to the access/** branches
6+
- 'access/**'
7+
workflow_dispatch:
8+
inputs:
9+
upstream-spack-packages-ref:
10+
description: 'builtin spack-packages ref to use'
11+
required: true
12+
type: string
13+
access-spack-packages-ref:
14+
description: 'access-spack-packages ref to use'
15+
required: true
16+
type: string
17+
spack-config-ref:
18+
description: 'spack-config ref to use'
19+
required: true
20+
type: string
21+
spack-ref:
22+
description: 'spack ref to use'
23+
required: true
24+
type: string
25+
run-self-hosted:
26+
description: 'Use self-hosted runners for the test'
27+
required: true
28+
default: true
29+
type: boolean
30+
# We don't want to overwhelm the runners with multiple commits in a PR.
31+
# So we will cancel any existing runs and only run the current HEAD of the branch
32+
concurrency:
33+
group: build-ci-${{ github.head_ref || github.ref_name }}
34+
cancel-in-progress: true
35+
jobs:
36+
setup-ci:
37+
name: Setup CI
38+
runs-on: ubuntu-latest
39+
# We run this in our runner container so we can effectively parse the git repository for each package via spack
40+
container: ghcr.io/access-nri/build-ci-runner:rocky
41+
env:
42+
# Note, this needs to be updated in line with refs in the CI job below
43+
BUILD_CI_WORKFLOW_VERSION: v3
44+
# Which directory under access-nri/access-spack-packages contains the spack packages
45+
ACCESS_SPACK_PACKAGES_ROOT_DIR: spack_repo/access/nri/packages
46+
outputs:
47+
# Matrices used in CI job
48+
manifest-matrix: ${{ steps.set-manifest-matrix.outputs.matrix }}
49+
exclude-matrix: ${{ steps.set-manifest-matrix.outputs.exclude-matrix }}
50+
# packages repositories
51+
builtin-spack-packages-ref: ${{ inputs.upstream-spack-packages-ref || github.event.pull_request.head.sha }}
52+
access-spack-packages-ref: ${{ inputs.access-spack-packages-ref || steps.defaults.outputs.access-spack-packages-ref }}
53+
# Global defaults for CI job
54+
spack-config-ref: ${{ inputs.spack-config-ref || steps.defaults.outputs.spack-config-ref }}
55+
spack-ref: ${{ inputs.spack-ref || steps.defaults.outputs.spack-ref }}
56+
steps:
57+
- name: Checkout upstream-spack-packages-ref
58+
uses: actions/checkout@v6
59+
with:
60+
ref: ${{ github.event.pull_request.head.ref || inputs.upstream-spack-packages-ref }}
61+
62+
- name: Checkout access-spack-packages
63+
uses: actions/checkout@v6
64+
with:
65+
repository: access-nri/access-spack-packages
66+
ref: ${{ inputs.access-spack-packages-ref }}
67+
68+
- name: Get packages from access-spack-packages
69+
id: access-spack-packages
70+
run: |
71+
pkgs=$(find ${{ env.ACCESS_SPACK_PACKAGES_ROOT_DIR }}/ -mindepth 1 -maxdepth 1 -type d -printf '%P ')
72+
73+
echo "Packages found in access-spack-packages: $pkgs"
74+
75+
echo "pkgs=$pkgs" >> $GITHUB_OUTPUT
76+
77+
- name: Setup Matrix
78+
id: set-manifest-matrix
79+
# Find all manifests defined in all packages MCRs (if applicable) or access-spack-packages if not found there
80+
# Creates a matrix of the form: [{PACKAGE, MANIFEST_REPO, MANIFEST_REPO_REF, MANIFEST_PATH_IN_REPO}, ...]
81+
uses: access-nri/access-spack-packages/.github/build-ci/actions/generate-manifest-matrix@api-v2
82+
with:
83+
packages: ${{ steps.access-spack-packages.outputs.pkgs }}
84+
packages-root-dir: ${{ env.ACCESS_SPACK_PACKAGES_ROOT_DIR }}
85+
token: ${{ secrets.SPACK_INSTALL_COMMAND_PAT }}
86+
87+
- name: Checkout build-ci
88+
uses: actions/checkout@v6
89+
with:
90+
repository: access-nri/build-ci
91+
ref: ${{ env.BUILD_CI_WORKFLOW_VERSION }}
92+
93+
- name: Get default refs from build-ci workflow
94+
id: defaults
95+
# GitHub does not treat empty-string inputs as eligible for substitution with a default
96+
# Since we are supporting both workflow_dispatch and pull_request triggers, the entrypoint inputs need to be filled in
97+
# So we are getting the default values from the workflow file itself, and passing them back into the workflow
98+
run: |
99+
default_spack_ref=$(yq '.on.workflow_call.inputs."spack-ref".default' .github/workflows/ci.yml)
100+
default_spack_config_ref=$(yq '.on.workflow_call.inputs."spack-config-ref".default' .github/workflows/ci.yml)
101+
default_access_spack_packages_ref=$(yq '.on.workflow_call.inputs."access-spack-packages-ref".default' .github/workflows/ci.yml)
102+
103+
echo "Default refs from ${{ env.BUILD_CI_WORKFLOW_VERSION }}: spack-ref=$default_spack_ref, spack-config-ref=$default_spack_config_ref, access-spack-packages-ref=$default_access_spack_packages_ref"
104+
105+
echo "spack-ref=$default_spack_ref" >> $GITHUB_OUTPUT
106+
echo "spack-config-ref=$default_spack_config_ref" >> $GITHUB_OUTPUT
107+
echo "access-spack-packages-ref=$default_access_spack_packages_ref" >> $GITHUB_OUTPUT
108+
109+
ci:
110+
name: CI
111+
needs:
112+
- setup-ci
113+
strategy:
114+
fail-fast: false
115+
max-parallel: 7
116+
matrix:
117+
# Respectively of the form:
118+
# [
119+
# {"template_value": "mom5", "repository": "ACCESS-NRI/MOM5", "ref": "master", "filepath": ".github/build-ci/manifests/intel.spack.yaml.j2"},
120+
# {"template_value": "mom5", "repository": "ACCESS-NRI/MOM5", "ref": "master", "filepath": ".github/build-ci/manifests/gcc.spack.yaml.j2"},
121+
# {"template_value": "datetime-fortran", "repository": "ACCESS-NRI/access-spack-packages", "ref": "api-v2", "filepath": ".github/build-ci/manifests/datetime-fortran/spack.yaml.j2"},
122+
# ...
123+
# ]
124+
package: ${{ fromJson(needs.setup-ci.outputs.manifest-matrix) }}
125+
# Exclude bundles and packages that can't build with build-ci
126+
exclude: ${{ fromJson(needs.setup-ci.outputs.exclude-matrix) }}
127+
uses: access-nri/build-ci/.github/workflows/ci.yml@v3
128+
with:
129+
spack-manifest-repository: ${{ matrix.package.repository }}
130+
spack-manifest-repository-ref: ${{ matrix.package.ref }}
131+
spack-manifest-path: ${{ matrix.package.filepath }}
132+
spack-manifest-data-path: .github/build-ci/data/standard.json
133+
spack-manifest-data-pairs: |-
134+
package ${{ matrix.package.template_value }}
135+
ref: ${{ matrix.package.ref }}
136+
spack-config-ref: ${{ needs.setup-ci.outputs.spack-config-ref }}
137+
spack-ref: ${{ needs.setup-ci.outputs.spack-ref }}
138+
builtin-spack-packages-ref: ${{ needs.setup-ci.outputs.builtin-spack-packages-ref }}
139+
access-spack-packages-ref: ${{ needs.setup-ci.outputs.access-spack-packages-ref }}
140+
# Workflow dispatch can switch depending on cluster/GitHub resourcing, otherwise run self-hosted
141+
run-self-hosted: ${{ inputs.run-self-hosted || true }}
142+
secrets:
143+
spack-install-command-pat: ${{ secrets.SPACK_INSTALL_COMMAND_PAT }}

0 commit comments

Comments
 (0)