Skip to content

Commit 4a7ba1a

Browse files
committed
Add GitHub release action to upload to PyPI & create GitHub release
1 parent 24a3b22 commit 4a7ba1a

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

.github/workflows/release.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
jobs:
9+
build:
10+
if: github.repository == 'typeddjango/django-stubs'
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- uses: actions/setup-python@v3
17+
with:
18+
python-version: '3.x'
19+
20+
- name: Install dependencies
21+
run: |
22+
python -m pip install -U pip
23+
python -m pip install -U setuptools twine wheel
24+
25+
- name: Build package
26+
run: |
27+
python setup.py --version
28+
python setup.py sdist bdist_wheel
29+
twine check dist/*
30+
31+
- name: Publish package to PyPI
32+
uses: pypa/gh-action-pypi-publish@release/v1
33+
with:
34+
user: __token__
35+
password: ${{ secrets.PYPI_API_TOKEN }}
36+
37+
print_hash: true
38+
verify_metadata: false # check done above
39+
40+
- name: create release
41+
uses: actions/github-script@v6
42+
with:
43+
script: |
44+
const tagName = context.ref.replace(/^refs\/tags\//, '');
45+
const release = await github.rest.repos.createRelease({
46+
owner: context.repo.owner,
47+
repo: context.repo.repo,
48+
tag_name: tagName,
49+
name: `Release ${tagName.replace(/^v/, '')}`,
50+
});
51+
52+
if (release.status < 200 || release.status >= 300) {
53+
core.setFailed(`Could not create release for tag '${tagName}'`);
54+
return;
55+
}

0 commit comments

Comments
 (0)