Skip to content

test [run reg-suite] #369

test [run reg-suite]

test [run reg-suite] #369

Workflow file for this run

# 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
- uses: actions/setup-python@v4
with:
python-version: '3.9'
cache: 'pip'
- name: Check if version updated
id: version_updated
run: |
git config --global user.email "[email protected]"
git config --global user.name "Theodore (Machine User)"
GITHUB_BRANCH=$(echo ${GITHUB_REF} | cut -d '/' -f 3-)
export PYTHONPATH=$PWD
pip install -q wheel
pip install -q nipype numpy matplotlib pandas pathvalidate pytz pyyaml voluptuous
python ./CPAC/utils/configuration/yaml_template.py
if [[ ! -z $(git diff origin/${GITHUB_BRANCH}) ]]
then
git add CPAC/resources/configs
git commit -m ":bulb: Update comments based on default preconfig"
fi
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
if [[ ! "$COMMIT_MESSAGE" == *"Update version to"* ]]
then
cd CPAC
VERSION=$(python -c "from info import __version__; print(('.'.join(('.'.join(__version__[::-1].split('-')[1].split('.')[1:])[::-1], __version__.split('-')[1])) if '-' in __version__ else __version__).split('+', 1)[0])")
cd ..
echo "v${VERSION}" > version
find ./CPAC/resources/configs -name "*.yml" -exec sed -i -r "s/^(# [Vv]ersion ).*$/# Version ${VERSION}/g" {} \;
git add version
VERSIONS=($(git diff origin/${GITHUB_BRANCH} -- version | tail -n 2))
export PATTERN="(declare|typeset) -a"
if [[ "$(declare -p VERSIONS)" =~ $PATTERN ]]
then
for DOCKERFILE in $(find ./.github/Dockerfiles -name "*.Dockerfile")
do
export IFS=""
for LINE in $(grep "FROM ghcr\.io/fcp\-indi/c\-pac/.*\-${VERSIONS[0]:1}" ${DOCKERFILE})
do
echo "Updating stage tags in ${DOCKERFILE}"
sed -i "s/\-${VERSIONS[0]:1}/\-${VERSIONS[1]:1}/g" ${DOCKERFILE}
done
done
unset IFS
fi
if [[ ! -z $(git diff origin/${GITHUB_BRANCH}) ]]
then
git add CPAC/resources/configs .github/Dockerfiles
git commit -m ":bookmark: Update version to ${VERSION} ($COMMIT_MESSAGE)" || true
git push origin HEAD:${GITHUB_BRANCH} || true
fi
cd ..
fi
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]
then
cd $HOME/work/C-PAC/C-PAC
for DOCKERFILE in $(ls .github/Dockerfiles/C-PAC.develop-*.Dockerfile)
do
if [[ "$DOCKERFILE" =~ .*C-PAC.develop-(.*)-(bionic|xenial).Dockerfile ]]
then
cp $DOCKERFILE variant-${BASH_REMATCH[1]}.Dockerfile
else
cp $DOCKERFILE Dockerfile
fi
done
git add *ockerfile
git commit -m ":truck: Copy develop Dockerfiles to root directory \
\
[skip ci]"
git push origin HEAD:${GITHUB_BRANCH} || true
fi
- 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 }}