Repository navigation
198 lines (173 loc) · 5.89 KB
/
Copy pathpython-package.yml
File metadata and controls
198 lines (173 loc) · 5.89 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
name: Python package
on:
push:
# Branch pushes build wheels on forks; upstream uses tags and pull requests.
branches:
- "**"
tags:
- "v*"
pull_request:
# closed is listed only so that closing or merging a PR starts a run that, through the concurrency
# group below, cancels the CI still running for it; all the jobs of that run are skipped.
types: [opened, synchronize, reopened, closed]
workflow_dispatch:
inputs:
publish_to_testpypi:
description: Publish the validated source distribution to TestPyPI
required: true
type: boolean
default: false
# Match the main CI policy: cancel superseded pull request runs, and keep branch
# runs grouped so only the newest queued run is retained.
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: read
jobs:
sdist:
if: github.event.action != 'closed' && (github.repository != 'plumed/plumed2' || github.event_name != 'push' || startsWith(github.ref, 'refs/tags/'))
name: Build source distribution
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: "3.11"
- name: Install build and validation tools
run: python -m pip install --upgrade pip build twine
- name: Prepare package version
working-directory: python
run: cp ../VERSION.txt PLUMED_VERSION
- name: Check release tag version
if: startsWith(github.ref, 'refs/tags/v')
run: |
package_version="$(grep -v '^#' VERSION.txt | tr -d '[:space:]')"
tag_version="${GITHUB_REF_NAME#v}"
test "$package_version" = "$tag_version" || {
echo "Tag $tag_version does not match VERSION.txt ($package_version)" >&2
exit 1
}
- name: Build source distribution
working-directory: python
run: python -m build --sdist
- uses: actions/upload-artifact@v6
with:
name: python-package-sdist
path: python/dist/*.tar.gz
wheels:
name: Wheels (${{ matrix.os }}, ${{ matrix.arch }})
needs: sdist
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-24.04
arch: x86_64
- os: ubuntu-24.04-arm
arch: aarch64
- os: macos-15-intel
arch: x86_64
- os: macos-15
arch: arm64
# kernel built with CMake and Visual Studio (see python/build_backend.py)
- os: windows-latest
arch: AMD64
runs-on: ${{ matrix.os }}
defaults:
run:
# Git Bash on Windows
shell: bash
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: "3.12"
- uses: actions/download-artifact@v7
with:
name: python-package-sdist
path: dist
- name: Extract source distribution
run: |
mkdir source
tar -xzf dist/*.tar.gz -C source
archive_root="$(tar -tzf dist/*.tar.gz | sed -n '1s,/.*,,p')"
# a native path, also for the Windows python (Git Bash $PWD is /d/a/...)
workdir="$(python -c 'import os; print(os.getcwd())')"
echo "PROJECT_DIR=$workdir/source/$archive_root" >> "$GITHUB_ENV"
- name: Build and test wheels
env:
CIBW_ARCHS: ${{ matrix.arch }}
run: |
python -m pip install --upgrade cibuildwheel twine
python -m cibuildwheel "$PROJECT_DIR" --output-dir wheelhouse
python -m twine check wheelhouse/*.whl
if [[ "$RUNNER_OS" == "Linux" ]]; then
python -m pip install auditwheel
for wheel in wheelhouse/*.whl; do auditwheel show "$wheel"; done
fi
# also when a later wheel fails, so that the ones already built can be inspected
- uses: actions/upload-artifact@v6
if: success() || failure()
with:
name: python-package-wheels-${{ matrix.os }}-${{ matrix.arch }}
path: wheelhouse/*.whl
if-no-files-found: ignore
publish:
name: Publish to PyPI
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
needs: [sdist, wheels]
runs-on: ubuntu-24.04
environment:
name: pypi
url: https://pypi.org/p/plumed
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v7
with:
pattern: python-package-sdist
path: dist
merge-multiple: true
- uses: actions/download-artifact@v7
with:
pattern: python-package-wheels-*
path: dist
merge-multiple: true
- uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Validate release artifacts
run: |
python -m pip install twine
python -m twine check dist/*
- name: Publish distributions
uses: pypa/gh-action-pypi-publish@release/v1
publish-testpypi:
name: Publish to TestPyPI
if: github.event_name == 'workflow_dispatch' && inputs.publish_to_testpypi
needs: [sdist, wheels]
runs-on: ubuntu-24.04
environment:
name: testpypi
url: https://test.pypi.org/p/plumed
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v7
with:
pattern: python-package-sdist
path: dist
merge-multiple: true
- uses: actions/download-artifact@v7
with:
pattern: python-package-wheels-*
path: dist
merge-multiple: true
- uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Publish distributions
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/