-
Notifications
You must be signed in to change notification settings - Fork 10
227 lines (193 loc) · 7.77 KB
/
release.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
name: release
on:
push:
branches: [stable]
workflow_dispatch:
inputs:
devN:
description: 'development release number'
required: false
default: '0'
env:
PKG_NAME: peerdid
jobs:
checks:
name: check releases
if: github.ref == 'refs/heads/stable'
runs-on: ubuntu-latest
outputs:
current_version: ${{ steps.current_version.outputs.current_version }}
release_info: ${{ steps.release_info.outputs.release_info }}
asset_tgz_url: ${{ steps.release_info.outputs.asset_tgz_url }}
asset_whl_url: ${{ steps.release_info.outputs.asset_whl_url }}
upload_url: ${{ steps.release_info.outputs.upload_url }}
already_in_pypi: ${{ steps.check_in_pypi.outputs.pypi_versions != '' }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Get current version
id: current_version
run: |
python -m pip install . --no-deps
out="$(pip show ${{ env.PKG_NAME }} | grep 'Version:' | awk '{print $2}')"
echo "$out"
echo "current_version=$out" >> $GITHUB_OUTPUT
shell: bash
- name: Get release info
id: release_info
run: |
release_info="$(curl -s https://api.github.com/repos/${{ github.repository }}/releases \
| jq -c '.[] | select(.name == "v${{ steps.current_version.outputs.current_version }}")')"
echo "release_info=$release_info" >> $GITHUB_OUTPUT
echo "$release_info"
asset_tgz_url="$(echo "$release_info" \
| jq -r '.assets[] | select(.name | match("^${{ env.PKG_NAME }}.*\\.tar.gz$")) | .browser_download_url')"
echo "asset_tgz_url=$asset_tgz_url" >> $GITHUB_OUTPUT
echo "$asset_tgz_url"
asset_whl_url="$(echo "$release_info" \
| jq -r '.assets[] | select(.name | match("^${{ env.PKG_NAME }}.*\\.whl$")) | .browser_download_url')"
echo "asset_whl_url=$asset_whl_url" >> $GITHUB_OUTPUT
echo "$asset_whl_url"
upload_url="$(echo "$release_info" | jq -r '.upload_url')"
echo "upload_url=$upload_url" >> $GITHUB_OUTPUT
echo "$upload_url"
shell: bash
- name: check if already deployed to PyPI
id: check_in_pypi
# Note. other options:
# - use 'pip install --no-deps PKG==VERSION' with current version
# - use 'pip index versions PKG==VERSION'
# (but it's a kind of experimental feature of pip >= 21.2)
run: |
python -m pip install --upgrade pip
out="$(pip install --use-deprecated=legacy-resolver ${{ env.PKG_NAME }}== 2>&1 \
| grep -E "Could not find .* ${{ steps.current_version.outputs.current_version }}(,|\))")"
echo "pypi_versions=$out" >> $GITHUB_OUTPUT
shell: bash {0} # to opt-out of default fail-fast behavior
release-github:
name: GitHub Release
if: github.ref == 'refs/heads/stable'
runs-on: ubuntu-latest
needs: checks
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: build dist
id: build_assets
if: ${{ !(needs.checks.outputs.asset_tgz_url && needs.checks.outputs.asset_whl_url) }}
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade build
python -m build
ls dist
asset_tgz_name="$(find dist -name '*.tar.gz' -printf '%f')"
echo "asset_tgz_name=$asset_tgz_name" >> $GITHUB_OUTPUT
asset_whl_name="$(find dist -name '*.whl' -printf '%f')"
echo "asset_whl_name=$asset_whl_name" >> $GITHUB_OUTPUT
shell: bash
- name: Create Release
id: create_release
if: ${{ ! needs.checks.outputs.release_info }}
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ needs.checks.outputs.current_version }}
release_name: v${{ needs.checks.outputs.current_version }}
- name: Set upload url
id: upload_url
if: ${{ !(needs.checks.outputs.asset_tgz_url && needs.checks.outputs.asset_whl_url) }}
run: |
if [[ -n "${{ needs.checks.outputs.upload_url }}" ]]; then
echo "value=${{ needs.checks.outputs.upload_url }}" >> $GITHUB_OUTPUT
else
echo "value=${{ steps.create_release.outputs.upload_url }}" >> $GITHUB_OUTPUT
fi
- name: Upload the source archive
if: ${{ !needs.checks.outputs.asset_tgz_url }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.upload_url.outputs.value }}
asset_path: dist/${{ steps.build_assets.outputs.asset_tgz_name }}
asset_name: ${{ steps.build_assets.outputs.asset_tgz_name }}
asset_content_type: application/x-gtar
- name: Upload the wheel
if: ${{ !needs.checks.outputs.asset_whl_url }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.upload_url.outputs.value }}
asset_path: dist/${{ steps.build_assets.outputs.asset_whl_name }}
asset_name: ${{ steps.build_assets.outputs.asset_whl_name }}
asset_content_type: application/zip
deploy-pypi:
name: Deploy to PyPI
if: github.ref == 'refs/heads/stable' && needs.checks.outputs.already_in_pypi == 'false'
runs-on: ubuntu-latest
needs: [checks, release-github]
steps:
- uses: actions/checkout@v3
- name: download GitHub artifacts
run: |
mkdir -p dist
cd dist
curl -s https://api.github.com/repos/${{ github.repository }}/releases/tags/v${{ needs.checks.outputs.current_version }} \
| jq -r ".assets[] | select(.name | contains(\"${{ env.PKG_NAME }}\")) | .browser_download_url" \
| wget -i -
ls
shell: bash
# NOTE uncomment once community actions are allowed for the github org
# - name: Publish to PyPI
# uses: pypa/[email protected]
# with:
# user: __token__
# password: ${{ secrets.PYPI_API_TOKEN }}
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Prepare python env
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade twine
shell: bash
- name: Publish to PyPI
env:
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: python -m twine upload --non-interactive --username __token__ dist/*
shell: bash
deploy-test-pypi:
name: Deploy to TestPyPI
if: github.ref != 'refs/heads/stable' && github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: set dev version
run: |
sed -i -r "s~__version__ = \"(.+)\"~__version__ = \"\1.dev${{ github.event.inputs.devN }}\"~" ./peerdid/__init__.py
grep version ./setup.py
shell: bash
- name: build dist
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade build
python -m build
ls dist
shell: bash
- name: install twine
run: python -m pip install --upgrade twine
shell: bash
- name: Publish to TestPyPI
env:
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
run: python -m twine upload --non-interactive --username __token__ --repository testpypi dist/*
shell: bash