-
-
Notifications
You must be signed in to change notification settings - Fork 41
121 lines (114 loc) · 5.71 KB
/
on_push.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
# 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
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@v3
with:
fetch-depth: 2
- name: Get changed files since last commit
uses: tj-actions/changed-files@v41.0.0
id: changed-files
with:
since_last_remote_commit: "true"
files: .github/Dockerfiles/*
json: "true"
- 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
# turn JSON array into BASH array
CHANGED_FILES=( $(echo ${{ steps.changed-files.outputs.all_changed_files }} | sed -e 's/\[//g' -e 's/\]//g' -e 's/\,/ /g') )
# 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}]"* ]] || [[ " ${CHANGED_FILES[*]} " =~ " ${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}]"* ]] || [[ " ${CHANGED_FILES[*]} " =~ " ${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}]"* ]] || [[ " ${CHANGED_FILES[*]} " =~ " ${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]"* ]] || [[ " ${CHANGED_FILES[*]} " =~ " 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
build-stages:
name: Build multistage image stages
needs: check-updated-preconfigs
uses: ./.github/workflows/build_and_test.yml
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 }}