-
Notifications
You must be signed in to change notification settings - Fork 0
122 lines (105 loc) · 3.85 KB
/
Copy pathgithub-release.yml
File metadata and controls
122 lines (105 loc) · 3.85 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
name: GitHub Release
# Triggered when the maintainer pushes tags created locally by
# `pnpm changeset publish` (e.g. @bridgent/cli@0.2.0).
# Each tag = one GitHub Release, with notes lifted out of the package's
# CHANGELOG.md. No NPM_TOKEN required — only the auto-provided
# GITHUB_TOKEN is used.
on:
push:
tags:
- '@bridgent/*@*'
permissions:
contents: write
# Tags are pushed in batches (`git push --follow-tags`); each one fans
# out into its own job. Don't cancel siblings — every tag deserves
# its own Release.
concurrency:
group: github-release-${{ github.ref }}
cancel-in-progress: false
jobs:
release:
name: Create GitHub Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
fetch-depth: 0
persist-credentials: false
- name: Parse tag
id: parse
run: |
set -euo pipefail
TAG="${GITHUB_REF_NAME}"
# @bridgent/cli@0.2.0 → PKG=@bridgent/cli, VERSION=0.2.0
VERSION="${TAG##*@}"
PKG="${TAG%@*}"
# @bridgent/cli → cli
PKG_DIR="${PKG#@bridgent/}"
echo "Tag: $TAG"
echo "Package: $PKG"
echo "Version: $VERSION"
echo "Dir: packages/$PKG_DIR"
{
echo "tag=$TAG"
echo "pkg=$PKG"
echo "version=$VERSION"
echo "pkg_dir=$PKG_DIR"
} >> "$GITHUB_OUTPUT"
- name: Extract changelog section
id: changelog
run: |
set -euo pipefail
PKG_DIR="${{ steps.parse.outputs.pkg_dir }}"
VERSION="${{ steps.parse.outputs.version }}"
PKG="${{ steps.parse.outputs.pkg }}"
CHANGELOG="packages/$PKG_DIR/CHANGELOG.md"
if [ ! -f "$CHANGELOG" ]; then
echo "::warning::No changelog at $CHANGELOG — using a stub."
BODY="Released \`$PKG@$VERSION\` to npm.
See [npm](https://www.npmjs.com/package/$PKG) for tarball and metadata."
else
# Pull the lines between '## VERSION' and the next '## ' header.
BODY=$(awk -v target="## $VERSION" '
/^## / {
if (capture) { exit }
if ($0 == target || index($0, target " ") == 1) { capture = 1; next }
}
capture { print }
' "$CHANGELOG")
if [ -z "${BODY// }" ]; then
BODY="No changelog entry found for $VERSION in $CHANGELOG.
Published as \`$PKG@$VERSION\` — see [npm](https://www.npmjs.com/package/$PKG)."
else
BODY="$BODY
---
Published as \`$PKG@$VERSION\` on [npm](https://www.npmjs.com/package/$PKG)."
fi
fi
{
echo "body<<RELEASE_BODY_EOF"
echo "$BODY"
echo "RELEASE_BODY_EOF"
} >> "$GITHUB_OUTPUT"
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
TAG="${{ steps.parse.outputs.tag }}"
TITLE="${{ steps.parse.outputs.pkg }}@${{ steps.parse.outputs.version }}"
# Skip if a Release for this tag already exists (re-runs are no-ops).
if gh release view "$TAG" >/dev/null 2>&1; then
echo "Release for $TAG already exists — leaving it alone."
exit 0
fi
# Mark prereleases (anything with a hyphen in the version such as
# 0.3.0-rc.1) so they don't show up as the headline release.
PREFLAG=""
if [[ "${{ steps.parse.outputs.version }}" == *-* ]]; then
PREFLAG="--prerelease"
fi
gh release create "$TAG" \
--title "$TITLE" \
--notes "${{ steps.changelog.outputs.body }}" \
--verify-tag \
$PREFLAG