always show a users current week rank #1475
Workflow file for this run
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: 'Deploy Webapp to staging' | |
on: | |
pull_request: | |
types: [labeled, opened, synchronize] | |
env: | |
SELECTED_PERMISSION_API_TAG: latest | |
concurrency: | |
group: staging-${{ github.ref }} | |
jobs: | |
deploy: | |
if: | | |
(github.event.action == 'labeled' && github.event.label.name == ':rocket: deploy') || | |
(github.event.action != 'labeled' && contains(github.event.pull_request.labels.*.name, ':rocket: deploy')) | |
runs-on: ubuntu-latest | |
# prevent workflows running in parallel | |
concurrency: deploy-pr-app-${{ github.head_ref }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Inject slug/short variables | |
uses: rlespinasse/github-slug-action@v4.x | |
with: | |
short-length: 7 | |
- name: Calculate Build ID and Stage env var | |
id: get_build_id | |
run: | | |
build_id=${{ hashFiles('package-lock.json', 'pages/api/**/*.[jt]s', 'lib/**/*.[jt]s') }} | |
echo "build_id=$build_id" >> $GITHUB_OUTPUT | |
full_stage_name="stg-webapp-${{ github.event.number }}-${{ env.GITHUB_HEAD_REF_SLUG }}" | |
# sanitize and trim string so that it can be used as a valid subdomain. Includes removing hyphens at the start and end of the name | |
stage_name=`echo "$full_stage_name" | sed -E -e 's/[^a-zA-Z0-9-]+//g' -e 's/(.{40}).*/\1/' -e 's/^-/0/' -e 's/-$/0/'` | |
# export the stage name so that it can be used in other steps | |
echo "STAGE_NAME=$stage_name" >> $GITHUB_ENV | |
# calculate web sockets staging domain name | |
websockets_full_stage_name="stg-websockets-${{ github.event.number }}-${{ env.GITHUB_HEAD_REF_SLUG }}" | |
websockets_stage_name=`echo "$websockets_full_stage_name" | sed -E -e 's/[^a-zA-Z0-9-]+//g' -e 's/(.{40}).*/\1/' -e 's/^-/0/' -e 's/-$/0/'` | |
echo "WEBSOCKETS_STAGE_NAME=$websockets_stage_name" >> $GITHUB_ENV | |
- name: Install dependencies | |
uses: ./.github/actions/install | |
- name: Build app | |
uses: ./.github/actions/build | |
with: | |
REACT_APP_APP_ENV: 'staging' | |
- 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: charmverse-web3-workspace | |
- name: Replace env_var with staging settings | |
run: | | |
ebextension_files=$(ls .ebextensions/*/00_env_vars.config) | |
ebstalk_apps_env_files=$(ls .ebstalk.apps.env/*) | |
for conf_file in $ebextension_files $ebstalk_apps_env_files; do | |
sed -i 's/prd/stg/g' $conf_file | |
sed -i 's/production/staging/g' $conf_file | |
done | |
# modifying cloudformation alarm to send alerts to test sns topic. | |
# leaving it in even if we're deleting the config before deploying | |
# Useful to avoid accidental triggering to system-status channel. | |
for conf_file in .ebextensions/*/06_cloudwatch_alarm.config; do | |
sed -i 's/Production-Alerts/lambda-test-debug/g' $conf_file | |
done | |
rm .ebextensions/*/06_cloudwatch_alarm.config | |
# substituting the websocket domain name | |
sed -i 's/REACT_APP_WEBSOCKETS_HOST=.*/REACT_APP_WEBSOCKETS_HOST=https:\/\/${{env.WEBSOCKETS_STAGE_NAME}}.charmverse.co/g' .ebstalk.apps.env/webapp.env | |
- name: Set the docker compose env variables | |
uses: mikefarah/yq@master | |
with: | |
cmd: | | |
yq -I 4 -i ' | |
with(.option_settings."aws:elasticbeanstalk:application:environment"; | |
.COMPOSE_PROJECT_NAME = "pr${{ github.event.number }}" | | |
.IMGTAG = "${{ github.run_id }}-${{ env.GITHUB_SHA_SHORT }}") | |
' .ebextensions/webapp/00_env_vars.config | |
- name: Run specific version of permission api if SELECTED_PERMISSION_API_TAG exists | |
if: env.SELECTED_PERMISSION_API_TAG && env.GITHUB_HEAD_REF_SLUG == env.SELECTED_PERMISSION_API_TAG | |
uses: mikefarah/yq@master | |
with: | |
cmd: | | |
yq -I 4 -i ' | |
with(.option_settings."aws:elasticbeanstalk:application:environment"; | |
.PERMISSION_IMGTAG = "${{ env.SELECTED_PERMISSION_API_TAG }}") | |
' .ebextensions/webapp/00_env_vars.config | |
- name: Parse compose profile to see if we need to enable datadog | |
id: get_compose_profiles | |
uses: mikefarah/yq@master | |
with: | |
cmd: yq -r '.option_settings."aws:elasticbeanstalk:application:environment".COMPOSE_PROFILES' .ebextensions/webapp/00_env_vars.config | |
- name: Set DDENABLED variable in environment for build and deploy steps | |
run: | | |
cat .ebextensions/webapp/00_env_vars.config | |
COMPOSE_PROFILES=${{ steps.get_compose_profiles.outputs.result }} | |
if [[ "$COMPOSE_PROFILES" =~ ddtst ]]; then | |
echo "DDENABLED=true" >> $GITHUB_ENV | |
fi | |
- name: Create a github deployment | |
uses: bobheadxi/deployments@v1 | |
id: deployment | |
with: | |
step: start | |
token: ${{ secrets.GITHUB_TOKEN }} | |
env: ${{ env.STAGE_NAME }} | |
ref: ${{ github.head_ref }} | |
override: true | |
- 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: Upload static assets to S3 | |
run: aws s3 sync .next/static/ s3://charm.cdn/webapp-assets/_next/static/ | |
- name: Package | |
run: | | |
mv .ebextensions .ebextensions_tmp && mv .ebextensions_tmp/webapp .ebextensions | |
cat files_to_zip.txt | zip --symlinks -r@ ${{env.STAGE_NAME}}.zip | |
- name: Deploy to staging | |
id: cdk_deploy | |
run: | | |
npm install -g aws-cdk | |
npx cdk deploy -c name=${{env.STAGE_NAME}} --method=direct --outputs-file cdk.out.json | |
env_url=$(jq --raw-output '.[$ENV.STAGE_NAME].DeploymentUrl' ./cdk.out.json) | |
echo "env_url=$env_url" >> $GITHUB_OUTPUT | |
- name: update the github deployment status | |
uses: bobheadxi/deployments@v1 | |
if: always() | |
with: | |
env: ${{ steps.deployment.outputs.env }} | |
step: finish | |
override: false | |
token: ${{ secrets.GITHUB_TOKEN }} | |
status: ${{ job.status }} | |
deployment_id: ${{ steps.deployment.outputs.deployment_id }} | |
env_url: ${{ steps.cdk_deploy.outputs.env_url }} | |
- name: Use datadog ci package to upload js maps | |
env: | |
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }} | |
run: | | |
npm install @datadog/datadog-ci --force | |
npx datadog-ci sourcemaps upload .next/static \ | |
--service=webapp \ | |
--release-version=${{ steps.docker_build_push.outputs.img_tag }} \ | |
--minified-path-prefix=${{ steps.cdk_deploy.outputs.env_url }}_next/static |