-
Notifications
You must be signed in to change notification settings - Fork 1
221 lines (187 loc) Β· 8.71 KB
/
release.yml
File metadata and controls
221 lines (187 loc) Β· 8.71 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
name: Publish CLIs
on:
push:
branches:
- main
pull_request:
branches:
- main
types:
- opened
- reopened
- synchronize
workflow_dispatch:
concurrency: ${{ github.workflow }}-${{ github.ref }}
env:
WORKSPACES: create-db create-pg create-postgres
PACKAGES_DIR: packages
POSTHOG_API_HOST: ${{ secrets.POSTHOG_API_HOST }}
POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
CREATE_DB_WORKER_URL: ${{ secrets.CREATE_DB_WORKER_URL }}
CLAIM_DB_WORKER_URL: ${{ secrets.CLAIM_DB_WORKER_URL }}
permissions:
contents: read
jobs:
release:
name: π Release CLIs
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: write # to create changeset PRs and version commits
pull-requests: write # to create changeset PRs
id-token: write # required for OIDC / Trusted Publishers
steps:
- name: ποΈ Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: true
- name: π€ Disable Husky
run: echo "HUSKY=0" >> $GITHUB_ENV
- name: π¦ Setup pnpm
uses: pnpm/action-setup@v4
- name: π§ Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
registry-url: "https://registry.npmjs.org"
cache: "pnpm"
- name: π§ Install dependencies
run: pnpm install
- name: β Disable pnpm git-checks
run: pnpm config set git-checks false
- name: π Publish Each CLI Package
env:
CREATE_DB_WORKER_URL: ${{ secrets.CREATE_DB_WORKER_URL }}
CLAIM_DB_WORKER_URL: ${{ secrets.CLAIM_DB_WORKER_URL }}
POSTHOG_API_HOST: ${{ secrets.POSTHOG_API_HOST }}
POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
run: |
echo "Using CREATE_DB_WORKER_URL=${CREATE_DB_WORKER_URL}"
echo "Using CLAIM_DB_WORKER_URL=${CLAIM_DB_WORKER_URL}"
echo "Using POSTHOG_API_HOST=${POSTHOG_API_HOST}"
for pkg in ${{ env.WORKSPACES }}; do
echo "Publishing $pkg to npm..."
cd "${{ env.PACKAGES_DIR }}/$pkg"
export POSTHOG_API_HOST="${POSTHOG_API_HOST}"
export POSTHOG_API_KEY="${POSTHOG_API_KEY}"
export CREATE_DB_WORKER_URL="${CREATE_DB_WORKER_URL}"
export CLAIM_DB_WORKER_URL="${CLAIM_DB_WORKER_URL}"
# First try to publish
if ! pnpm publish --access public --no-git-checks; then
echo "Publish failed, trying to bump version and retry..."
npm version patch --no-git-tag-version
pnpm publish --access public --no-git-checks || echo "Publish failed again for $pkg"
fi
cd - >/dev/null
done
- name: π Ensure Changeset Exists
run: |
if [ -z "$(ls -A .changeset 2>/dev/null)" ]; then
echo "No changeset found. Creating a default one..."
pnpm changeset add --empty --message "chore(release): auto-generated changeset"
fi
- name: π Prepare Changesets PR
id: changesets
uses: changesets/action@v1
with:
version: pnpm changeset version
commit: "chore(release): version packages"
title: "chore(release): version packages"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
preview:
name: π§ Preview release (PR #${{ github.event.number }})
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: write # For publishing to GitHub releases
pull-requests: write # To comment on PRs
id-token: write # required for OIDC / Trusted Publishers
steps:
- name: ποΈ Checkout full history
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: true
- name: π€ Disable Husky
run: echo "HUSKY=0" >> $GITHUB_ENV
- name: π¦ Setup pnpm
uses: pnpm/action-setup@v4
- name: π§ Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
registry-url: "https://registry.npmjs.org"
cache: "pnpm"
- name: π§ Install dependencies
run: pnpm install
- name: β Disable pnpm git-checks
run: pnpm config set git-checks false
- name: π Copy README to child CLIs
run: |
for pkg in create-pg create-postgres; do
cp packages/create-db/README.md "packages/$pkg/README.md"
done
- name: π Create unique preview tag
run: |
SAFE_REF=$(echo "${{ github.event.pull_request.head.ref }}" | tr '/' '-')
echo "PRE_TAG=pr${{ github.event.number }}-${SAFE_REF}-${{ github.run_id }}" >> $GITHUB_ENV
- name: π Bump & publish CLI previews
env:
PRE_TAG: ${{ env.PRE_TAG }}
CREATE_DB_WORKER_URL: ${{ secrets.CREATE_DB_WORKER_URL }}
CLAIM_DB_WORKER_URL: ${{ secrets.CLAIM_DB_WORKER_URL }}
POSTHOG_API_HOST: ${{ secrets.POSTHOG_API_HOST }}
POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
run: |
# Resolve URLs with fallback
CREATE_DB_WORKER_URL="${{ secrets.CREATE_DB_WORKER_URL }}"
CLAIM_DB_WORKER_URL="${{ secrets.CLAIM_DB_WORKER_URL }}"
# Persist for next steps
echo "CREATE_DB_WORKER_URL=$CREATE_DB_WORKER_URL" >> $GITHUB_ENV
echo "CLAIM_DB_WORKER_URL=$CLAIM_DB_WORKER_URL" >> $GITHUB_ENV
echo "Using CREATE_DB_WORKER_URL=$CREATE_DB_WORKER_URL"
echo "Using CLAIM_DB_WORKER_URL=$CLAIM_DB_WORKER_URL"
echo "Using POSTHOG_API_HOST=${POSTHOG_API_HOST}"
for pkg in ${{ env.WORKSPACES }}; do
cd "${{ env.PACKAGES_DIR }}/$pkg"
export CREATE_DB_WORKER_URL
export CLAIM_DB_WORKER_URL
export POSTHOG_API_HOST="${POSTHOG_API_HOST}"
export POSTHOG_API_KEY="${POSTHOG_API_KEY}"
npm version prerelease \
--preid "$PRE_TAG" \
--no-git-tag-version
pnpm publish --access public --tag pr${{ github.event.number }} --no-git-checks
cd - >/dev/null
done
- name: π¬ Post preview-testing instructions
uses: actions/github-script@v6
env:
PRE_TAG: ${{ env.PRE_TAG }}
CREATE_DB_WORKER_URL: ${{ secrets.CREATE_DB_WORKER_URL }}
CLAIM_DB_WORKER_URL: ${{ secrets.CLAIM_DB_WORKER_URL }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const tag = process.env.PRE_TAG;
const dbUrl = process.env.CREATE_DB_WORKER_URL;
const clUrl = process.env.CLAIM_DB_WORKER_URL;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: `
β
**Preview CLIs & Workers are live!**
Test the CLIs locally under tag \`${tag}\`:
\`\`\`bash
npx create-db@pr${{ github.event.number }}
npx create-pg@pr${{ github.event.number }}
npx create-postgres@pr${{ github.event.number }}
\`\`\`
**Worker URLs**
β’ Create-DB Worker: ${dbUrl}
β’ Claim-DB Worker: ${clUrl}
> These will live as long as this PR exists under tag \`${tag}\`.`
});