1
- name : Surge PR Preview
1
+ name : Preview Deployment
2
2
3
- on : [pull_request]
3
+ on :
4
+ pull_request :
5
+ types : [opened, synchronize, reopened, closed]
4
6
5
7
env :
6
8
NODE : 18
7
9
WORKING_DIRECTORY : packages/web
8
10
9
11
jobs :
10
- preview :
12
+ build :
11
13
runs-on : ubuntu-latest
12
14
permissions :
13
- pull-requests : write # allow surge-preview to create/update PR comments
15
+ id-token : write
16
+ contents : read
17
+
14
18
steps :
19
+ - name : Cancel Previous Runs
20
+
21
+ with :
22
+ access_token : ${{ secrets.GITHUB_TOKEN }}
23
+
15
24
- name : Checkout
16
25
uses : actions/checkout@v3
17
26
@@ -30,12 +39,29 @@ jobs:
30
39
run : yarn lint
31
40
working-directory : ${{ env.WORKING_DIRECTORY }}
32
41
33
- - uses : afc163/surge-preview@v1
34
- id : preview_step
42
+ - name : Configure AWS credentials using OIDC
43
+ uses : aws-actions/configure-aws-credentials@v2
35
44
with :
36
- surge_token : ${{ secrets.SURGE_TOKEN }}
37
- dist : dist
38
- build : |
39
- vite build
40
- - name : Get the preview_url
41
- run : echo "url => ${{ steps.preview_step.outputs.preview_url }}"
45
+ role-to-assume : arn:aws:iam::003081160852:role/osm-gradient-deploy-s3-role
46
+ aws-region : us-east-1
47
+
48
+ - name : Build
49
+ run : npx vite build
50
+ working-directory : ${{ env.WORKING_DIRECTORY }}
51
+
52
+ - name : Deploy to S3 (Preview)
53
+ if : github.event.action != 'closed'
54
+ run : |
55
+ PR_NUMBER=${{ github.event.number }}
56
+ BUCKET_NAME="osm-gradient-pr-${PR_NUMBER}"
57
+ aws s3 mb s3://$BUCKET_NAME
58
+ aws s3 sync ./dist s3://$BUCKET_NAME --delete
59
+ aws s3 website s3://$BUCKET_NAME --index-document index.html --error-document index.html
60
+ working-directory : ${{ env.WORKING_DIRECTORY }}
61
+
62
+ - name : Cleanup S3 Bucket
63
+ if : github.event.action == 'closed'
64
+ run : |
65
+ PR_NUMBER=${{ github.event.number }}
66
+ BUCKET_NAME="osm-gradient-pr-${PR_NUMBER}"
67
+ aws s3 rb s3://$BUCKET_NAME --force
0 commit comments