Repository navigation
114 lines (107 loc) · 4.19 KB
/
Copy pathrelease.yml
File metadata and controls
114 lines (107 loc) · 4.19 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
name: release
# Cuts a release to PyPI when a `v*` tag is pushed.
#
# Auth uses PyPI's trusted-publishing flow: no API tokens stored on
# our side - PyPI verifies the OIDC token GitHub mints for this
# specific workflow file + environment combination.
on:
push:
tags:
- "v*"
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: read
jobs:
build:
name: Build sdist + wheel
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: astral-sh/setup-uv@v10.3.2
with:
python-version: "3.13"
enable-cache: true
- name: Sanity-check tag matches pyproject version
run: |
tag="${GITHUB_REF_NAME#v}"
pyproject="$(grep -E '^version = ' pyproject.toml | head -1 | sed -E 's/.*"(.*)".*/\1/')"
if [ "$tag" != "$pyproject" ]; then
echo "Tag $GITHUB_REF_NAME (-> $tag) does not match pyproject version $pyproject"
exit 1
fi
- name: Build distributions
run: uv build
- uses: actions/upload-artifact@v7
with:
name: dist
path: dist/
publish:
name: Publish to PyPI (trusted publishing)
needs: build
runs-on: ubuntu-latest
# Match the environment name configured on PyPI under
# "trusted publisher" for this project. Gating behind a GitHub
# Environment also lets you require manual approval per release.
environment:
name: pypi
url: https://pypi.org/project/chapkit/
permissions:
id-token: write # required for the OIDC token PyPI verifies
steps:
- uses: actions/download-artifact@v8
with:
name: dist
path: dist/
- uses: pypa/gh-action-pypi-publish@release/v1
# No `password:` here - the action reads the GitHub OIDC
# token from the runner and exchanges it with PyPI.
github-release:
name: Publish GitHub Release
needs: publish
runs-on: ubuntu-latest
permissions:
contents: write # required to create the release + attach assets
steps:
- uses: actions/checkout@v7
- uses: actions/download-artifact@v8
with:
name: dist
path: dist/
# Release notes come from the annotated tag message: the subject line is
# ignored (the release title is the tag name) and the body becomes the
# notes, followed by GitHub's generated list of merged pull requests.
# Write the tag with a real body, for example:
#
# git tag -a v1.2.0 --cleanup=verbatim -F notes.md
#
# where notes.md starts with a one-line subject, a blank line, and then
# the prose describing what changed, why, and how to upgrade. Keep
# --cleanup=verbatim: without it git treats lines starting with "#" as
# comments and strips Markdown headings such as "## Fixed" from the
# notes. Check with `git cat-file tag v1.2.0` before pushing. A tag with
# no body still releases, with only the generated list, and a warning is
# emitted so the notes get edited afterwards.
- name: Assemble release notes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git fetch --no-tags --force origin "refs/tags/$GITHUB_REF_NAME:refs/tags/$GITHUB_REF_NAME"
tag_body="$(git tag -l --format='%(contents:body)' "$GITHUB_REF_NAME" | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}')"
generated="$(gh api "repos/$GITHUB_REPOSITORY/releases/generate-notes" -f tag_name="$GITHUB_REF_NAME" --jq .body)"
if [ -n "$tag_body" ]; then
printf '%s\n\n%s\n' "$tag_body" "$generated" > release-notes.md
else
echo "::warning::Tag $GITHUB_REF_NAME has no annotation body; release notes contain only the generated pull request list. Edit them with 'gh release edit $GITHUB_REF_NAME --notes-file ...'."
printf '%s\n' "$generated" > release-notes.md
fi
- name: Create release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "$GITHUB_REF_NAME" \
--title "$GITHUB_REF_NAME" \
--notes-file release-notes.md \
--verify-tag \
dist/*.whl dist/*.tar.gz