-
Notifications
You must be signed in to change notification settings - Fork 91
90 lines (72 loc) · 3.05 KB
/
deploy.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
on:
push:
branches: [ main, release, '*staging*', 'rapid-v1.x' ]
pull_request:
branches: [ main ]
permissions:
id-token: write # required to use OIDC authentication
contents: read # required to checkout the code from the repo
env:
FORCE_COLOR: 2
jobs:
deploy:
runs-on: ubuntu-latest
# This tells Github that a deployment happened and where to find it
environment:
name: Staging
url: ${{ steps.target.outputs.url }}
steps:
- run: |
echo "::remove-matcher owner=eslint-compact::"
echo "::remove-matcher owner=eslint-stylish::"
- name: 📥 Checkout
uses: actions/checkout@v4
- name: ⚙️ Use Node.js 18
uses: actions/setup-node@v4
with:
node-version: 18
- name: 🏗️ Install
run: |
npm install
npm run all
# - name: 🧪 Test
# run: npm run test
- name: 🔐 Setup AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_RAPID_DEPLOY_ROLE_ARN }}
role-duration-seconds: 900 # the ttl of the session, in seconds.
aws-region: us-west-2
- name: 📋 Setup environment vars
run: |
echo "YYYYMMDD=$(date +'%Y%m%d')" >> "$GITHUB_ENV"
echo "BUILD_SHA=$(git rev-parse --short ${{ github.sha }})" >> "$GITHUB_ENV"
# On branch push, the BUILD_ID will be 'branch_name-revision', e.g. `main-d3adc0de`
# The revision is unique, so we save every one of these indefinitely.
- name: 🗂️ Setup BUILD_ID for push
if: ${{ github.event_name == 'push' }}
run: echo "BUILD_ID=${{ github.ref_name }}-${{ env.BUILD_SHA }}" >> "$GITHUB_ENV"
# On pull request, the BUILD_ID will be 'pull-request-#', e.g. `pull-request-1123`
# Subsequent changes to the pull request will overwrite this build.
- name: 🗂️ Setup BUILD_ID for pull request
if: ${{ github.event_name == 'pull_request' }}
run: echo "BUILD_ID=pull-request-${{ github.event.pull_request.number }}" >> "$GITHUB_ENV"
- name: 🎯 Setup deployment targets
id: target
run: |
echo "s3=s3://world.ai.rapid/rapid/${{ env.BUILD_ID }}" >> "$GITHUB_OUTPUT"
echo "url=https://rapideditor.org/rapid/${{ env.BUILD_ID }}/index.html" >> "$GITHUB_OUTPUT"
# Rewrite the urls and embed build info in index.html
- name: 🔨 Predeploy index.html
run: node scripts/predeploy.js
- name: 📤 Copy build to S3
run: |
aws s3 sync dist ${{ steps.target.outputs.s3 }} --delete --only-show-errors
echo "Your build is here: ${{ steps.target.outputs.url }}"
- name: 🐤 Set as canary build
if: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
run: |
aws s3 sync dist s3://world.ai.rapid/canary/ --delete --only-show-errors
aws s3 cp dist/index.html s3://world.ai.rapid/canary --only-show-errors
echo "This is latest build on main, so it is available here: https://rapideditor.org/canary"