Fix clicking Table of Contents #16533
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 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') || contains(github.event.pull_request.labels.*.name, ':rocket: deploy-ceramic'))) | |
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/[email protected] | |
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 | |
- 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.STAGE_NAME}}.charmverse.co:3002/g' .ebstalk.apps.env/webapp.env | |
# substituting the connect api domain name | |
sed -i 's/REACT_APP_CONNECT_API_HOST=.*/REACT_APP_CONNECT_API_HOST=https:\/\/${{env.STAGE_NAME}}.charmverse.co:4000/g' .ebstalk.apps.env/connect.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/00_env_vars.config | |
yq -I 4 -i ' | |
with(.option_settings."aws:elasticbeanstalk:application:environment"; | |
.IMGTAG = "${{ github.run_id }}-${{ env.GITHUB_SHA_SHORT }}") | |
' .ebextensions_cron/00_env_vars.config | |
yq -I 4 -i ' | |
with(.option_settings."aws:elasticbeanstalk:application:environment"; | |
.IMGTAG = "${{ github.run_id }}-${{ env.GITHUB_SHA_SHORT }}") | |
' .ebextensions_ceramic/00_env_vars.config | |
yq -I 4 -i ' | |
with(.option_settings."aws:elasticbeanstalk:application:environment"; | |
.IMGTAG = "${{ github.run_id }}-${{ env.GITHUB_SHA_SHORT }}") | |
' .ebextensions_websockets/00_env_vars.config | |
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_connect/00_env_vars.config | |
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_sunnyawards/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/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/00_env_vars.config | |
- name: Set DDENABLED variable in environment for build and deploy steps | |
run: | | |
cat .ebextensions/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: Override config with Connect app | |
# wrap the condition in "${{}}" because the string includes a colon | |
# see https://github.com/actions/runner/issues/1019 | |
if: "${{ contains(github.event.pull_request.labels.*.name, ':rocket: deploy-connect') }}" | |
run: | | |
rm -rf .ebextensions && mv .ebextensions_connect .ebextensions | |
- name: Override config with Sunny Awards | |
# wrap the condition in "${{}}" because the string includes a colon | |
# see https://github.com/actions/runner/issues/1019 | |
if: "${{ contains(github.event.pull_request.labels.*.name, ':rocket: deploy-sunnyawards') }}" | |
run: | | |
rm -rf .ebextensions && mv .ebextensions_sunnyawards .ebextensions | |
- name: Package | |
run: | | |
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 }} | |
# update websockets in staging | |
- name: Update and Package ceramic server | |
run: | | |
rm -rf .ebextensions && mv .ebextensions_ceramic .ebextensions | |
cat files_to_zip.txt | zip --symlinks -r@ deploy_ceramic.zip | |
- name: Deploy ceramic to Beanstalk | |
if: > | |
(github.event.action == 'labeled' && github.event.label.name == 'deploy-ceramic') || | |
(github.event.action != 'labeled' && contains(github.event.pull_request.labels.*.name, 'deploy-ceramic')) | |
uses: einaregilsson/beanstalk-deploy@v22 | |
with: | |
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
application_name: stg-charmverse-ceramic-link | |
environment_name: stg-charmverse-ceramic-link | |
version_label: ${{ github.sha }} | |
region: us-east-1 | |
deployment_package: deploy_ceramic.zip | |
use_existing_version_if_available: true # allows triggering re-deploys with same version | |
wait_for_deployment: false # set to false to save sweet Github minutes | |
# update websockets in staging | |
- name: Update and Package websockets | |
run: | | |
rm -rf .ebextensions && mv .ebextensions_websockets .ebextensions | |
cat files_to_zip.txt | zip --symlinks -r@ deploy_websockets.zip | |
- name: Deploy websockets to Beanstalk | |
uses: einaregilsson/beanstalk-deploy@v22 | |
with: | |
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
application_name: stg-charmverse-websockets | |
environment_name: stg-charmverse-websockets | |
version_label: ${{ github.sha }} | |
region: us-east-1 | |
deployment_package: deploy_websockets.zip | |
use_existing_version_if_available: true # allows triggering re-deploys with same version | |
wait_for_deployment: false # set to false to save sweet Github minutes | |
- 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 |