-
-
Notifications
You must be signed in to change notification settings - Fork 39
148 lines (139 loc) · 6.2 KB
/
Copy pathon_push.yaml
File metadata and controls
148 lines (139 loc) · 6.2 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
139
140
141
142
143
144
145
146
147
148
# Copyright (C) 2022-2023 C-PAC Developers
# This file is part of C-PAC.
# C-PAC is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
# C-PAC is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
# License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with C-PAC. If not, see <https://www.gnu.org/licenses/>.
name: Build and test C-PAC
permissions:
checks: write
contents: read
deployments: write
issues: write
packages: write
pull-requests: write
statuses: write
on:
push:
jobs:
check-updated-preconfigs:
name: Check if preconfigs need updated
outputs:
phase_one: ${{ steps.rebuild.outputs.phase_one }}
rebuild_phase_one: ${{ steps.rebuild.outputs.rebuild_phase_one }}
phase_two: ${{ steps.rebuild.outputs.phase_two }}
rebuild_phase_two: ${{ steps.rebuild.outputs.rebuild_phase_two }}
phase_three: ${{ steps.rebuild.outputs.phase_three }}
rebuild_phase_three: ${{ steps.rebuild.outputs.rebuild_phase_three }}
runs-on: ubuntu-latest
steps:
- name: Check out C-PAC
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Determine stages to rebuild
env:
MESSAGE: ${{ github.event.head_commit.message }}
id: rebuild
run: |
# initialize phase arrays
declare -a PHASE_ONE PHASE_TWO PHASE_THREE REBUILD_PHASE_ONE REBUILD_PHASE_TWO REBUILD_PHASE_THREE
# loop through stages to maybe rebuild
for STAGE in $(cat ${GITHUB_WORKSPACE}/.github/stage_requirements/phase_one.txt)
do
PHASE_ONE+=($STAGE)
# check commit message for [rebuild STAGE] or if STAGE has changed
if [[ "${MESSAGE}" == *"[rebuild ${STAGE}]"* ]]
then
REBUILD_PHASE_ONE+=($STAGE)
fi
done
for STAGE in $(cat ${GITHUB_WORKSPACE}/.github/stage_requirements/phase_two.txt)
do
PHASE_TWO+=($STAGE)
if [[ "${MESSAGE}" == *"[rebuild ${STAGE}]"* ]]
then
REBUILD_PHASE_TWO+=($STAGE)
fi
done
for STAGE in $(cat ${GITHUB_WORKSPACE}/.github/stage_requirements/phase_three.txt)
do
PHASE_THREE+=($STAGE)
if [[ "${MESSAGE}" == *"[rebuild ${STAGE}]"* ]] || [[ "${MESSAGE}" == *"[rebuild base-${STAGE}]"* ]]
then
REBUILD_PHASE_THREE+=($STAGE)
fi
done
# add base stages based on their dependencies
BASES=("${PHASE_THREE[@]}" standard)
if [[ "${MESSAGE}" == *"[rebuild standard]"* ]] || [[ "${MESSAGE}" == *"[rebuild base-standard]"* ]]
then
REBUILD_PHASE_THREE+=(standard)
fi
for BASE in $BASES
do
for STAGE in $(cat ${GITHUB_WORKSPACE}/.github/stage_requirements/${BASE}.txt)
do
if ([[ " ${REBUILD_PHASE_ONE[*]} " =~ " ${STAGE} " ]] || [[ " ${REBUILD_PHASE_TWO[*]} " =~ " ${STAGE} " ]]) && [[ ! " ${REBUILD_PHASE_THREE[*]} " =~ " ${STAGE} " ]]
then
REBUILD_PHASE_THREE+=($BASE)
fi
done
done
# send stages to rebuild as JSON strings to job outputs
phase_one=$(jq --compact-output --null-input '$ARGS.positional' --args -- ${PHASE_ONE[@]})
rebuild_phase_one=$(jq --compact-output --null-input '$ARGS.positional' --args -- ${REBUILD_PHASE_ONE[@]})
phase_two=$(jq --compact-output --null-input '$ARGS.positional' --args -- ${PHASE_TWO[@]})
rebuild_phase_two=$(jq --compact-output --null-input '$ARGS.positional' --args -- ${REBUILD_PHASE_TWO[@]})
phase_three=$(jq --compact-output --null-input '$ARGS.positional' --args -- ${PHASE_THREE[@]})
rebuild_phase_three=$(jq --compact-output --null-input '$ARGS.positional' --args -- ${REBUILD_PHASE_THREE[@]})
echo "phase_one=${phase_one}" >> $GITHUB_OUTPUT
echo "rebuild_phase_one=${rebuild_phase_one}" >> $GITHUB_OUTPUT
echo "phase_two=${phase_two}" >> $GITHUB_OUTPUT
echo "rebuild_phase_two=${rebuild_phase_two}" >> $GITHUB_OUTPUT
echo "phase_three=${phase_three}" >> $GITHUB_OUTPUT
echo "rebuild_phase_three=${rebuild_phase_three}" >> $GITHUB_OUTPUT
check_pr:
runs-on: ubuntu-latest
outputs:
test_mode: ${{ steps.check_pr.outputs.test_mode }}
steps:
- name: Check out C-PAC
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Check if commit is in a PR to develop
id: check_pr
run: |
TEST_MODE=none
if echo "${{ github.event.head_commit.message }}" | grep -q '\[run reg-suite lite\]'
then
TEST_MODE=lite
elif gh pr list --base develop --json number,state,draft | jq 'any(.[]; .state == "OPEN" or .draft == true)'; then
TEST_MODE=lite
elif gh pr list --base main --json number,state,draft | jq 'any(.[]; .state == "OPEN" or .draft == true)'; then
TEST_MODE=full
fi
echo "test_mode=${TEST_MODE}"
echo "test_mode=${TEST_MODE}" >> $GITHUB_OUTPUT
build-stages:
name: Build multistage image stages
needs:
- check_pr
- check-updated-preconfigs
uses: ./.github/workflows/build_and_test.yaml
secrets: inherit
with:
phase_one: ${{ needs.check-updated-preconfigs.outputs.phase_one }}
rebuild_phase_one: ${{ needs.check-updated-preconfigs.outputs.rebuild_phase_one }}
phase_two: ${{ needs.check-updated-preconfigs.outputs.phase_two }}
rebuild_phase_two: ${{ needs.check-updated-preconfigs.outputs.rebuild_phase_two }}
phase_three: ${{ needs.check-updated-preconfigs.outputs.phase_three }}
rebuild_phase_three: ${{ needs.check-updated-preconfigs.outputs.rebuild_phase_three }}
test_mode: ${{ needs.check_pr.outputs.test_mode }}