-
-
Notifications
You must be signed in to change notification settings - Fork 1
104 lines (101 loc) · 3.24 KB
/
Copy pathpublish.yml
File metadata and controls
104 lines (101 loc) · 3.24 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
name: Publish package
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'
defaults:
run:
shell: bash
permissions:
contents: read
jobs:
test:
uses: ./.github/workflows/test.yml
secrets: inherit
publish:
needs: test
name: "Publish"
runs-on: ubuntu-latest
env:
NAME: qs_codec
environment:
name: pypi
url: https://pypi.org/p/${{ env.NAME }}
permissions:
id-token: write
contents: write
steps:
- uses: actions/checkout@v7
- name: Compare package version with ref/tag
id: compare
run: |
set -euo pipefail
VERSION=$(awk -F'"' '/__version__/ {print $2}' src/${{ env.NAME }}/__init__.py)
TAG=${GITHUB_REF_NAME#v}
if [[ "$VERSION" != "$TAG" ]]; then
echo "Version in src/$NAME/__init__.py ($VERSION) does not match tag ($TAG)"
exit 1
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Check CHANGELOG.md
id: check_changelog
run: |
set -euo pipefail
if ! grep -Eq "^##[[:space:]]+${VERSION}([[:space:]]|$)" CHANGELOG.md; then
echo "CHANGELOG.md does not contain a section for $VERSION"
exit 1
fi
- name: Set up Python
id: setup_python
uses: actions/setup-python@v6
with:
python-version: "3.x"
cache: "pip"
cache-dependency-path: pyproject.toml
- name: Install build dependencies
id: install_build_dependencies
run: pip install build setuptools wheel twine
- name: Build a binary wheel and a source tarball
id: build
run: python -m build --sdist --wheel --outdir dist/ .
- name: Check built artifacts metadata (twine)
id: twine_check
run: python -m twine check dist/*
- name: Publish distribution package to PyPI
id: publish
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
- name: Create tag-specific CHANGELOG
id: create_changelog
run: |
set -euo pipefail
CHANGELOG_PATH=$RUNNER_TEMP/CHANGELOG.md
# Extract the section that matches exactly this tag version (from its header down to, but not including, the next header)
awk -v ver="$VERSION" '
$0 ~ "^##[[:space:]]+" ver "([[:space:]]|$)" {print; insec=1; next}
insec && /^##[[:space:]]/ {exit}
insec {print}
' CHANGELOG.md | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' > "$CHANGELOG_PATH"
printf "\n**PyPI:** https://pypi.org/project/%s/%s/\n" "$NAME" "$VERSION" >> "$CHANGELOG_PATH"
echo "CHANGELOG_PATH=$CHANGELOG_PATH" >> "$GITHUB_ENV"
- name: Github Release
id: github_release
uses: softprops/action-gh-release@v3
with:
name: ${{ env.VERSION }}
tag_name: ${{ github.ref }}
body_path: ${{ env.CHANGELOG_PATH }}
files: |
dist/*.whl
dist/*.tar.gz
- name: Cleanup
if: ${{ always() }}
run: |
rm -rf dist
rm -rf $CHANGELOG_PATH
docs:
uses: ./.github/workflows/docs.yml
needs: [test, publish]
permissions:
contents: write
secrets: inherit