-
Notifications
You must be signed in to change notification settings - Fork 17
221 lines (186 loc) · 7.41 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
name: release
on:
push:
branches: [stable]
workflow_dispatch:
inputs:
devN:
description: 'development release number'
required: false
default: '0'
env:
PKG_NAME: didcomm
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@v2
- name: Setup Python
id: setup
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: pip install tomli
- name: Get current version
id: current_version
run: python ./.github/scripts/current_version.py
- name: Get release info
id: release_info
run: |
release_info="$(curl -s https://api.github.com/repos/${{ github.repository }}/releases \
| jq '.[] | select(.name == "v${{ steps.current_version.outputs.current_version }}")')"
echo "::set-output name=release_info::$release_info"
echo "$release_info"
asset_tgz_url="$(echo "$release_info" \
| jq -r '.assets[] | select(.name | match("^${{ env.PKG_NAME }}.*\\.tar.gz$")) | .browser_download_url')"
echo "::set-output name=asset_tgz_url::$asset_tgz_url"
echo "$asset_tgz_url"
asset_whl_url="$(echo "$release_info" \
| jq -r '.assets[] | select(.name | match("^${{ env.PKG_NAME }}.*\\.whl$")) | .browser_download_url')"
echo "::set-output name=asset_whl_url::$asset_whl_url"
echo "$asset_whl_url"
upload_url="$(echo "$release_info" | jq -r '.upload_url')"
echo "::set-output name=upload_url::$upload_url"
echo "$upload_url"
- 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 "::set-output name=pypi_versions::$out"
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
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v4
id: setup
with:
python-version: '3.x'
cache: 'poetry'
- name: Install dependencies
if: steps.setup.outputs.cache-hit != 'true'
run: poetry install
- name: build dist
id: build_assets
if: ${{ !(needs.checks.outputs.asset_tgz_url && needs.checks.outputs.asset_whl_url) }}
run: |
poetry build
asset_tgz_name="$(find dist -name '*.tar.gz' -printf '%f')"
echo "::set-output name=asset_tgz_name::$asset_tgz_name"
asset_whl_name="$(find dist -name '*.whl' -printf '%f')"
echo "::set-output name=asset_whl_name::$asset_whl_name"
- 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 "::set-output name=value::${{ needs.checks.outputs.upload_url }}"
else
echo "::set-output name=value::${{ steps.create_release.outputs.upload_url }}"
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: Install poetry
run: pipx install poetry
- 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
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Publish to PyPI
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_API_TOKEN }}
run: poetry publish
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
- name: Get current version
id: current_version
run: |
pip install tomli
python ./.github/scripts/current_version.py
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v4
id: setup
with:
python-version: '3.x'
cache: 'poetry'
- name: Install dependencies
if: steps.setup.outputs.cache-hit != 'true'
run: poetry install
- name: set dev version
run: |
poetry version "${{ steps.current_version.outputs.current_version }}.dev${{ github.event.inputs.devN }}"
- name: build dist
run: poetry build
- name: Publish to Test PyPI
env:
POETRY_PYPI_TOKEN_TEST_PYPI: ${{ secrets.PYPI_API_TOKEN }}
run: |
poetry config repositories.test-pypi https://test.pypi.org/legacy/
poetry publish -r test-pypi