Merge branch 'development' of https://github.com/CruGlobal/know-god-w… #549
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build & Deploy | |
on: | |
push: | |
branches: | |
- staging | |
- development | |
- master | |
pull_request: | |
branches: | |
- staging | |
- master | |
workflow_dispatch: | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
build: | |
name: Checks, Tests & Build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Repository checkout | |
uses: actions/checkout@v4 | |
- name: Node.js setup | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: .tool-versions | |
- name: 📦 Install dependencies | |
run: yarn install | |
- name: 💅 Prettier check | |
run: yarn prettier:check | |
- name: 💨 Lint check | |
run: yarn lint | |
- name: ✅ Run Tests | |
run: yarn test --no-watch | |
- name: 🏗️ Build app | |
run: yarn build | |
deploy: | |
name: Deploy | |
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/development') | |
runs-on: ubuntu-latest | |
environment: | |
name: ${{ (github.ref == 'refs/heads/master' && 'prod') || (github.ref == 'refs/heads/staging' && 'stage') || 'dev' }} | |
needs: build | |
permissions: | |
id-token: write | |
contents: read | |
steps: | |
- name: Repository checkout | |
uses: actions/checkout@v4 | |
- name: Node.js setup | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: .tool-versions | |
- name: 📦 Install dependencies | |
run: yarn install | |
- name: 🏗️ Build app | |
run: yarn build --configuration $buildEnvironment | |
env: | |
buildEnvironment: ${{ github.ref == 'refs/heads/development' && 'development' || 'production' }} | |
- name: Copy embed.js | |
run: cp embed/embed.js dist/embed.js | |
- name: Copy mobile directory | |
run: cp -r mobile/ dist/mobile/ | |
- name: Update embed host | |
run: sed -i "s%$appDomainPlaceholder%$appDomain%g" dist/embed.js | |
env: | |
appDomainPlaceholder: '{appDomain}' | |
appDomain: https://${{ secrets.HOST_NAME }} | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-region: us-east-1 | |
role-to-assume: ${{ secrets.AWS_IAM_ROLE_ARN }} | |
- name: Deploy to s3 | |
run: | | |
aws s3 sync dist/knowgod $S3_BUCKET --acl 'public-read' --exclude '*.html' --cache-control 'public, max-age=31536000' --delete | |
aws s3 sync dist/knowgod $S3_BUCKET --acl 'public-read' --include '*.html' --cache-control 'public, max-age=120' --delete | |
aws s3 cp dist/embed.js $S3_BUCKET --acl 'public-read' --cache-control 'public, max-age=600' | |
aws s3 sync dist/mobile $S3_BUCKET --acl 'public-read' --cache-control 'public, max-age=3600' --content-type 'application/json' | |
env: | |
S3_BUCKET: s3://${{ secrets.AWS_S3_BUCKET }} |