generated from nipreps/Cookiecutter
-
Notifications
You must be signed in to change notification settings - Fork 1
148 lines (140 loc) · 4.04 KB
/
build-test.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: Build & test
on:
push:
branches:
- main
tags:
- "*"
pull_request:
branches:
- main
schedule:
- cron: '0 0 * * 1'
defaults:
run:
shell: bash
concurrency:
group: python-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
job_metadata:
if: github.repository == 'nipreps/synthstrip'
runs-on: ubuntu-latest
outputs:
commit_message: ${{ steps.get_commit_message.outputs.commit_message }}
version: ${{ steps.show_version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Print head git commit message
id: get_commit_message
run: |
if [[ -z "$COMMIT_MSG" ]]; then
COMMIT_MSG=$(git show -s --format=%s $REF)
fi
echo commit_message=$COMMIT_MSG | tee -a $GITHUB_OUTPUT
env:
COMMIT_MSG: ${{ github.event.head_commit.message }}
REF: ${{ github.event.pull_request.head.sha }}
- name: Detect version
id: show_version
run: |
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
VERSION=${GITHUB_REF##*/}
else
pipx run hatch version # Once to avoid output of initial setup
VERSION=$( pipx run hatch version )
fi
echo version=$VERSION | tee -a $GITHUB_OUTPUT
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3
- name: Display Python information
run: python -c "import sys; print(sys.version)"
- name: Build sdist and wheel
run: pipx run build
- name: Check release tools
run: pipx run twine check dist/*
- name: Save build output
uses: actions/upload-artifact@v3
with:
name: dist
path: dist/
test:
needs: [job_metadata, build]
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
install: [repo]
include:
- python-version: "3.12"
install: sdist
- python-version: "3.12"
install: wheel
- python-version: "3.12"
install: editable
env:
INSTALL_TYPE: ${{ matrix.install }}
steps:
- uses: actions/checkout@v4
if: matrix.install == 'repo' || matrix.install == 'editable'
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Fetch packages
if: matrix.install == 'sdist' || matrix.install == 'wheel'
uses: actions/download-artifact@v3
with:
name: dist
path: dist/
- name: Select archive
run: |
if [ "$INSTALL_TYPE" = "sdist" ]; then
ARCHIVE=$( ls dist/*.tar.gz )
elif [ "$INSTALL_TYPE" = "wheel" ]; then
ARCHIVE=$( ls dist/*.whl )
elif [ "$INSTALL_TYPE" = "repo" ]; then
ARCHIVE="."
elif [ "$INSTALL_TYPE" = "editable" ]; then
ARCHIVE="-e ."
fi
echo "ARCHIVE=$ARCHIVE" | tee -a $GITHUB_ENV
- name: Install package
run: python -m pip install $ARCHIVE
- name: Check version
run: |
INSTALLED_VERSION=$(python -c 'from nipreps.synthstrip import __version__; print(__version__, end="")')
echo "INSTALLED: \"${INSTALLED_VERSION}\""
test "${INSTALLED_VERSION}" = "${VERSION}"
env:
VERSION: ${{ needs.job_metadata.outputs.version }}
- name: Ensure CLI tool is available
run: nipreps-synthstrip -h
publish:
runs-on: ubuntu-latest
needs: test
if: github.repository == 'nipreps/synthstrip' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/download-artifact@v3
with:
name: dist
path: dist/
- uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}