Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/Dockerfiles/C-PAC.develop-jammy.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# 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/>.
FROM ghcr.io/fcp-indi/c-pac/stage-base:standard-v1.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev1
FROM ghcr.io/fcp-indi/c-pac/stage-base:standard-v1.8.8.dev1
LABEL org.opencontainers.image.description="Full C-PAC image"
LABEL org.opencontainers.image.source=https://github.com/FCP-INDI/C-PAC
USER root
Expand Down Expand Up @@ -42,7 +42,7 @@ RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /root/.cache/* \
&& apt-get autoremove -y \
&& ldconfig \
&& chmod 777 / \
&& chmod 777 $(ls / | grep -v1.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev1 sys | grep -v1.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev1 proc)
&& chmod 777 $(ls / | grep -v sys | grep -v proc)
ENV PYTHONUSERBASE=/home/c-pac_user/.local
ENV PATH=$PATH:/home/c-pac_user/.local/bin \
PYTHONPATH=$PYTHONPATH:$PYTHONUSERBASE/lib/python3.10/site-packages \
Expand Down
4 changes: 2 additions & 2 deletions .github/Dockerfiles/C-PAC.develop-lite-jammy.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# 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/>.
FROM ghcr.io/fcp-indi/c-pac/stage-base:lite-v1.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev1
FROM ghcr.io/fcp-indi/c-pac/stage-base:lite-v1.8.8.dev1
LABEL org.opencontainers.image.description="Full C-PAC image without FreeSurfer"
LABEL org.opencontainers.image.source=https://github.com/FCP-INDI/C-PAC
USER root
Expand Down Expand Up @@ -43,7 +43,7 @@ RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /root/.cache/* \
&& apt-get autoremove -y \
&& ldconfig \
&& chmod 777 / \
&& chmod 777 $(ls / | grep -v1.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev1 sys | grep -v1.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev1 proc)
&& chmod 777 $(ls / | grep -v sys | grep -v proc)
ENV PYTHONUSERBASE=/home/c-pac_user/.local
ENV PATH=$PATH:/home/c-pac_user/.local/bin \
PYTHONPATH=$PYTHONPATH:$PYTHONUSERBASE/lib/python3.10/site-packages \
Expand Down
4 changes: 2 additions & 2 deletions .github/Dockerfiles/base-standard.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# License along with C-PAC. If not, see <https://www.gnu.org/licenses/>.
FROM ghcr.io/fcp-indi/c-pac/freesurfer:6.0.0-min.neurodocker-jammy AS freesurfer

FROM ghcr.io/fcp-indi/c-pac/stage-base:lite-v1.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev1
FROM ghcr.io/fcp-indi/c-pac/stage-base:lite-v1.8.8.dev1
LABEL org.opencontainers.image.description="NOT INTENDED FOR USE OTHER THAN AS A STAGE IMAGE IN A MULTI-STAGE BUILD \
Standard software dependencies for C-PAC standard images"
LABEL org.opencontainers.image.source=https://github.com/FCP-INDI/C-PAC
Expand Down Expand Up @@ -56,7 +56,7 @@ RUN apt-get autoremove -y \
&& rm -rf results.txt \
&& ldconfig \
&& chmod 777 / /home/c-pac_user \
&& chmod 777 $(ls / | grep -v1.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev1 sys | grep -v1.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev11.8.8.dev1 proc)
&& chmod 777 $(ls / | grep -v sys | grep -v proc)

# set user
USER c-pac_user
206 changes: 163 additions & 43 deletions .github/scripts/autoversioning.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#!/usr/bin/env bash

# Copyright (C) 2024 C-PAC Developers
# Copyright (C) 2024-2025 C-PAC Developers

# This file is part of C-PAC.

Expand All @@ -17,54 +17,174 @@
# 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/>.

# Update version comment strings
function wait_for_git_lock() {
while [ -f "./.git/index.lock" ]; do
echo "Waiting for the git lock file to be removed..."
sleep 1
done

set -euo pipefail
trap 'echo "❌ Script failed at line $LINENO with exit code $?"' ERR

# -------------------------------------------------------------------------
# Helpers
# -------------------------------------------------------------------------

git_add_with_retry() {
local file=$1
local attempts=0
local max_attempts=10
while ! git add "$file"; do
attempts=$((attempts+1))
echo "Git add failed for $file (attempt $attempts), retrying..."
sleep 1
if [[ $attempts -ge $max_attempts ]]; then
echo "❌ Failed to git add $file after $max_attempts attempts"
exit 1
fi
done
}

update_file_if_changed() {
# Run a regex replacement or copy on a file and stage it if it changed
local expr=$1
local src=$2
local dest=${3:-$src}

local changed=0
if [[ -n "$expr" ]]; then
tmp=$(mktemp)
sed -E "$expr" "$src" > "$tmp"
if ! cmp -s "$tmp" "$dest"; then
mv "$tmp" "$dest"
git_add_with_retry "$dest"
changed=1
else
rm "$tmp"
fi
else
if [[ ! -f "$dest" ]] || ! cmp -s "$src" "$dest"; then
cp "$src" "$dest"
git_add_with_retry "$dest"
changed=1
fi
fi
return $changed
}

cd CPAC || exit 1
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
export _SED_COMMAND="s/^(# [Vv]ersion ).*$/# Version ${VERSION}/g"
if [[ "$OSTYPE" == "darwin"* ]]; then
# Mac OSX
find ./CPAC/resources/configs -name "*.yml" -exec sed -i '' -E "${_SED_COMMAND}" {} \;
log_info() {
echo "=== $* ==="
}

# -------------------------------------------------------------------------
# Main
# -------------------------------------------------------------------------

START_DIR=$(pwd)
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
REPO_ROOT="$(realpath "$SCRIPT_DIR/../..")"

# -------------------------------------------------------------------------
# Fetch version
# -------------------------------------------------------------------------
log_info "Fetching version"
VERSION=$(python -c "import sys; sys.path.insert(0, '$REPO_ROOT/CPAC'); from info import __version__; print(__version__.split('+', 1)[0])")
VERSION_FILE="$REPO_ROOT/version"
if [[ -f "$VERSION_FILE" ]]; then
cd "$REPO_ROOT"
OLD_VERSION=$(git show "$(git log --pretty=format:'%h' -n 1 -- version | tail -n 1)":version)
cd "$START_DIR"
else
# Linux and others
find ./CPAC/resources/configs -name "*.yml" -exec sed -i'' -r "${_SED_COMMAND}" {} \;
OLD_VERSION="<none>"
fi
wait_for_git_lock && git add version
VERSIONS=( `git show $(git log --pretty=format:'%h' -n 1 version | tail -n 1):version` `cat version` )
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]}" ${DOCKERFILE})
do
echo "Updating stage tags in ${DOCKERFILE}"
echo "v${VERSION}" > "$VERSION_FILE"

# -------------------------------------------------------------------------
# Write version file and stage it
# -------------------------------------------------------------------------
log_info "Updating version file"
if update_file_if_changed "" <(echo "v${VERSION}") "$VERSION_FILE"; then
git_add_with_retry "$VERSION_FILE"
fi

# -------------------------------------------------------------------------
# Update YAML config files
# -------------------------------------------------------------------------
log_info "Updating YAML config files"
VERSION_EXPR="s/^(# [Vv]ersion ).*$/# Version ${VERSION}/g"
for YAML_FILE in "$REPO_ROOT"/CPAC/resources/configs/{*.yml,*.yaml,test_configs/*.yml,test_configs/*.yaml}; do
[[ -e "$YAML_FILE" ]] || continue

echo "Processing ${YAML_FILE}"
echo "Applying regex: ${VERSION_EXPR}"

# Run sed safely
tmp=$(mktemp)
if ! sed -E "$VERSION_EXPR" "$YAML_FILE" > "$tmp"; then
echo "❌ sed failed on $YAML_FILE"
rm "$tmp"
exit 1
fi

if ! cmp -s "$tmp" "$YAML_FILE"; then
mv "$tmp" "$YAML_FILE"
echo "Updated $YAML_FILE"
git_add_with_retry "$YAML_FILE"
else
rm "$tmp"
echo "No changes needed for $YAML_FILE"
fi
done

# -------------------------------------------------------------------------
# Update Dockerfiles (only C-PAC tags)
# -------------------------------------------------------------------------
log_info "Updating Dockerfiles"
NEW_VERSION=$(<"$VERSION_FILE")

if [[ "$OLD_VERSION" != "$NEW_VERSION" ]]; then
for DOCKERFILE in "$REPO_ROOT"/.github/Dockerfiles/*.Dockerfile; do
if grep -q "FROM ghcr\.io/fcp-indi/c-pac/.*-${OLD_VERSION}" "$DOCKERFILE"; then
echo "Updating C-PAC version in ${DOCKERFILE} from ${OLD_VERSION} to ${NEW_VERSION}"

if [[ "$OSTYPE" == "darwin"* ]]; then
# Mac OSX
sed -i "" "s/\-${VERSIONS[0]}/\-${VERSIONS[1]}/g" ${DOCKERFILE}
# macOS sed
sed -i "" "s/-${OLD_VERSION}/-${NEW_VERSION}/g" "$DOCKERFILE"
else
# Linux and others
sed -i "s/\-${VERSIONS[0]}/\-${VERSIONS[1]}/g" ${DOCKERFILE}
# Linux sed
sed -i -E "s/-${OLD_VERSION}/-${NEW_VERSION}/g" "$DOCKERFILE"
fi
done

git_add_with_retry "$DOCKERFILE"
fi
done
unset IFS
fi
wait_for_git_lock && git add CPAC/resources/configs .github/Dockerfiles

# Overwrite top-level Dockerfiles with the CI Dockerfiles
wait_for_git_lock && cp .github/Dockerfiles/C-PAC.develop-jammy.Dockerfile Dockerfile
wait_for_git_lock && cp .github/Dockerfiles/C-PAC.develop-lite-jammy.Dockerfile variant-lite.Dockerfile
for DOCKERFILE in $(ls *Dockerfile)
do
wait_for_git_lock && git add $DOCKERFILE

# -------------------------------------------------------------------------
# Overwrite top-level Dockerfiles
# -------------------------------------------------------------------------
log_info "Updating top-level Dockerfiles"
TOP_DOCKERFILES=(
".github/Dockerfiles/C-PAC.develop-jammy.Dockerfile:Dockerfile"
".github/Dockerfiles/C-PAC.develop-lite-jammy.Dockerfile:variant-lite.Dockerfile"
)
for SRC_DST in "${TOP_DOCKERFILES[@]}"; do
# Split SRC_DST by colon safely
SRC="${SRC_DST%%:*}"
DST="${SRC_DST##*:}"

FULL_SRC="$REPO_ROOT/$SRC"
FULL_DST="$REPO_ROOT/$DST"

if [[ ! -f "$FULL_SRC" ]]; then
echo "⚠️ Source Dockerfile does not exist: $FULL_SRC"
continue
fi
echo "Updating top-level Dockerfile: $FULL_DST from $FULL_SRC"
cp "$FULL_SRC" "$FULL_DST" && git_add_with_retry "$FULL_DST"
done

# Return to original directory
cd "$START_DIR"

# -------------------------------------------------------------------------
# Summary
# -------------------------------------------------------------------------
echo
echo "Version changed: (from ${OLD_VERSION} to ${NEW_VERSION})"
echo "======================"
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ repos:
name: Update Dockerfiles and version comments
entry: .github/scripts/autoversioning.sh
language: script
files: '.*Dockerfile$|.*\.yaml$|^CPAC/info\.py$'
files: '(^CPAC/info\.py$|.*Dockerfile$|.*\.ya?ml$)'
- id: update-yaml-comments
name: Update YAML comments
entry: CPAC/utils/configuration/yaml_template.py
Expand Down
6 changes: 5 additions & 1 deletion CPAC/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ def _docs_prefix() -> str:
return DOCS_URL_PREFIX


license_notice = f"""Copyright (C) 2022-2024 C-PAC Developers.
def license_notice() -> str:
"""Get the license notice for this version."""
return f"""Copyright (C) 2022-2024 C-PAC Developers.

This program comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions. For
details, see {_docs_prefix()}/license or the COPYING and
COPYING.LESSER files included in the source code."""


__all__ = ["license_notice", "version", "__version__"]
16 changes: 11 additions & 5 deletions CPAC/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,22 @@

def get_cpac_gitversion() -> str | None:
"""CPAC version as reported by the last commit in git."""
from pathlib import Path
from importlib.resources import as_file, files
import subprocess

gitpath = Path(__file__).parent.resolve()

gitpathgit = gitpath / ".git"
if not gitpathgit.exists():
with as_file(files("CPAC")) as _cpac:
gitpath = _cpac
gitpathgit = None
for _cpacpath in [gitpath, *gitpath.parents]:
git_dir = _cpacpath / ".git"
if git_dir.exists():
gitpathgit = git_dir
break
if not gitpathgit:
return None

ver = None

try:
o, _ = subprocess.Popen(
"git describe --always", shell=True, cwd=gitpath, stdout=subprocess.PIPE
Expand Down
2 changes: 1 addition & 1 deletion CPAC/pipeline/cpac_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def run_workflow(
)
if c.pipeline_setup["system_config"]["random_seed"] is not None
else "",
license_notice=CPAC.license_notice.replace("\n", "\n "),
license_notice=CPAC.license_notice().replace("\n", "\n "),
),
)
subject_info = {}
Expand Down
2 changes: 1 addition & 1 deletion CPAC/resources/configs/data_config_S3-BIDS-ABIDE.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# CPAC Data Configuration File
# Version
# Version 1.8.8.dev1
#
# http://fcp-indi.github.io for more info.
#
Expand Down
2 changes: 1 addition & 1 deletion CPAC/resources/configs/data_config_S3-BIDS-ADHD200.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# CPAC Data Configuration File
# Version
# Version 1.8.8.dev1
#
# http://fcp-indi.github.io for more info.
#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# CPAC Data Configuration File
# Version
# Version 1.8.8.dev1
#
# http://fcp-indi.github.io for more info.
#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# CPAC Data Configuration File
# Version
# Version 1.8.8.dev1
#
# http://fcp-indi.github.io for more info.
#
Expand Down
2 changes: 1 addition & 1 deletion CPAC/resources/configs/data_config_cpac_benchmark.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# CPAC Data Configuration File
# Version
# Version 1.8.8.dev1
#
# http://fcp-indi.github.io for more info.
#
Expand Down
2 changes: 1 addition & 1 deletion CPAC/resources/configs/data_settings_template.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# CPAC Data Settings File
# Version
# Version 1.8.8.dev1
#
# http://fcp-indi.github.io for more info.
#
Expand Down
2 changes: 1 addition & 1 deletion CPAC/resources/configs/group_config_template.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# CPAC Group-Level Analysis Configuration YAML file
# Version
# Version 1.8.8.dev1
#
# http://fcp-indi.github.io for more info.
#
Expand Down
Loading