-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (83 loc) · 3.15 KB
/
pr-preview.yml
File metadata and controls
99 lines (83 loc) · 3.15 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
name: PR Preview Deployment
on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- 'client/**'
- '.github/workflows/pr-preview.yml'
permissions:
contents: read
pull-requests: write
issues: write
jobs:
deploy-preview:
runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.full_name == github.repository
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
cache-dependency-path: client/package-lock.json
- name: Install dependencies
working-directory: client
run: npm ci
- name: Build application
working-directory: client
run: npm run build
- name: Deploy to S3 PR Preview
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: us-east-1
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
aws s3 sync client/dist s3://6v-simulator-pr-previews/pr-${PR_NUMBER}/ --delete
- name: Invalidate CloudFront
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: us-east-1
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
aws cloudfront create-invalidation \
--distribution-id E1DZ4HUUOSPRK5 \
--paths "/pr-${PR_NUMBER}/*"
- name: Comment PR with preview URL
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request.number;
const previewUrl = `https://pr-${prNumber}.dev.6v.allison.la`;
const comment = `## 🚀 PR Preview Ready!
**Preview URL:** ${previewUrl}
**Commit:** ${context.sha.substring(0, 7)}
This preview will be automatically updated with new commits.
The preview will be removed when the PR is closed.`;
// Find and update existing comment or create new one
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('PR Preview Ready')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: comment
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: comment
});
}