-
Notifications
You must be signed in to change notification settings - Fork 1
137 lines (123 loc) · 5.31 KB
/
model-1-build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
name: Build package
on:
workflow_call:
jobs:
setup-spack-packages:
name: Info from spack-packages
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get-version.outputs.version }}
steps:
- uses: actions/checkout@v3
with:
repository: access-nri/spack-packages
ref: main
fetch-tags: true
- name: Fetch history for main
# By default, actions/checkout only checks out `--depth=1` (the tip of the main branch).
# Even when we fetch tags the history is fragmented and usually isn't traversable from HEAD with `git describe --tags`.
# We fetch the entirety of the main branch history to be able to do the next step.
run: git fetch --unshallow
- name: Get latest spack-packages tags
id: get-version
# This command traverses `main` to find the last `git tag` and suppresses the 'long form' of tags (that have a bunch of commit metadata).
run: echo "version=$(git describe --tags --abbrev=0)" >> $GITHUB_OUTPUT
setup-model:
name: Info from ${{ github.repository }}
runs-on: ubuntu-latest
outputs:
package-name: ${{ steps.get-package-name.outputs.package }}
steps:
- name: Get package name
id: get-package-name
# for the cases where the repo name is in uppercase but the package name is lowercase (eg. access-nri/MOM5)
run: echo "package=$(echo ${{ github.event.repository.name }} | tr [:upper:] [:lower:])" >> $GITHUB_OUTPUT
setup-build-ci:
name: Info from build-ci
runs-on: ubuntu-latest
needs:
- setup-model
outputs:
compilers: ${{ steps.get-compilers.outputs.compilers }}
model: ${{ steps.get-model.outputs.model }}
steps:
- uses: actions/checkout@v3
with:
repository: access-nri/build-ci
- name: Get compilers to test
id: get-compilers
run: echo "compilers=$(jq -c . config/compilers.json)" >> $GITHUB_OUTPUT
- name: Get model to test
id: get-model
# model-components are associated with an overarching model (for example, cice5 is associated with access-om2), this uses models.json to find the associated model
run: |
model=$(jq -cr 'to_entries[] | select(.value | contains(["${{ needs.setup-model.outputs.package-name }}"])) | .key' config/models.json)
if [ -z "$model" ]; then
exit 1
else
echo "model=$model" >> $GITHUB_OUTPUT
fi
build:
runs-on: ubuntu-latest
needs:
- setup-spack-packages
- setup-build-ci
- setup-model
strategy:
fail-fast: false
matrix:
compiler: ${{ fromJson(needs.setup-build-ci.outputs.compilers) }}
permissions:
packages: read
env:
PACKAGE_NAME: ${{ needs.setup-model.outputs.package-name }}
SPACK_YAML_LOCATION: $SPACK_ROOT/../environments/${{ needs.setup-model.outputs.package-name }}
container:
image: ghcr.io/access-nri/build-${{ needs.setup-build-ci.outputs.model }}-${{ matrix.compiler.COMPILER_NAME }}${{ matrix.compiler.COMPILER_VERSION }}-${{ needs.setup-spack-packages.outputs.version }}:latest
credentials:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
options: --interactive --tty
volumes:
- /lockfiles:/lockfiles
steps:
- name: Get correct ref
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "GH_REF=${{ github.head_ref }}" >> $GITHUB_ENV
else
echo "GH_REF=${{ github.ref_name }}" >> $GITHUB_ENV
fi
- name: Build ${{ env.PACKAGE_NAME }} via spack
run: |
. $SPACK_ROOT/../spack-config/spack-enable.bash
spack load ${{ matrix.compiler.COMPILER_PKG_NAME }}@${{ matrix.compiler.COMPILER_PKG_VERSION }}
spack compiler find
spack env activate ${{ env.PACKAGE_NAME }}
spack find --show-concretized --long
cp ${{ env.SPACK_YAML_LOCATION }}/spack.yaml /lockfiles/generic.spack.yaml
cp ${{ env.SPACK_YAML_LOCATION }}/spack.lock /lockfiles/generic.spack.lock
echo "------------------------------------------------------------------------------"
spack change --match-spec ${{ env.PACKAGE_NAME }} ${{ env.PACKAGE_NAME }}@git.$GH_REF%${{ matrix.compiler.COMPILER_NAME }}@${{ matrix.compiler.COMPILER_VERSION }} target=$ENV_SPACK_TARGET
spack concretize --reuse
spack find --show-concretized --long
cp ${{ env.SPACK_YAML_LOCATION }}/spack.yaml /lockfiles/current.spack.yaml
cp ${{ env.SPACK_YAML_LOCATION }}/spack.lock /lockfiles/current.spack.lock
echo "------------------------------------------------------------------------------"
spack install
- name: Generate force-concretized lockfile
if: failure()
run: |
. $SPACK_ROOT/../spack-config/spack-enable.bash
spack load ${{ matrix.compiler.COMPILER_PKG_NAME }}@${{ matrix.compiler.COMPILER_PKG_VERSION }}
spack compiler find
spack env activate ${{ env.PACKAGE_NAME }}
spack concretize --force
cp ${{ env.SPACK_YAML_LOCATION }}/spack.lock /lockfiles/force.spack.lock
- name: Upload lockfiles
if: always()
uses: actions/upload-artifact@v4
with:
name: ${{ env.PACKAGE_NAME }}
path: /lockfiles/*.spack.*
if-no-files-found: error