-
Notifications
You must be signed in to change notification settings - Fork 1
128 lines (107 loc) · 3.25 KB
/
release.yml
File metadata and controls
128 lines (107 loc) · 3.25 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 git tag to release (for example v2026.04.14)"
required: true
type: string
concurrency:
group: release-${{ github.event.inputs.tag || github.ref_name }}
cancel-in-progress: false
permissions:
contents: write
jobs:
validate:
name: Validate release tag
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.meta.outputs.tag }}
version: ${{ steps.meta.outputs.version }}
steps:
- name: Check out repository
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Resolve release metadata
id: meta
shell: bash
run: |
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
TAG="${{ github.event.inputs.tag }}"
if ! git rev-parse -q --verify "refs/tags/${TAG}" >/dev/null; then
echo "Tag ${TAG} does not exist on origin"
exit 1
fi
else
TAG="${GITHUB_REF_NAME}"
fi
if [[ ! "${TAG}" =~ ^v[0-9]{4}\.[0-9]{2}\.[0-9]{2}(\.[0-9]+)?$ ]]; then
echo "Tag ${TAG} does not match vYYYY.MM.DD or vYYYY.MM.DD.N"
exit 1
fi
VERSION="$(python - <<'PY'
from pathlib import Path
import re
text = Path("src/octopal/_version.py").read_text(encoding="utf-8")
match = re.search(r'__version__\s*=\s*"([^"]+)"', text)
if not match:
raise SystemExit("Could not find __version__ in src/octopal/_version.py")
print(match.group(1))
PY
)"
EXPECTED_VERSION="${TAG#v}"
if [[ "${VERSION}" != "${EXPECTED_VERSION}" ]]; then
echo "Version mismatch: tag=${EXPECTED_VERSION}, file=${VERSION}"
exit 1
fi
echo "tag=${TAG}" >> "${GITHUB_OUTPUT}"
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
test:
name: Run release checks
runs-on: ubuntu-latest
needs: validate
steps:
- name: Check out repository
uses: actions/checkout@v5
with:
ref: ${{ needs.validate.outputs.tag }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Set up uv
uses: astral-sh/setup-uv@v7
- name: Sync dependencies
run: uv sync --extra dev
- name: Run test suite
run: uv run pytest
publish:
name: Publish GitHub release
runs-on: ubuntu-latest
needs:
- validate
- test
steps:
- name: Check out repository
uses: actions/checkout@v5
with:
ref: ${{ needs.validate.outputs.tag }}
- name: Create GitHub release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ needs.validate.outputs.tag }}
VERSION: ${{ needs.validate.outputs.version }}
shell: bash
run: |
if gh release view "${TAG}" >/dev/null 2>&1; then
echo "Release ${TAG} already exists; skipping."
exit 0
fi
gh release create "${TAG}" \
--verify-tag \
--title "Octopal ${VERSION}" \
--generate-notes