-
Notifications
You must be signed in to change notification settings - Fork 3
202 lines (173 loc) · 5.54 KB
/
deployment.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
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
199
200
201
202
name: Build and Deploy Package
on:
push:
paths:
- src/mrpro/VERSION
jobs:
build-testpypi-package:
name: Build Package for TestPyPI
runs-on: ubuntu-latest
outputs:
version: ${{ steps.set_suffix.outputs.version }}
suffix: ${{ steps.set_suffix.outputs.suffix }}
version_changed: ${{ steps.changes.outputs.version_changed }}
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Checkout Code
uses: actions/checkout@v4
- name: Check if VERSION file is modified compared to main
uses: dorny/paths-filter@v3
id: changes
with:
base: main
filters: |
version_changed:
- 'src/mrpro/VERSION'
- name: Set Version Suffix
id: set_suffix
run: |
VERSION=$(cat src/mrpro/VERSION)
SUFFIX=rc$(date +%s)
echo "MRPROVERSIONSUFFIX=$SUFFIX" >> $GITHUB_ENV
echo "suffix=$SUFFIX" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Build Package
run: |
python -m pip install --upgrade build
python -m build
- name: Upload TestPyPI Distribution Artifact
uses: actions/upload-artifact@v4
with:
name: testpypi-package-distribution
path: dist/
testpypi-deployment:
name: Deploy to TestPyPI
needs:
- build-testpypi-package
runs-on: ubuntu-latest
if: needs.build-testpypi-package.outputs.version_changed == 'true'
environment:
name: testpypi
url: https://test.pypi.org/p/mrpro
permissions:
id-token: write
steps:
- name: Download TestPyPI Distribution
uses: actions/download-artifact@v4
with:
name: testpypi-package-distribution
path: dist/
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
verbose: true
test-install-from-testpypi:
name: Test Installation from TestPyPI
needs:
- testpypi-deployment
- build-testpypi-package
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install MRpro from TestPyPI
run: |
VERSION=${{ needs.build-testpypi-package.outputs.version }}
SUFFIX=${{ needs.build-testpypi-package.outputs.suffix }}
for i in {1..3}; do
if python -m pip install mrpro==$VERSION$SUFFIX --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/; then
echo "Package installed successfully."
break
else
echo "Attempt $i failed. Retrying in 10 seconds..."
sleep 10
fi
done
build-pypi-package:
name: Build Package for PyPI
runs-on: ubuntu-latest
needs:
- test-install-from-testpypi
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install Automatic Versioning Tool
run: |
python -m pip install setuptools-git-versioning
- name: Get Current Version
id: get_version
run: |
VERSION=$(python -m setuptools_git_versioning)
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
- name: Build Package
run: |
python -m pip install --upgrade build
python -m build
- name: Store PyPI Distribution
uses: actions/upload-artifact@v4
with:
name: pypi-package-distribution
path: dist/
pypi-deployment:
name: Deploy to PyPI
needs:
- build-pypi-package
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/mrpro
permissions:
contents: write
id-token: write
steps:
- name: Download PyPI Distribution
uses: actions/download-artifact@v4
with:
name: pypi-package-distribution
path: dist/
- name: Create Tag
uses: actions/github-script@v7
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/v${{ needs.build-pypi-package.outputs.version }}',
sha: context.sha
})
- name: Create Release
uses: actions/github-script@v7
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
script: |
github.rest.repos.createRelease({
draft: false,
generate_release_notes: true,
name: "v${{ needs.build-pypi-package.outputs.version }}",
owner: context.repo.owner,
prerelease: false,
repo: context.repo.repo,
tag_name: "v${{ needs.build-pypi-package.outputs.version }}",
});
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://upload.pypi.org/legacy/
verbose: true
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
# Cancel in-progress runs when a new workflow with the same group name is triggered
cancel-in-progress: true