-
Notifications
You must be signed in to change notification settings - Fork 70
121 lines (108 loc) · 4.48 KB
/
pr.yml
File metadata and controls
121 lines (108 loc) · 4.48 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
# name: Preview Deploy
on:
- pull_request
permissions:
contents: read
pull-requests: write
env:
NEXT_TELEMETRY_DISABLED: 1
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
ALGOLIA_APP_ID: ${{secrets.ALGOLIA_APP_ID}}
ALGOLIA_INDEX_NAME: ${{secrets.ALGOLIA_INDEX_NAME}}
ALGOLIA_SEARCH_KEY: ${{secrets.ALGOLIA_SEARCH_KEY}}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
deploy-preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # 6.0.1
with:
fetch-depth: 2
- name: Enable Corepack (Pre-Setup)
run: corepack enable
- name: Setup Node.js
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # 6.3.0
with:
node-version: 22
- name: Enable Corepack
run: |
corepack enable
corepack prepare yarn@4.12.0 --activate
- name: Install Vercel CLI
run: npm install --global vercel@canary
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} --scope=${{ secrets.VERCEL_ORG_ID }}
- name: Build Project Artifacts
run: vercel build --token=${{ secrets.VERCEL_TOKEN }} --scope=${{ secrets.VERCEL_ORG_ID }}
- name: Deploy Project Artifacts to Vercel
run: |
DEPLOYMENT_URL=$(vercel deploy --prebuilt --archive=tgz --token=${{ secrets.VERCEL_TOKEN }} --scope=${{ secrets.VERCEL_ORG_ID }})
echo "Deployment URL: $DEPLOYMENT_URL"
vercel alias set $DEPLOYMENT_URL pr-${{ github.event.number }}-midnight-docs.vercel.app --token=${{ secrets.VERCEL_TOKEN }} --scope=${{ secrets.VERCEL_ORG_ID }}
run-LHCI-workflow:
needs: [deploy-preview]
uses: ./.github/workflows/light-house-ci.yml
secrets: inherit
with:
preview_url: pr-${{ github.event.number }}-midnight-docs.vercel.app
run-PWCI-workflow:
needs: [deploy-preview]
uses: ./.github/workflows/playwright-visual-regression.yml
secrets: inherit
with:
preview_url: pr-${{ github.event.number }}-midnight-docs.vercel.app
comment-preview-url:
needs: [deploy-preview]
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Create or update PR comment with preview URL
if: github.event_name == 'pull_request'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 #v9.0.0
with:
script: |
const previewUrl = `https://pr-${{ github.event.number }}-midnight-docs.vercel.app`;
const commentHeader = "### 🚀 Preview Deployment";
const timestamp = new Date().toISOString();
const commitSha = context.sha.substring(0, 7);
// Fetch existing comments
const { data: comments } = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
});
// Look for an existing comment we created earlier
const existing = comments.find(c =>
c.user.type === "Bot" &&
c.body.includes(commentHeader)
);
const dateStr = new Date(timestamp).toLocaleString('en-US', {
timeZone: 'UTC',
dateStyle: 'medium',
timeStyle: 'short'
});
const body = `${commentHeader}\n\n✅ **Deployment Ready**\n\n🔗 **Preview URL:** ${previewUrl}\n\n📝 **Latest commit:** \`${commitSha}\`\n⏰ **Updated:** ${dateStr} UTC\n\n---\n*This preview updates automatically when you push new commits to this PR.*`;
if (existing) {
// Update existing comment
await github.rest.issues.updateComment({
comment_id: existing.id,
owner: context.repo.owner,
repo: context.repo.repo,
body
});
console.log('Updated existing preview URL comment');
} else {
// Create new comment
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body
});
console.log('Created new preview URL comment');
}