forked from mozilla/pdf.js
-
Notifications
You must be signed in to change notification settings - Fork 0
80 lines (69 loc) · 2.73 KB
/
publish_website_to_aws.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
name: Deploy Website to AWS
on:
pull_request:
types: [opened, synchronize, reopened]
push:
branches:
- master
jobs:
build-deploy:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
pull-requests: write # Ensure GitHub Actions can comment on PRs
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
- name: Install dependencies
run: |
npm ci
npm install -g gulp-cli
- name: Build the website
run: gulp web
- name: Configure AWS credentials (Pull Request)
if: github.event_name == 'pull_request'
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Deploy to S3 (Pull Request)
if: github.event_name == 'pull_request'
run: |
aws s3 sync build/gh-pages/ s3://${{ vars.AWS_BUCKET_NAME }}/${{ github.event.pull_request.head.sha }}/ --acl public-read
- name: Comment deployment URL on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const url = `https://${{ vars.AWS_BUCKET_NAME }}.s3.us-east-1.amazonaws.com/${{ github.event.pull_request.head.sha }}/web/viewer.html?file=${{ vars.TEST_PDF }}`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Preview your deployment: [View Here](${url})`
});
- name: Configure AWS credentials (Production)
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/github-actions-role
aws-region: us-east-1
role-session-name: GitHubActionsSession
- name: Deploy to S3 (Production)
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
run: |
aws s3 sync build/gh-pages/ s3://${{ vars.AWS_PRODUCTION_BUCKET_NAME }}/ --acl public-read
- name: Update environment secret with production URL
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
run: |
gh secret set PRODUCTION_URL -b "https://dfdsfqw2easdfas.cloudfront.net/web/viewer.html"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}