-
Notifications
You must be signed in to change notification settings - Fork 6
128 lines (109 loc) · 3.32 KB
/
Copy pathpython-publish.yml
File metadata and controls
128 lines (109 loc) · 3.32 KB
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
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: "Existing release tag, for example v0.0.9.3"
required: true
type: string
env:
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}
permissions:
contents: read
concurrency:
group: release-${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}
cancel-in-progress: false
jobs:
build:
name: Test and build distributions
runs-on: ubuntu-latest
steps:
- name: Check out release tag
uses: actions/checkout@v6
with:
ref: ${{ env.RELEASE_TAG }}
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.x"
cache: pip
cache-dependency-path: |
requirements.txt
setup.py
- name: Install build tools
run: python -m pip install --upgrade build setuptools twine
- name: Validate tag matches package version
shell: bash
run: |
if [[ ! "$RELEASE_TAG" =~ ^v[0-9]+(\.[0-9]+){2,3}([abrc][0-9]+)?$ ]]; then
echo "::error::Invalid release tag: $RELEASE_TAG"
exit 1
fi
package_version="$(python setup.py --version)"
tag_version="${RELEASE_TAG#v}"
if [[ "$package_version" != "$tag_version" ]]; then
echo "::error::Tag $RELEASE_TAG does not match package version $package_version"
exit 1
fi
- name: Run unit tests
run: python -m unittest discover -s tests -v
- name: Build wheel and source distribution
run: python -m build
- name: Check distribution metadata
run: python -m twine check dist/*
- name: Store distributions
uses: actions/upload-artifact@v5
with:
name: python-package-distributions
path: dist/
if-no-files-found: error
retention-days: 7
publish-pypi:
name: Publish to PyPI
needs: build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/qsnctf/
permissions:
id-token: write
steps:
- name: Download distributions
uses: actions/download-artifact@v6
with:
name: python-package-distributions
path: dist/
- name: Publish distributions with Trusted Publishing
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
github-release:
name: Create GitHub Release
needs: publish-pypi
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download distributions
uses: actions/download-artifact@v6
with:
name: python-package-distributions
path: dist/
- name: Create release and upload distributions
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
shell: bash
run: |
if gh release view "$RELEASE_TAG" >/dev/null 2>&1; then
gh release upload "$RELEASE_TAG" dist/* --clobber
else
gh release create "$RELEASE_TAG" dist/* \
--verify-tag \
--generate-notes \
--latest
fi