-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (127 loc) · 5.09 KB
/
ci.yml
File metadata and controls
138 lines (127 loc) · 5.09 KB
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
138
# Requires vars.NAME to be set as a variable.
name: CI
on:
pull_request:
types:
- opened
- reopened
- synchronize
- closed
- ready_for_review
- converted_to_draft
branches:
- main
- dev
- backport/*.*
paths:
- config/**
- '**/spack.yaml'
issue_comment:
types:
- created
- edited
jobs:
# FIXME: For now, this modified workflow does not deploy based on changes to the config/** files.
# If you change the config/** files, you will need to manually update the manifests you want to deploy.
setup-pr:
name: Setup PR Info
if: >-
github.event_name == 'pull_request' ||
(github.event_name == 'issue_comment' && startsWith(github.event.comment.body, '!redeploy'))
runs-on: ubuntu-latest
outputs:
manifest: ${{ steps.matrix.outputs.string }}
steps:
- name: Get PR HEAD
# Get the HEAD of the pull request, which is obtained differently depending on the event (pull_request or issue_comment)
id: pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.event.issue.number }}
run: |
head=$(gh pr view \
${{ env.PR_NUMBER }} \
--repo ${{ github.repository }} \
--json headRefName \
--jq '.headRefName'
)
echo "For ${{ github.event_name }} the PR number is ${{ env.PR_NUMBER }} and the head is $head"
echo "head=$head" >> $GITHUB_OUTPUT
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ steps.pr.outputs.head }}
- name: Get changed files
# Get changed **/spack.yaml files so we can deploy them
id: changed-files
uses: tj-actions/changed-files@ed68ef82c095e0d48ec87eccea555d944a631a4c # v46.0.6
with:
# If it is a non-closed pull request, we want to get the changed files since the last remote commit, so we don't redeploy files not changed in a commit
# If it is a closed PR, or an issue_comment with !redeploy, we want to get the changed files across the whole branch
since_last_remote_commit: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
json: true
output_dir: .
write_output_files: true
files: |
**/spack.yaml
- name: Format changed files
# We reformat the json list of changed files as list of objects containing the name (the containing folder) and the path (the containing folder AND manifest name)
# Eg, ["fre-nctools/spack.yaml", "gh/spack.yaml"] becomes: [{"name": "fre-nctools", "path": "fre-nctools/spack.yaml"}, {"name": "gh", "path": "gh/spack.yaml"}]
id: matrix
run: |
echo "Changed files: ${{ steps.changed-files.outputs.all_changed_files }}"
echo "All changed files:"
cat all_changed_files.json
echo ""
jq -c '[.[] | {name: split("/")[0], path: .}]' all_changed_files.json > matrix.json
echo "Matrix:"
cat matrix.json
echo "string=$(cat matrix.json)" >> $GITHUB_OUTPUT
pr-ci:
name: CI
needs:
- setup-pr
# A matrix strategy with no elements is considered an error, so we only run this job if there are changed manifests
# and it is either a non-closed pull request or an issue comment that starts with !redeploy
if: >-
needs.setup-pr.outputs.manifest != '[]' &&
((github.event_name == 'pull_request' && github.event.action != 'closed') ||
(github.event_name == 'issue_comment' && startsWith(github.event.comment.body, '!redeploy')))
strategy:
# The failure of install of an unrelated tool shouldn't affect the others
fail-fast: false
# We don't want to spam the spack instance with install requests - this means that it will seem that
# only one of the jobs is being run within the matrix.
max-parallel: 1
matrix:
manifest: ${{ fromJson(needs.setup-pr.outputs.manifest) }}
uses: access-nri/build-cd/.github/workflows/ci.yml@v8
with:
model: ${{ matrix.manifest.name }}
spack-manifest-path: ${{ matrix.manifest.path }}
spack-manifest-schema-version: 2-0-0
config-versions-schema-version: 4-0-0
config-packages-schema-version: 1-0-0
permissions:
pull-requests: write
contents: write
statuses: write
secrets: inherit
pr-closed:
name: Closed
if: >-
needs.setup-pr.outputs.manifest != '[]' &&
github.event_name == 'pull_request' && github.event.action == 'closed'
needs:
- setup-pr
strategy:
# The failure of uninstall of an unrelated tool shouldn't affect the others
fail-fast: false
# We don't want to spam the spack instance with uninstall requests
max-parallel: 1
matrix:
manifest: ${{ fromJson(needs.setup-pr.outputs.manifest) }}
uses: access-nri/build-cd/.github/workflows/ci-closed.yml@v8
with:
spack-manifest-path: ${{ matrix.manifest.path }}
secrets: inherit