-
Notifications
You must be signed in to change notification settings - Fork 2
90 lines (71 loc) · 2.53 KB
/
deploy-staging.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
81
82
83
84
85
86
87
88
89
90
name: Deploy Staging
on:
pull_request:
branches:
- main
env:
PR_NUMBER: ${{github.event.pull_request.number}}
AWS_BUCKET_NAME: gatsby-uswds-ts-starter
AWS_REGION: us-west-1
jobs:
run-ci:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
name: Lint, test, build and deploy
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install pnpm
uses: pnpm/[email protected]
with:
version: 7
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: lts/*
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
- name: Check types
run: pnpm type-check
- name: Check linting
run: pnpm lint
- name: Run tests
run: pnpm test
- name: Check commits messages
uses: wagoid/commitlint-github-action@v5
- name: Set DESTINATION_FOLDER for branch
run: |
echo "DESTINATION_FOLDER=$(echo $PR_NUMBER-$GITHUB_SHA | cut -c 1-11)" >> $GITHUB_ENV
- name: Build project
run: pnpm build
env:
SITE_URL: "${{ secrets.STAGE_SITE_URL }}"
DEPLOY_PREFIX: "/${{env.DESTINATION_FOLDER}}/"
- name: Write AWS_REGION to env context
run: |
echo "AWS_REGION=$(echo $AWS_REGION)" >> $GITHUB_ENV
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Deploy to AWS
run: aws s3 sync ./public/ s3://$AWS_BUCKET_NAME/${{env.DESTINATION_FOLDER}} --acl public-read --delete
- name: Write AWS_BUCKET_NAME to env context
run: |
echo "AWS_BUCKET_NAME=$(echo $AWS_BUCKET_NAME)" >> $GITHUB_ENV
- name: Update PR with staging URL
uses: mshick/add-pr-comment@v1
with:
# Deploy to S3 for the staging URL
message: |
**🚢 Here is the frontend staging link: 🚢**
Find it here: http://${{env.AWS_BUCKET_NAME}}.s3-website.${{env.AWS_REGION}}.amazonaws.com/${{env.DESTINATION_FOLDER}} !
repo-token: ${{ secrets.GITHUB_TOKEN }}
repo-token-user-login: "github-actions[bot]" # The user.login for temporary GitHub tokens
allow-repeats: false # This is the default