Repository navigation
138 lines (118 loc) · 3.83 KB
/
Copy pathrelease.yml
File metadata and controls
138 lines (118 loc) · 3.83 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
129
130
131
132
133
134
135
136
137
138
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
version:
description: "Version to publish, e.g. 0.1.1"
required: true
type: string
permissions:
contents: read
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Resolve release
id: release
shell: bash
env:
INPUT_VERSION: ${{ inputs.version }}
run: |
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
VERSION="${INPUT_VERSION#v}"
TAG="v${VERSION}"
else
TAG="${GITHUB_REF_NAME}"
VERSION="${TAG#v}"
fi
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
echo "tag=${TAG}" >> "${GITHUB_OUTPUT}"
- name: Install build tooling
run: python -m pip install build twine
- name: Verify release version
env:
RELEASE_VERSION: ${{ steps.release.outputs.version }}
run: |
python - <<'PY'
from pathlib import Path
import os
import re
text = Path("src/geodebug/version.py").read_text()
match = re.search(r'__version__ = "([^"]+)"', text)
if match is None:
raise SystemExit("package version not found")
package_version = match.group(1)
release_version = os.environ["RELEASE_VERSION"]
if package_version != release_version:
raise SystemExit(
f"release version {release_version} != package version {package_version}"
)
PY
- name: Build distributions
run: python -m build
- name: Validate distributions
run: python -m twine check dist/*
- name: Upload distributions for PyPI
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
if-no-files-found: error
- name: Extract release notes
env:
RELEASE_VERSION: ${{ steps.release.outputs.version }}
run: |
python - <<'PY'
from pathlib import Path
import os
import re
version = os.environ["RELEASE_VERSION"]
text = Path("CHANGELOG.md").read_text()
match = re.search(
rf"^## {re.escape(version)}[^\n]*\n(?P<body>.*?)(?=^## |\Z)",
text,
re.MULTILINE | re.DOTALL,
)
if match is None:
raise SystemExit(f"CHANGELOG entry not found for {version}")
Path("/tmp/release-notes.md").write_text(
f"## GeoDebug {version}\n\n" + match.group("body").strip() + "\n"
)
PY
- name: Create GitHub release
shell: bash
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ steps.release.outputs.tag }}
run: |
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
gh release create "${RELEASE_TAG}" dist/* --target "${GITHUB_SHA}" --notes-file /tmp/release-notes.md
else
gh release create "${RELEASE_TAG}" dist/* --notes-file /tmp/release-notes.md --verify-tag
fi
publish-pypi:
name: Publish to PyPI
needs: release
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/geodebug
permissions:
id-token: write
steps:
- name: Download distributions
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distributions with trusted publishing
uses: pypa/gh-action-pypi-publish@release/v1