Skip to content

Commit 3314c18

Browse files
committed
CI: Update CI to do build/version check/test
1 parent 6e35d6f commit 3314c18

File tree

1 file changed

+101
-58
lines changed

1 file changed

+101
-58
lines changed

.github/workflows/pythonpackage.yml

Lines changed: 101 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -18,85 +18,128 @@ permissions:
1818
contents: read
1919

2020
jobs:
21+
job_metadata:
22+
if: github.repository == 'nipreps/sdcflows'
23+
runs-on: ubuntu-latest
24+
outputs:
25+
commit_message: ${{ steps.get_commit_message.outputs.commit_message }}
26+
version: ${{ steps.show_version.outputs.version }}
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0
32+
- name: Print head git commit message
33+
id: get_commit_message
34+
run: |
35+
if [[ -z "$COMMIT_MSG" ]]; then
36+
COMMIT_MSG=$(git show -s --format=%s $REF)
37+
fi
38+
echo commit_message=$COMMIT_MSG | tee -a $GITHUB_OUTPUT
39+
env:
40+
COMMIT_MSG: ${{ github.event.head_commit.message }}
41+
REF: ${{ github.event.pull_request.head.sha }}
42+
- name: Detect version
43+
id: show_version
44+
run: |
45+
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
46+
VERSION=${GITHUB_REF##*/}
47+
else
48+
pip install setuptools_scm
49+
VERSION=$( python -m setuptools_scm )
50+
fi
51+
echo version=$VERSION | tee -a $GITHUB_OUTPUT
52+
2153
build:
54+
if: github.repository == 'nipreps/sdcflows'
55+
runs-on: ubuntu-latest
56+
steps:
57+
- uses: actions/checkout@v4
58+
with:
59+
fetch-depth: 0
60+
- name: Set up Python 3
61+
uses: actions/setup-python@v4
62+
with:
63+
python-version: 3
64+
- name: Display Python version
65+
run: python -c "import sys; print(sys.version)"
66+
- name: Build niworkflows
67+
run: pipx run build
68+
- name: Check distributions
69+
run: pipx run twine check dist/*
70+
- uses: actions/upload-artifact@v3
71+
with:
72+
name: dist
73+
path: dist/
74+
75+
test:
2276
if: "!startsWith(github.ref, 'refs/tags/') && !contains(github.event.head_commit.message, '[skip ci]')"
77+
needs: [build, job_metadata]
2378
runs-on: ubuntu-latest
2479
strategy:
2580
matrix:
26-
python-version: ["3.8", "3.9", "3.10"]
27-
pip: ["pip==21.2", "pip~=22.0"]
81+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
82+
install: [repo]
83+
include:
84+
- python-version: "3.11"
85+
install: sdist
86+
- python-version: "3.11"
87+
install: wheel
88+
- python-version: "3.11"
89+
install: editable
90+
91+
env:
92+
INSTALL_TYPE: ${{ matrix.install }}
2893

2994
steps:
30-
- uses: actions/checkout@v3
31-
- name: Fetch all tags (for setuptools_scm to work)
32-
run: |
33-
/usr/bin/git -c protocol.version=2 fetch --tags --prune --unshallow origin
95+
- uses: actions/checkout@v4
96+
if: matrix.install == 'repo' || matrix.install == 'editable'
97+
with:
98+
fetch-depth: 0
3499
- name: Set up Python ${{ matrix.python-version }}
35100
uses: actions/setup-python@v4
36101
with:
37102
python-version: ${{ matrix.python-version }}
38-
- uses: actions/cache@v3
103+
- name: Fetch packages
104+
if: matrix.install == 'sdist' || matrix.install == 'wheel'
105+
uses: actions/download-artifact@v3
39106
with:
40-
path: $HOME/.cache/pip
41-
key: pip-cache-v1
42-
restore-keys: |
43-
pip-cache-
44-
- name: Build in confined environment and interpolate version
107+
name: dist
108+
path: dist/
109+
- name: Select archive
45110
run: |
46-
python -m venv /tmp/buildenv
47-
source /tmp/buildenv/bin/activate
48-
python -m pip install -U build "setuptools >= 45" wheel "setuptools_scm >= 6.2" \
49-
setuptools_scm_git_archive pip twine docutils
50-
51-
python -m build -s -w
52-
python -m twine check dist/sdcflows-*
53-
mv dist /tmp/package
54-
rm -rf sdcflows.egg-info/
55-
# Interpolate version
56-
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
57-
TAG=${GITHUB_REF##*/}
111+
if [ "$INSTALL_TYPE" = "sdist" ]; then
112+
ARCHIVE=$( ls dist/*.tar.gz )
113+
elif [ "$INSTALL_TYPE" = "wheel" ]; then
114+
ARCHIVE=$( ls dist/*.whl )
115+
elif [ "$INSTALL_TYPE" = "repo" ]; then
116+
ARCHIVE="."
117+
elif [ "$INSTALL_TYPE" = "editable" ]; then
118+
ARCHIVE="-e ."
58119
fi
59-
THISVERSION=$( python -m setuptools_scm )
60-
THISVERSION=${TAG:-$THISVERSION}
61-
echo "Expected VERSION: \"${THISVERSION}\""
62-
echo "THISVERSION=${THISVERSION}" >> $GITHUB_ENV
63-
- name: Install in confined environment [pip]
64-
run: |
65-
python -m venv /tmp/pip
66-
source /tmp/pip/bin/activate
67-
python -m pip install -U "setuptools >= 45" "setuptools_scm >= 6.2" "${{ matrix.pip }}"
68-
python -m pip install .
69-
INSTALLED_VERSION=$(python -c 'import sdcflows as sdc; print(sdc.__version__, end="")')
70-
echo "VERSION: \"${THISVERSION}\""
71-
echo "INSTALLED: \"${INSTALLED_VERSION}\""
72-
test "${INSTALLED_VERSION}" = "${THISVERSION}"
73-
- name: Install in confined environment [sdist]
74-
run: |
75-
python -m venv /tmp/install_sdist
76-
source /tmp/install_sdist/bin/activate
77-
python -m pip install -U "setuptools >= 45" "${{ matrix.pip }}"
78-
python -m pip install /tmp/package/sdcflows*.tar.gz
79-
INSTALLED_VERSION=$(python -c 'import sdcflows as sdc; print(sdc.__version__, end="")')
80-
echo "VERSION: \"${THISVERSION}\""
81-
echo "INSTALLED: \"${INSTALLED_VERSION}\""
82-
test "${INSTALLED_VERSION}" = "${THISVERSION}"
83-
- name: Install in confined environment [wheel]
120+
echo "ARCHIVE=$ARCHIVE" | tee -a $GITHUB_ENV
121+
- name: Install package
122+
run: python -m pip install $ARCHIVE
123+
- name: Check version
84124
run: |
85-
python -m venv /tmp/install_wheel
86-
source /tmp/install_wheel/bin/activate
87-
python -m pip install -U "setuptools >= 45" "${{ matrix.pip }}"
88-
python -m pip install /tmp/package/sdcflows*.whl
89-
INSTALLED_VERSION=$(python -c 'import sdcflows as sdc; print(sdc.__version__, end="")')
125+
INSTALLED_VERSION=$(python -c 'import sdcflows; print(sdcflows.__version__, end="")')
90126
echo "INSTALLED: \"${INSTALLED_VERSION}\""
91-
test "${INSTALLED_VERSION}" = "${THISVERSION}"
127+
test "${INSTALLED_VERSION}" = "${VERSION}"
128+
env:
129+
VERSION: ${{ needs.job_metadata.outputs.version }}
130+
- name: Install test dependencies
131+
run: python -m pip install "sdcflows[tests]"
132+
- name: Run tests
133+
run: pytest -sv --doctest-modules --cov sdcflows --pyargs sdcflows
134+
- uses: codecov/codecov-action@v3
135+
name: Submit to CodeCov
92136

93137
flake8:
94138
runs-on: ubuntu-latest
95139
steps:
96-
- uses: actions/checkout@v3
140+
- uses: actions/checkout@v4
97141
- name: Set up Python 3
98142
uses: actions/setup-python@v4
99143
with:
100144
python-version: 3
101-
- run: pip install flake8
102-
- run: flake8 sdcflows/
145+
- run: pipx run flake8 sdcflows/

0 commit comments

Comments
 (0)