-
Notifications
You must be signed in to change notification settings - Fork 97
159 lines (135 loc) · 5.16 KB
/
Copy pathrelease.yml
File metadata and controls
159 lines (135 loc) · 5.16 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: Release
on:
push:
branches:
- main
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: read
env:
EMULATOR_PACKAGES: adapter-next apple aws clerk core github google microsoft mongoatlas okta resend slack stripe vercel
jobs:
check-release:
name: Check for new version
runs-on: ubuntu-latest
outputs:
should_release: ${{ steps.check.outputs.should_release }}
version: ${{ steps.check.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Compare versions to registry
id: check
run: |
LOCAL_VERSION=$(node -p "require('./packages/emulate/package.json').version")
SHOULD_RELEASE=false
REGISTRY_VERSION=$(npm view emulate version 2>/dev/null || echo "0.0.0")
echo "emulate — local: $LOCAL_VERSION, registry: $REGISTRY_VERSION"
if [ "$LOCAL_VERSION" != "$REGISTRY_VERSION" ]; then
SHOULD_RELEASE=true
fi
for pkg in $EMULATOR_PACKAGES; do
REGISTRY_VERSION=$(npm view "@emulators/$pkg" version 2>/dev/null || echo "0.0.0")
echo "@emulators/$pkg — local: $LOCAL_VERSION, registry: $REGISTRY_VERSION"
if [ "$LOCAL_VERSION" != "$REGISTRY_VERSION" ]; then
SHOULD_RELEASE=true
fi
done
echo "should_release=$SHOULD_RELEASE" >> "$GITHUB_OUTPUT"
echo "version=$LOCAL_VERSION" >> "$GITHUB_OUTPUT"
publish:
name: Publish
needs: check-release
if: needs.check-release.outputs.should_release == 'true'
runs-on: ubuntu-latest
environment: Release
permissions:
contents: read
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.11.0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
cache: pnpm
registry-url: "https://registry.npmjs.org"
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build
run: pnpm build
- name: Publish packages
run: |
LOCAL_VERSION="${{ needs.check-release.outputs.version }}"
FAILED=""
# Use `pnpm publish` instead of `npm publish` so the `workspace:*`
# protocol gets rewritten to the resolved version in the published
# tarball. `npm publish` would leave it as a literal `workspace:*`,
# which consumers cannot resolve.
REGISTRY_VERSION=$(npm view emulate version 2>/dev/null || echo "0.0.0")
if [ "$LOCAL_VERSION" = "$REGISTRY_VERSION" ]; then
echo "emulate@$LOCAL_VERSION already published, skipping"
else
echo "Publishing emulate@$LOCAL_VERSION..."
if ! (cd packages/emulate && pnpm publish --provenance --no-git-checks --access public); then
FAILED="$FAILED emulate"
fi
fi
for pkg in $EMULATOR_PACKAGES; do
REGISTRY_VERSION=$(npm view "@emulators/$pkg" version 2>/dev/null || echo "0.0.0")
if [ "$LOCAL_VERSION" = "$REGISTRY_VERSION" ]; then
echo "@emulators/$pkg@$LOCAL_VERSION already published, skipping"
continue
fi
echo "Publishing @emulators/$pkg@$LOCAL_VERSION..."
if ! (cd "packages/@emulators/$pkg" && pnpm publish --provenance --no-git-checks --access public); then
FAILED="$FAILED @emulators/$pkg"
fi
done
if [ -n "$FAILED" ]; then
echo "Failed to publish:$FAILED"
exit 1
fi
github-release:
name: Create GitHub Release
needs: [check-release, publish]
if: needs.check-release.outputs.should_release == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Extract changelog entry
run: |
VERSION="${{ needs.check-release.outputs.version }}"
awk '/<!-- release:start -->/{found=1; next} /<!-- release:end -->/{found=0} found{print}' CHANGELOG.md > /tmp/release-notes.md
LINES=$(wc -l < /tmp/release-notes.md | tr -d ' ')
if [ "$LINES" -lt 2 ]; then
echo "Error: No release notes found between <!-- release:start --> and <!-- release:end --> markers in CHANGELOG.md"
exit 1
fi
echo "Extracted release notes for $VERSION ($LINES lines)"
- name: Create GitHub Release
run: |
VERSION="${{ needs.check-release.outputs.version }}"
TAG="v$VERSION"
if gh release view "$TAG" &>/dev/null; then
echo "Release $TAG already exists, skipping"
else
echo "Creating release $TAG..."
gh release create "$TAG" \
--title "$TAG" \
--target ${{ github.sha }} \
--notes-file /tmp/release-notes.md
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}