Repository navigation
115 lines (109 loc) · 4.2 KB
/
Copy pathrelease.yml
File metadata and controls
115 lines (109 loc) · 4.2 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
name: release
# Push a tag that matches the version in pyproject.toml:
# git tag v0.1.3 && git push origin v0.1.3
# It is tested, built once, published to PyPI through Trusted Publishing (no
# token is stored anywhere: PyPI trusts this workflow in the `pypi`
# environment), and then released on GitHub with the same wheel and sdist,
# plus a Sigstore-signed build-provenance attestation for both.
on:
push:
tags: ["v*"]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # sign the provenance with a short-lived Sigstore certificate
attestations: write # record it with GitHub, for `gh attestation verify`
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with:
python-version: "3.12"
- name: Tag matches the package version
run: |
version=$(uv run --no-project python -c "import tomllib;print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
if [ "v$version" != "$GITHUB_REF_NAME" ]; then
echo "::error::tag $GITHUB_REF_NAME does not match pyproject version $version"
exit 1
fi
- run: uv sync --locked
- run: uv run pytest
- run: uv build
- run: uvx twine check --strict dist/*
- id: attest
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
with:
# Exactly what is published: `dist/*` also matched the .gitignore
# that uv build writes there.
subject-path: |
dist/*.whl
dist/*.tar.gz
# Kept out of dist/: PyPI takes only the wheel and sdist. The release
# carries it, so the files can be checked without asking GitHub.
- name: Keep the signed provenance for the release
env:
BUNDLE: ${{ steps.attest.outputs.bundle-path }}
run: |
mkdir signed
cp "$BUNDLE" "signed/kdev_cli-${GITHUB_REF_NAME#v}.sigstore.json"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: dist
path: dist/
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: signed
path: signed/
pypi:
needs: build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/kdev-cli/
permissions:
id-token: write # Trusted Publishing, and signed attestations for each file
steps:
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: dist
path: dist/
- uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
release:
# After PyPI, so a GitHub release always means `pip install kdev-cli` works.
needs: [build, pypi]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: dist
path: dist/
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: signed
path: signed/
- name: Release notes from CHANGELOG.md
run: |
version="${GITHUB_REF_NAME#v}"
awk -v v="$version" '
$0 ~ "^## \\[?" v "\\]?" {on=1; next}
on && /^## / {exit}
on {print}
' CHANGELOG.md > notes.md
test -s notes.md || echo "Release $GITHUB_REF_NAME" > notes.md
- uses: softprops/action-gh-release@8a0cd651e5b2365bd640854a3fa5dfc70e4875f3 # v3.0.3 # zizmor: ignore[superfluous-actions] `gh release create` would do, but a release job cannot be tried before a release
with:
body_path: notes.md
files: |
dist/*
signed/*
fail_on_unmatched_files: true