Skip to content

Commit ade9621

Browse files
committed
updated CI/CD deployment workflow
- directly use pypa workflow (instead of MDAnalysis deployment workflow) - use different steps for build and deploy - introduce environments testpypi and pypi - test before upload
1 parent 0052c5b commit ade9621

1 file changed

Lines changed: 174 additions & 35 deletions

File tree

.github/workflows/deploy.yaml

Lines changed: 174 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and upload to PyPi
1+
name: Build and Deploy Package
22

33
on:
44
push:
@@ -9,49 +9,188 @@ on:
99
- published
1010

1111
jobs:
12-
test_pypi_push:
12+
build:
13+
name: Build package
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: "3.x"
23+
24+
- name: Install build dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install build twine
28+
29+
- name: Build package (binary wheel and source distribution package)
30+
run: |
31+
python -m build
32+
33+
- name: Check package
34+
run: |
35+
twine check dist/*
36+
37+
- name: Upload dist files
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: dist-files
41+
path: dist/
42+
retention-days: 1
43+
44+
test-install:
45+
name: Test package installation
46+
runs-on: ubuntu-latest
47+
needs: build
48+
steps:
49+
- name: Set up Python
50+
uses: actions/setup-python@v5
51+
with:
52+
python-version: "3.x"
53+
54+
- name: Download dist files
55+
uses: actions/download-artifact@v4
56+
with:
57+
name: dist-files
58+
path: dist/
59+
60+
- name: Install package
61+
run: |
62+
python -m pip install --upgrade pip
63+
pip install dist/*.whl
64+
65+
- name: Test import
66+
run: |
67+
python -c "import gromacs; print('Package imported successfully')"
68+
69+
test-pytest:
70+
name: Run tests
71+
runs-on: ubuntu-latest
72+
needs: build
73+
steps:
74+
- name: Set up Python
75+
uses: actions/setup-python@v5
76+
with:
77+
python-version: "3.x"
78+
79+
- name: Download dist files
80+
uses: actions/download-artifact@v4
81+
with:
82+
name: dist-files
83+
path: dist/
84+
85+
- name: Install system dependencies (GROMACS)
86+
run: |
87+
sudo apt-get update
88+
sudo apt-get install -y gromacs
89+
90+
- name: Install package with test dependencies
91+
run: |
92+
python -m pip install --upgrade pip
93+
WHEEL_FILE=$(ls dist/*.whl)
94+
pip install "$WHEEL_FILE"[test]
95+
96+
- name: Run tests
97+
run: |
98+
pytest -n auto --verbose --pyargs gromacs
99+
100+
deploy-testpypi:
101+
name: Deploy to TestPyPI
102+
runs-on: ubuntu-latest
103+
needs: [build, test-install, test-pytest]
104+
if: |
105+
github.repository == 'Becksteinlab/GromacsWrapper' &&
106+
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/'))
13107
environment:
14-
name: TestPyPi
108+
name: testpypi
15109
url: https://test.pypi.org/p/GromacsWrapper
16110
permissions:
17-
id-token: write
111+
id-token: write # IMPORTANT: mandatory for trusted publishing
112+
steps:
113+
- name: Download dist files
114+
uses: actions/download-artifact@v4
115+
with:
116+
name: dist-files
117+
path: dist/
118+
119+
- name: Publish to TestPyPI
120+
uses: pypa/gh-action-pypi-publish@v1.12.4
121+
with:
122+
repository-url: https://test.pypi.org/legacy/
123+
124+
deploy-pypi:
125+
name: Deploy to PyPI
126+
runs-on: ubuntu-latest
127+
needs: [build, test-install, test-pytest]
18128
if: |
19129
github.repository == 'Becksteinlab/GromacsWrapper' &&
20-
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/'))
21-
name: "TestPyPi: Build and upload pure Python wheels"
22-
runs-on: ubuntu-latest
23-
24-
steps:
25-
- uses: actions/checkout@v4
26-
27-
- name: testpypi_deploy
28-
uses: MDAnalysis/pypi-deployment@main
29-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
30-
with:
31-
test_submission: true
32-
package_name: 'GromacsWrapper'
33-
module_name: 'gromacs'
34-
tests: false
35-
36-
pypi_push:
130+
(github.event_name == 'release' && github.event.action == 'published')
37131
environment:
38-
name: PyPi
132+
name: pypi
39133
url: https://pypi.org/p/GromacsWrapper
40134
permissions:
41-
id-token: write
135+
id-token: write # IMPORTANT: mandatory for trusted publishing
136+
steps:
137+
- name: Download dist files
138+
uses: actions/download-artifact@v4
139+
with:
140+
name: dist-files
141+
path: dist/
142+
143+
- name: Publish to PyPI
144+
uses: pypa/gh-action-pypi-publish@v1.12.4
145+
146+
test-deployed-testpypi:
147+
name: Test deployed package (TestPyPI)
148+
runs-on: ubuntu-latest
149+
needs: deploy-testpypi
42150
if: |
43151
github.repository == 'Becksteinlab/GromacsWrapper' &&
44-
(github.event_name == 'release' && github.event.action == 'published')
45-
name: "PyPi: Build and upload pure Python wheels"
46-
runs-on: ubuntu-latest
152+
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/'))
153+
steps:
154+
- name: Set up Python
155+
uses: actions/setup-python@v5
156+
with:
157+
python-version: "3.x"
47158

159+
- name: Install from TestPyPI
160+
run: |
161+
python -m pip install --upgrade pip
162+
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ GromacsWrapper[test]
163+
164+
- name: Test import
165+
run: |
166+
python -c "import gromacs; print('Package imported successfully from TestPyPI')"
167+
168+
- name: Run basic tests
169+
run: |
170+
python -c "import gromacs; print('Package version:', gromacs.__version__)"
171+
172+
test-deployed-pypi:
173+
name: Test deployed package (PyPI)
174+
runs-on: ubuntu-latest
175+
needs: deploy-pypi
176+
if: |
177+
github.repository == 'Becksteinlab/GromacsWrapper' &&
178+
(github.event_name == 'release' && github.event.action == 'published')
48179
steps:
49-
- uses: actions/checkout@v4
50-
51-
- name: pypi_deploy
52-
uses: MDAnalysis/pypi-deployment@main
53-
if: github.event_name == 'release' && github.event.action == 'published'
54-
with:
55-
package_name: 'GromacsWrapper'
56-
module_name: 'gromacs'
57-
tests: false
180+
- name: Set up Python
181+
uses: actions/setup-python@v5
182+
with:
183+
python-version: "3.x"
184+
185+
- name: Install from PyPI
186+
run: |
187+
python -m pip install --upgrade pip
188+
pip install GromacsWrapper[test]
189+
190+
- name: Test import
191+
run: |
192+
python -c "import gromacs; print('Package imported successfully from PyPI')"
193+
194+
- name: Run basic tests
195+
run: |
196+
python -c "import gromacs; print('Package version:', gromacs.__version__)"

0 commit comments

Comments
 (0)