Skip to content

Cleanup the admin dashboard (#4891) #150

Cleanup the admin dashboard (#4891)

Cleanup the admin dashboard (#4891) #150

name: Scoutgame Scout Game Admin CI
on:
push:
branches: [main]
paths:
- '.cdk/**'
- 'docker-compose.yml'
- '.ebextensions/scoutgameadmin/**'
- '.ebstalk.apps.env/scoutgameadmin.env'
- '.github/actions/**'
- '.github/workflows/deploy_scoutgameadmin.yml'
- 'package.json'
- 'package-lock.json'
- 'apps/scoutgameadmin/**'
pull_request:
types: [labeled, opened, synchronize]
branches: ['**']
paths:
- '.cdk/**'
- 'docker-compose.yml'
- '.ebextensions/scoutgameadmin/**'
- '.ebstalk.apps.env/scoutgameadmin.env'
- '.github/actions/**'
- '.github/workflows/deploy_scoutgameadmin.yml'
- 'package.json'
- 'package-lock.json'
- 'apps/scoutgameadmin/**'
workflow_dispatch:
inputs:
core_pkg_version:
description: 'Core pkg version to update to'
required: true
concurrency:
group: ci-scoutgameadmin-${{ github.event_name }}-${{ github.ref }}
jobs:
build:
name: Build Scout Game Admin
runs-on: ubuntu-latest
outputs:
head_commit_message: ${{ steps.setup_variables.outputs.commit_message }}
deploy_staging: ${{ steps.setup_variables.outputs.deploy_staging }}
skip_tests: ${{ steps.setup_variables.outputs.skip_tests }}
steps:
- name: Print Triggering event context payload
env:
workflow_event_context: ${{ toJSON(github.event) }}
run: |
echo "$workflow_event_context"
echo "Workflow and code ref: ${{github.ref}}"
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup variables
id: setup_variables
# source https://github.com/orgs/community/discussions/28474
run: |
echo "commit_message=$(git show -s --format=%s)" >> "$GITHUB_OUTPUT"
echo "deploy_staging=${{(github.event.action == 'labeled' && github.event.label.name == ':rocket: deploy-scoutgameadmin') || (github.event.action != 'labeled' && contains(github.event.pull_request.labels.*.name, ':rocket: deploy-scoutgameadmin'))}}" >> $GITHUB_OUTPUT
echo "skip_tests=${{ contains(env.commit_message, 'skip-tests') }}" >> $GITHUB_OUTPUT
- name: Install dependencies
uses: ./.github/actions/install
with:
core_pkg_version: ${{ inputs.core_pkg_version }}
commit_core_pkg_upgrade: true
- name: Build app
uses: ./.github/actions/build_app
with:
app_name: scoutgameadmin
test-scoutgameadmin:
name: Test apps
runs-on: ubuntu-latest
needs: build
if: ${{ github.event.action != 'labeled' && needs.build.outputs.skip_tests != 'true' }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Restore dependencies from cache
uses: ./.github/actions/install
- name: Restore app from cache
uses: ./.github/actions/build_app
with:
app_name: scoutgameadmin
- name: Typecheck app
run: npm run typecheck -w apps/scoutgameadmin
upload-docker:
name: Upload Docker image
runs-on: ubuntu-latest
# run whether previous jobs were successful or skipped
if: |
github.ref == 'refs/heads/main' || needs.build.outputs.deploy_staging == 'true'
needs: build
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install dependencies
uses: ./.github/actions/install
- name: Restore app from cache
uses: ./.github/actions/build_app
with:
app_name: scoutgameadmin
- name: Update Dockerfile
run: |
rm Dockerfile && mv apps/scoutgameadmin/Dockerfile Dockerfile
- name: Build and Push Docker image
id: docker_build_push
uses: ./.github/actions/build_docker_image
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: us-east-1
with:
ecr_registry: scoutgameadmin
upload-static-assets:
name: Upload assets in production
runs-on: ubuntu-latest
# run whether previous jobs were successful or skipped
if: github.ref == 'refs/heads/main' && !(failure() || cancelled())
needs: build
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install dependencies
uses: ./.github/actions/install
with:
app_name: scoutgameadmin
- name: Calculate Build ID
id: get_build_id
run: |
build_id=${{ hashFiles('package-lock.json', 'apps/**/*.[jt]s', 'lib/**/*.[jt]s') }}
echo "build_id=$build_id" >> $GITHUB_OUTPUT
- name: Restore app from cache
uses: ./.github/actions/build_app
with:
app_name: scoutgameadmin
- name: Configure AWS credentials
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
deploy-production:
name: Deploy to production
# run whether previous jobs were successful or skipped
if: github.ref == 'refs/heads/main' && !(failure() || cancelled())
needs: [test-scoutgameadmin, upload-docker, upload-static-assets]
runs-on: ubuntu-latest
strategy:
matrix:
include:
- stack: prd-scoutgameadmin
ebextensions: scoutgameadmin
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4.x
with:
short-length: 7
# we need to bring back node_modules which includes tsconfig-paths which is used by CDK files
- name: Install dependencies
uses: ./.github/actions/install
with:
app_name: scoutgameadmin
- name: Set the docker compose env variables
uses: mikefarah/yq@master
with:
cmd: |
mv .ebextensions .ebextensions_tmp && mv .ebextensions_tmp/${{ matrix.ebextensions }} .ebextensions
yq -I 4 -i '
with(.option_settings."aws:elasticbeanstalk:application:environment";
.IMGTAG = "${{ github.run_id }}-${{ env.GITHUB_SHA_SHORT }}")
' .ebextensions/00_env_vars.config
- name: Configure AWS credentials
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: Package and deploy
run: |
cat files_to_zip.txt | zip --symlinks -r@ ${{ matrix.stack }}.zip
npx aws-cdk deploy --method=direct -c name=${{ matrix.stack }}
deploy-staging:
name: Deploy to staging
if: needs.build.outputs.deploy_staging == 'true'
runs-on: ubuntu-latest
# prevent staging deploys + cleanup running in parallel
concurrency: staging-${{ github.ref }}
needs: [build, upload-docker]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/deploy_staging
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
app_name: scoutgameadmin
discord-alert:
name: Notify Discord of failure
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && failure()
# pass in all steps so we can check if any failed
needs: [test-scoutgameadmin, upload-docker, upload-static-assets, upload-docker, deploy-production]
steps:
- name: If any of prev jobs failed notify discord
if: contains(needs.*.result, 'failure')
uses: sarisia/actions-status-discord@v1
with:
webhook: ${{ secrets.DISCORD_WARNINGS_WEBHOOK }}
status: 'failure'
content: 'Hey <@&1027309276454207519>'
title: 'Scout Game Admin deploy workflow failed'
description: |
Failed workflow URL: https://github.com/charmverse/app.charmverse.io/actions/runs/${{ github.run_id }}
color: '16515843'
url: 'https://github.com/charmverse/app.charmverse.io/actions/runs/${{ github.run_id }}'
username: GitHub Actions
avatar_url: 'https://github.githubassets.com/images/modules/logos_page/Octocat.png'