-
Notifications
You must be signed in to change notification settings - Fork 47
207 lines (182 loc) · 7.09 KB
/
ci.yml
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
name: Preview & Release
on:
push:
tags:
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10
branches:
- main
pull_request:
permissions:
contents: read
pull-requests: write
issues: write
jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy
environment: ${{ startsWith(github.ref, 'refs/tags/v') && 'Production' || 'Staging' }}
outputs:
deployment-url: ${{ steps.deploy.outputs.deployment-url}}
steps:
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
- name: Deploy
id: deploy
uses: cloudflare/wrangler-action@v3
with:
wranglerVersion: "* -w"
packageManager: pnpm # you can omit this if you use npm
workingDirectory: "packages/backend"
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
preCommands: pnpm install && pnpm build
command: pages deploy dist --project-name=pkg-pr-new --branch=main
- name: Deployment Url
env:
DEPLOYMENT_URL: ${{ steps.deploy.outputs.deployment-url }}
run: echo $DEPLOYMENT_URL
release:
environment: Production
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
needs: deploy
steps:
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/
cache: "pnpm"
- run: pnpm install
- run: |
pnpm build:publish
npm publish --access public # new version is already set before the tag event
working-directory: ./packages/cli
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
cr:
concurrency:
group: continuous-releases
runs-on: ubuntu-latest
needs: deploy
steps:
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 18
cache: "pnpm"
- run: pnpm install
- run: echo $API_URL ; pnpm build
env:
API_URL: ${{ needs.deploy.outputs.deployment-url }}
- run: pnpm tsx script/ci.ts
working-directory: ./packages/backend
env:
NITRO_WEBHOOK_SECRET: ${{ secrets.NITRO_WEBHOOK_SECRET }}
NITRO_APP_ID: ${{ secrets.NITRO_APP_ID }}
NITRO_PRIVATE_KEY: ${{ secrets.NITRO_PRIVATE_KEY }}
NITRO_RM_STALE_KEY: ${{ secrets.NITRO_RM_STALE_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: pnpm tsx script/update-webhook-url.ts
if: ${{ github.event_name != 'workflow_dispatch' }}
working-directory: ./packages/backend
env:
API_URL: ${{ needs.deploy.outputs.deployment-url }}
# NITRO_WEBHOOK_SECRET: ${{ secrets.NITRO_WEBHOOK_SECRET }}
NITRO_APP_ID: ${{ secrets.NITRO_APP_ID }}
NITRO_PRIVATE_KEY: ${{ secrets.NITRO_PRIVATE_KEY }}
# NITRO_RM_STALE_KEY: ${{ secrets.NITRO_RM_STALE_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: dummy big file
run: |
file_size=120 # 120 MB
file_path="dummy_random_content.txt"
file_size_in_bytes=$((file_size * 1024 * 1024))
head -c $file_size_in_bytes </dev/urandom >$file_path
echo "File $file_path created with random content of size $file_size MB."
working-directory: ./playgrounds/playground-b
- name: pkg.pr.new
run: pnpm publish:playgrounds --json output.json --comment=off
- name: Post or update comment
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const output = JSON.parse(fs.readFileSync('output.json', 'utf8'));
const packages = output.packages.map(p => `- ${p.name}: ${p.url}`).join('\n');
const templates = output.templates.map(t => `- [${t.name}](${t.url})`).join('\n');
const commitSha = context.eventName === 'pull_request' && github.event.pull_request
? github.event.pull_request.head.sha
: github.sha;
const body = `## Custom Publish Message for ${commitSha.substring(0, 7)}
### Published Packages:
${packages}
### Templates:
${templates}`;
const botCommentIdentifier = '## Custom Publish Message';
async function findBotComment(issueNumber) {
if (!issueNumber) return null;
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber
});
return comments.data.find(comment => comment.body.includes(botCommentIdentifier));
}
async function createOrUpdateComment(issueNumber) {
if (!issueNumber) {
console.log('No issue number provided. Cannot post or update comment.');
return;
}
const existingComment = await findBotComment(issueNumber);
if (existingComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
issue_number: issueNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
}
}
async function logPublishInfo() {
console.log('\n' + '='.repeat(50));
console.log('Publish Information for commit:', commitSha.substring(0, 7));
console.log('='.repeat(50));
console.log('\nPublished Packages:');
console.log(packages);
console.log('\nTemplates:');
console.log(templates);
console.log('\n' + '='.repeat(50));
}
if (context.eventName === 'pull_request') {
if (context.issue.number) {
await createOrUpdateComment(context.issue.number);
}
} else if (context.eventName === 'push') {
const pullRequests = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
head: `${context.repo.owner}:${context.ref.replace('refs/heads/', '')}`
});
if (pullRequests.data.length > 0) {
await createOrUpdateComment(pullRequests.data[0].number);
} else {
console.log('No open pull request found for this push. Logging publish information to console:');
await logPublishInfo();
}
}