-
Notifications
You must be signed in to change notification settings - Fork 2
110 lines (98 loc) · 3.53 KB
/
Copy pathrelease.yml
File metadata and controls
110 lines (98 loc) · 3.53 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
# SPDX-FileCopyrightText: 2026 William Jin <AuraMindNest@outlook.com>
#
# SPDX-License-Identifier: BSL-1.0
name: Release
# Standalone tagging and GitHub Releases.
on:
workflow_dispatch:
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
# actions/checkout v6.0.2
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
with:
ref: main
fetch-depth: 0
- name: Parse versions from pyproject.toml
id: versions
run: |
set -euo pipefail
python3 <<'PY' >> "$GITHUB_OUTPUT"
import re
import tomllib
from pathlib import Path
data = tomllib.loads(Path("pyproject.toml").read_text())
plugin_version = data["project"]["version"]
weblate_version = None
for dep in data["project"]["dependencies"]:
match = re.fullmatch(r"Weblate\[all\]==(.+)", dep)
if match:
weblate_version = match.group(1)
break
if not weblate_version:
raise SystemExit("Weblate[all]== pin not found in pyproject.toml")
print(f"plugin_version={plugin_version}")
print(f"weblate_version={weblate_version}")
print(f"tag=v{plugin_version}")
PY
- name: Fail if tag already exists
run: |
set -euo pipefail
tag="${{ steps.versions.outputs.tag }}"
if git ls-remote --tags origin "refs/tags/${tag}" | grep -q .; then
echo "Tag ${tag} already exists on origin"
exit 1
fi
- name: Extract changelog section for release
id: changelog
env:
PLUGIN_VERSION: ${{ steps.versions.outputs.plugin_version }}
WEBLATE_VERSION: ${{ steps.versions.outputs.weblate_version }}
run: |
set -euo pipefail
notes_file="${RUNNER_TEMP}/release-notes.md"
python3 <<'PY'
import os
import re
from pathlib import Path
version = os.environ["PLUGIN_VERSION"]
weblate_version = os.environ["WEBLATE_VERSION"]
changelog = Path("CHANGELOG.md").read_text()
pattern = rf"^## \[{re.escape(version)}\].*?(?=^## |\Z)"
match = re.search(pattern, changelog, re.MULTILINE | re.DOTALL)
if not match:
raise SystemExit(
f"No ## [{version}] section found in CHANGELOG.md"
)
section = match.group(0).rstrip()
notes_file = Path(os.environ["RUNNER_TEMP"]) / "release-notes.md"
notes_file.write_text(
f"{section}\n\n---\n\nBuilt against Weblate {weblate_version}.\n"
)
PY
echo "notes_file=${notes_file}" >> "$GITHUB_OUTPUT"
- name: Configure git for tag push
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Create and push tag
run: |
set -euo pipefail
tag="${{ steps.versions.outputs.tag }}"
weblate_version="${{ steps.versions.outputs.weblate_version }}"
git tag -a "${tag}" -m "Release ${tag} (Weblate ${weblate_version})"
git push origin "${tag}"
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
tag="${{ steps.versions.outputs.tag }}"
weblate_version="${{ steps.versions.outputs.weblate_version }}"
gh release create "${tag}" \
--title "${tag} (Weblate ${weblate_version})" \
--notes-file "${{ steps.changelog.outputs.notes_file }}"