Repository navigation
114 lines (106 loc) · 4.18 KB
/
Copy pathrelease.yml
File metadata and controls
114 lines (106 loc) · 4.18 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
name: Release
on:
push:
branches: [master]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 22
- uses: oven-sh/setup-bun@v2
with:
bun-version: "1.4.2"
- run: bun install --frozen-lockfile
- run: bun run build
- run: bun run test
- name: Create Release Pull Request or Publish
id: changesets
uses: changesets/action@v1
with:
publish: bun run release
version: bun run version-packages
title: "chore: version packages"
commit: "chore: version packages"
# Disable the action's built-in GitHub release creation — it races
# when 2+ packages publish in the same run and the GitHub Releases
# API rejects the batch with `tag_name: already_exists` for all but
# one of the packages. Drive release creation ourselves below,
# serially, so the same race can't happen. (See #77.)
createGithubReleases: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create GitHub releases for each published package
if: steps.changesets.outputs.published == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PUBLISHED: ${{ steps.changesets.outputs.publishedPackages }}
run: |
set -euo pipefail
# `publishedPackages` is a JSON array like:
# [{ "name": "@workkit/agent", "version": "0.2.0" }, ...]
# `changeset publish` already pushed the per-package tags
# (e.g. `@workkit/agent@0.2.0`) before this step runs.
echo "$PUBLISHED" | jq -c '.[]' | while read -r pkg; do
name=$(echo "$pkg" | jq -r '.name')
version=$(echo "$pkg" | jq -r '.version')
tag="${name}@${version}"
# Idempotency: skip if a release for this tag already exists. This
# also makes the backfill story trivial — re-running the workflow
# (or invoking this step manually) only fills in what's missing.
if gh release view "$tag" >/dev/null 2>&1; then
echo "✓ release already exists: $tag"
continue
fi
# Resolve the package directory from its name so we can read the
# CHANGELOG. Walk both `packages/*` and `integrations/*` (the only
# workspace globs that ship to npm).
pkgdir=""
for dir in packages/* integrations/*; do
if [ -f "$dir/package.json" ] && [ "$(jq -r .name "$dir/package.json")" = "$name" ]; then
pkgdir="$dir"
break
fi
done
# Extract just the section for THIS version from the changelog.
# Format produced by `@changesets/cli/changelog`:
# # <package name>
# ## <version>
# ### <change-kind>
# - <commit>: <summary>
# ## <previous version>
# ...
notes_file=$(mktemp)
if [ -n "$pkgdir" ] && [ -f "$pkgdir/CHANGELOG.md" ]; then
awk -v ver="$version" '
/^## / {
if (in_section) exit
# Match "## <ver>" exactly (token-aware, not substring).
if ($2 == ver) { in_section = 1; next }
}
in_section
' "$pkgdir/CHANGELOG.md" > "$notes_file"
fi
# Empty changelog falls back to a one-line auto-note rather than
# creating a blank release body.
if [ ! -s "$notes_file" ]; then
echo "Release ${tag} (no changelog entry found)" > "$notes_file"
fi
echo "→ creating release: $tag"
gh release create "$tag" \
--title "$tag" \
--notes-file "$notes_file"
done