-
-
Notifications
You must be signed in to change notification settings - Fork 119
83 lines (71 loc) · 2.36 KB
/
deploy-website.yml
File metadata and controls
83 lines (71 loc) · 2.36 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
name: Deploy Website to S3
on:
push:
branches:
- master
- dev
paths:
- 'apps/old-website/**'
- 'docs/**'
- '.github/workflows/deploy-website.yml'
workflow_dispatch:
inputs:
environment:
description: 'Environment to deploy to'
required: true
type: choice
options:
- dev
- prod
default: 'dev'
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Setup PNPM
uses: pnpm/action-setup@v2
with:
version: 9.6.0
run_install: false
- name: Install dependencies
run: pnpm i
- name: Build Docusaurus Website
run: |
cd apps/old-website
pnpm build
- name: Set environment variables
id: set-env
run: |
if [[ "${{ github.ref }}" == "refs/heads/master" || "${{ github.event.inputs.environment }}" == "prod" ]]; then
echo "S3_BUCKET=${{ secrets.PROD_S3_BUCKET }}" >> $GITHUB_ENV
echo "CLOUDFRONT_ID=${{ secrets.PROD_CLOUDFRONT_ID }}" >> $GITHUB_ENV
echo "Deploying to PRODUCTION"
elif [[ "${{ github.ref }}" == "refs/heads/dev" || "${{ github.event.inputs.environment }}" == "dev" ]]; then
echo "S3_BUCKET=${{ secrets.DEV_S3_BUCKET }}" >> $GITHUB_ENV
echo "CLOUDFRONT_ID=${{ secrets.DEV_CLOUDFRONT_ID }}" >> $GITHUB_ENV
echo "Deploying to DEVELOPMENT"
else
echo "Branch is not configured for deployment. Skipping."
exit 1
fi
- name: Configure AWS Credentials
if: env.S3_BUCKET
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: ${{ secrets.AWS_REGION }}
- name: Deploy to S3 Bucket
if: env.S3_BUCKET
run: |
aws s3 sync ./apps/old-website/build s3://${{ env.S3_BUCKET }} --delete
- name: Invalidate CloudFront
if: env.CLOUDFRONT_ID
run: |
aws cloudfront create-invalidation --distribution-id ${{ env.CLOUDFRONT_ID }} --paths "/*"