-
Notifications
You must be signed in to change notification settings - Fork 4
107 lines (91 loc) · 3.39 KB
/
Copy pathrelease.yml
File metadata and controls
107 lines (91 loc) · 3.39 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
name: Release
on:
push:
tags:
- "v*.*.*"
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout tag
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate release tag
id: tag
shell: bash
run: |
tag="${GITHUB_REF_NAME}"
if [[ ! "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+([-.+][0-9A-Za-z.-]+)?$ ]]; then
echo "::error title=Invalid release tag::Expected a tag like v1.2.3, got ${tag}."
exit 1
fi
target_sha="$(git rev-list -n 1 "$tag")"
git fetch --no-tags origin +refs/heads/*:refs/remotes/origin/*
on_release_branch=false
if git show-ref --verify --quiet refs/remotes/origin/master &&
git merge-base --is-ancestor "$target_sha" origin/master; then
on_release_branch=true
fi
if git show-ref --verify --quiet refs/remotes/origin/main &&
git merge-base --is-ancestor "$target_sha" origin/main; then
on_release_branch=true
fi
if [[ "$on_release_branch" != "true" ]]; then
echo "::error title=Tag is not on the release branch::${tag} must point to a commit contained in master or main."
exit 1
fi
{
echo "tag=${tag}"
echo "version=${tag#v}"
echo "target_sha=${target_sha}"
} >> "$GITHUB_OUTPUT"
- name: Extract release notes from CHANGELOG
env:
RELEASE_VERSION: ${{ steps.tag.outputs.version }}
shell: python
run: |
import json
import os
import pathlib
import re
version = os.environ["RELEASE_VERSION"]
changelog = pathlib.Path("CHANGELOG.md")
text = changelog.read_text(encoding="utf-8")
match = re.search(
rf"^## \[{re.escape(version)}\](?: - [^\n]+)?\s*\n(?P<body>.*?)(?=^## \[|\Z)",
text,
re.MULTILINE | re.DOTALL,
)
if not match:
raise SystemExit(f"Could not find CHANGELOG.md section for {version}.")
body = match.group("body").strip()
if not body:
raise SystemExit(f"CHANGELOG.md section for {version} is empty.")
package_json = pathlib.Path("Packages/com.kurisu.ceres/package.json")
package_version = json.loads(package_json.read_text(encoding="utf-8")).get("version")
if package_version != version:
raise SystemExit(
f"package.json is {package_version}, but release tag is v{version}."
)
pathlib.Path("release_notes.md").write_text(body + "\n", encoding="utf-8")
- name: Ensure release does not already exist
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
if gh release view "${{ steps.tag.outputs.tag }}" >/dev/null 2>&1; then
echo "::error title=Release already exists::Release ${{ steps.tag.outputs.tag }} already exists."
exit 1
fi
- name: Create GitHub release
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
gh release create "${{ steps.tag.outputs.tag }}" \
--title "${{ steps.tag.outputs.tag }}" \
--notes "$(cat release_notes.md)" \
--generate-notes