Skip to content

Commit a5a8281

Browse files
committed
ci(content): improve deploy content
1 parent 5e8299b commit a5a8281

File tree

2 files changed

+11
-33
lines changed

2 files changed

+11
-33
lines changed

β€Ž.github/workflows/deploy-content.yamlβ€Ž

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,28 @@ name: Deploy Content
33
on:
44
push:
55
branches: [main]
6-
pull_request:
6+
pull_request_target:
77
types: [opened, reopened, synchronize, closed]
88

99
concurrency:
1010
group: deploy-content-${{ github.ref }}
1111

1212
env:
1313
STAGE: ${{ github.ref == 'refs/heads/main' && 'prod' || format('pr-{0}', github.event.number) }}
14+
COMMAND: ${{ github.event_name == 'pull_request_target' && github.event.action == 'closed' && 'destroy' || 'deploy' }}
15+
SHA: ${{ github.event.pull_request.head.sha || github.sha }}
1416

1517
jobs:
16-
deploy:
18+
deploy-or-destroy:
1719
if: ${{ github.event.action != 'closed' }}
1820
runs-on: ubuntu-latest
1921
permissions:
2022
contents: read
2123
pull-requests: write
2224
steps:
2325
- uses: actions/checkout@v4
24-
25-
- uses: pnpm/action-setup@v4
26-
27-
- uses: actions/setup-node@v5
2826
with:
29-
node-version: 22
30-
cache: pnpm
31-
32-
- run: pnpm i
33-
34-
- run: cd apps/content && pnpm alchemy deploy --stage ${{ env.STAGE }}
35-
env:
36-
ALCHEMY_STATE_TOKEN: ${{ secrets.ALCHEMY_STATE_TOKEN }}
37-
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
38-
PULL_REQUEST: ${{ github.event.number }}
39-
GITHUB_SHA: ${{ github.sha }}
40-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41-
42-
cleanup:
43-
runs-on: ubuntu-latest
44-
if: ${{ github.event_name == 'pull_request' && github.event.action == 'closed' }}
45-
permissions:
46-
contents: read
47-
pull-requests: write
48-
steps:
49-
- uses: actions/checkout@v4
27+
ref: ${{ env.SHA }}
5028

5129
- uses: pnpm/action-setup@v4
5230

@@ -57,10 +35,10 @@ jobs:
5735

5836
- run: pnpm i
5937

60-
- run: cd apps/content && pnpm alchemy destroy --stage ${{ env.STAGE }}
38+
- run: cd apps/content && pnpm alchemy ${{ env.COMMAND }} --stage ${{ env.STAGE }}
6139
env:
6240
ALCHEMY_STATE_TOKEN: ${{ secrets.ALCHEMY_STATE_TOKEN }}
6341
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
6442
PULL_REQUEST: ${{ github.event.number }}
65-
GITHUB_SHA: ${{ github.sha }}
43+
GITHUB_SHA: ${{ env.SHA }}
6644
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

β€Žapps/content/alchemy.run.tsβ€Ž

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const app = await alchemy('orpc-content', {
1111
stateStore: scope => new CloudflareStateStore(scope),
1212
})
1313

14-
const content = await Website('content', {
14+
const website = await Website('website', {
1515
build: {
1616
command: 'pnpm run build',
1717
},
@@ -21,18 +21,18 @@ const content = await Website('content', {
2121
}),
2222
})
2323

24-
console.log(`βœ… Deployed to: ${content.url}`)
24+
console.log(`βœ… Deployed to: ${website.url}`)
2525

2626
if (process.env.PULL_REQUEST) {
27-
await GitHubComment('preview-comment', {
27+
await GitHubComment('pr-preview-comment', {
2828
owner: 'unnoq',
2929
repository: 'orpc',
3030
issueNumber: Number(process.env.PULL_REQUEST),
3131
body: `## πŸš€ Preview Deployed
3232
3333
Your changes have been deployed to a preview environment:
3434
35-
**🌐 Website:** ${content.url}
35+
**🌐 Website:** ${website.url}
3636
3737
Built from commit ${process.env.GITHUB_SHA?.slice(0, 7) ?? 'unknown'}
3838

0 commit comments

Comments
Β (0)