👔 Use max_iter
parameter for longitudinal template generation.
#1188
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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/[email protected] | |
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 }} |