Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

give sunny awards its own CI workflow #4466

Merged
merged 13 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .ebextensions/sunnyawards/00_env_vars.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ option_settings:
COMPOSE_PROFILES: "prd-sunnyawards"
EBSTALK_ENV_FILE: "sunnyawards.env"
SERVICE_ENV: "prd" # this sets the value of datadog env tag
SERVICE_NAME: "sunnyawards-app"
IMGNAME: "charmverse-connect"
SERVICE_NAME: "sunnyawards"
IMGNAME: "sunnyawards"
IMGTAG: ""
26 changes: 26 additions & 0 deletions .github/actions/build_app/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: 'Build app'

inputs:
app_name:
description: The name of the app'
required: true

runs:
using: 'composite'
steps:

- name: Restore build
id: restore_build
uses: actions/cache@v4
with:
# include the public folder in case the build output puts something there (like sw.js)
path: |
apps/${{ inputs.app_name }}/.next
apps/${{ inputs.app_name }}/public
key: app-${{ inputs.app_name }}-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('lib/**/*.ts[x]', '@connect-shared/**/*.ts[x]', 'apps/${{ inputs.app_name }}/**/*.ts', 'apps/${{ inputs.app_name }}/**/*.scss') }}

- name: Build app
shell: bash
if: steps.restore_build.outputs.cache-hit != 'true'
run: |
npm run ${{ inputs.app_name }}:build
21 changes: 0 additions & 21 deletions .github/actions/build_connect/action.yml

This file was deleted.

19 changes: 0 additions & 19 deletions .github/actions/build_farcaster/action.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on:
- 'package.json'
- 'package-lock.json'
- 'apps/connect/**'
- 'apps/sunnyawards/**'
- '@connect-shared/**'
- 'abis/**'
- 'adapters/**'
Expand Down Expand Up @@ -70,8 +69,10 @@ jobs:
commit_core_pkg_upgrade: true
save_cache: true

- name: Build apps
uses: ./.github/actions/build_connect
- name: Build app
uses: ./.github/actions/build_app
with:
app_name: connect

# source https://github.com/orgs/community/discussions/28474
- name: Print head git commit message
Expand Down Expand Up @@ -110,18 +111,15 @@ jobs:
run: npx dotenv -e .env.test.local -- npm run prisma:reset

- name: Restore app from cache
uses: ./.github/actions/build_connect
uses: ./.github/actions/build_app
with:
app_name: connect

- name: Validate Webapp
run: |
npm run lint -w apps/connect
npm run typecheck -w apps/connect

- name: Validate Sunny Awards
run: |
npm run lint -w apps/sunnyawards
npm run typecheck -w apps/sunnyawards

test-connect-e2e:
name: Test Connect e2e
runs-on: ubuntu-latest
Expand Down Expand Up @@ -154,7 +152,9 @@ jobs:
run: npx dotenv -e .env.test.local -- npm run prisma:reset

- name: Restore app from cache
uses: ./.github/actions/build_connect
uses: ./.github/actions/build_app
with:
app_name: connect

- name: Start connect app
run: |
Expand Down Expand Up @@ -185,78 +185,14 @@ jobs:
mcr.microsoft.com/playwright:v1.42.1-jammy \
npm run connect:test:e2e:ci

test-sunnyawards-e2e:
name: Test Sunny Awards e2e
runs-on: ubuntu-latest
needs: build-app
if: ${{ github.event.action != 'labeled' && !contains(needs.build-app.outputs.head-commit-message, 'skip-tests') }}
# Postgres setup copied from https://gist.github.com/2color/537f8ef13ecec80059abb007839a6878
services:
postgres:
image: postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
--hostname postgres
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432

steps:
- uses: actions/checkout@v4

- name: Restore dependencies from cache
uses: ./.github/actions/install

- name: Setup test database
run: npx dotenv -e .env.test.local -- npm run prisma:reset

- name: Restore app from cache
uses: ./.github/actions/build_connect

- name: Start Sunny Awards app
run: |
npm run sunnyawards:start:test:ci &> connect.log &
sleep_loop_ct=0
until curl localhost:3337/api/health || [[ $sleep_loop_ct > 30 ]]; do
echo "webapp not up in loop $sleep_loop_ct ... sleeping"
sleep_loop_ct=$((sleep_loop_ct + 1))
sleep 1
done

- name: Run Sunny Awards E2E tests
env:
REACT_APP_APP_ENV: 'test'
# we have to run docker command ourselves to set network=host so that playwright can access the server
run: |
[[ "${{ runner.debug }}" = "1" ]] && tail -f connect.log &
docker run --name mcrmicrosoftcomplaywrightv1343jammy_68c205 \
--workdir /github/workspace --rm \
-e "REACT_APP_APP_ENV" -e CI=true \
-v "/var/run/docker.sock":"/var/run/docker.sock" \
-v "/home/runner/work/_temp/_github_home":"/github/home" \
-v "/home/runner/work/_temp/_github_workflow":"/github/workflow" \
-v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" \
-v "/home/runner/work/app.charmverse.io/app.charmverse.io":"/github/workspace" \
--network "host" \
--ipc=host \
mcr.microsoft.com/playwright:v1.42.1-jammy \
npm run sunnyawards:test:e2e:ci

upload-docker:
name: Upload Docker image
runs-on: ubuntu-latest
# run whether previous jobs were successful or skipped
if: |
github.ref == 'refs/heads/main' ||
(github.event.action == 'labeled' && github.event.label.name == ':rocket: deploy-connect') ||
(github.event.action == 'labeled' && github.event.label.name == ':rocket: deploy-sunnyawards') ||
(github.event.action != 'labeled' && (contains(github.event.pull_request.labels.*.name, ':rocket: deploy-connect') || contains(github.event.pull_request.labels.*.name, ':rocket: deploy-sunnyawards')))
(github.event.action != 'labeled' && (contains(github.event.pull_request.labels.*.name, ':rocket: deploy-connect')))
needs: build-app
steps:
- uses: actions/checkout@v4
Expand All @@ -266,8 +202,10 @@ jobs:
- name: Install dependencies
uses: ./.github/actions/install

- name: Build app
uses: ./.github/actions/build_connect
- name: Restore app from cache
uses: ./.github/actions/build_app
with:
app_name: connect

- name: Update Dockerfile
run: |
Expand Down Expand Up @@ -303,8 +241,10 @@ jobs:
build_id=${{ hashFiles('package-lock.json', 'apps/**/*.[jt]s', 'lib/**/*.[jt]s') }}
echo "build_id=$build_id" >> $GITHUB_OUTPUT

- name: Build app
uses: ./.github/actions/build_connect
- name: Restore app from cache
uses: ./.github/actions/build_app
with:
app_name: connect

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
Expand All @@ -316,7 +256,6 @@ jobs:
- name: Upload static assets to S3
run: |
aws s3 sync apps/connect/.next/static/ s3://charm.cdn/webapp-assets/_next/static/
aws s3 sync apps/sunnyawards/.next/static/ s3://charm.cdn/webapp-assets/_next/static/

- name: Upload JS source maps to Datadog
env:
Expand All @@ -329,20 +268,16 @@ jobs:
--minified-path-prefix=https://cdn.charmverse.io/_next/static

deploy-production:
name: Deploy ${{ matrix.name }}
name: Deploy to production
# run whether previous jobs were successful or skipped
if: github.ref == 'refs/heads/main' && !(failure() || cancelled())
needs: [test-connect, test-connect-e2e, test-sunnyawards-e2e, upload-docker, upload-static-assets]
needs: [test-connect, test-connect-e2e, upload-docker, upload-static-assets]
runs-on: ubuntu-latest
strategy:
matrix:
include:
- name: Connect App
stack: prd-connect
- stack: prd-connect
ebextensions: connect
- name: Sunny Awards
stack: prd-sunnyawards
ebextensions: sunnyawards
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -382,8 +317,7 @@ jobs:
name: Deploy to staging
if: |
(github.event.action == 'labeled' && github.event.label.name == ':rocket: deploy-connect') ||
(github.event.action == 'labeled' && github.event.label.name == ':rocket: deploy-sunnyawards') ||
(github.event.action != 'labeled' && (contains(github.event.pull_request.labels.*.name, ':rocket: deploy-connect') || contains(github.event.pull_request.labels.*.name, ':rocket: deploy-sunnyawards')))
(github.event.action != 'labeled' && (contains(github.event.pull_request.labels.*.name, ':rocket: deploy-connect')))

runs-on: ubuntu-latest
# prevent workflows running in parallel
Expand All @@ -399,9 +333,7 @@ jobs:

- name: Calculate Stage env var
run: |
if ${{contains(github.event.pull_request.labels.*.name, ':rocket: deploy-connect')}}; then stack='stg-connect'; fi
if ${{contains(github.event.pull_request.labels.*.name, ':rocket: deploy-sunnyawards')}}; then stack='stg-sunnyawards'; fi
full_stage_name="$stack-${{ github.event.number }}-${{ env.GITHUB_HEAD_REF_SLUG }}"
full_stage_name="stg-connect-${{ 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/'`
Expand Down Expand Up @@ -449,24 +381,11 @@ jobs:
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- 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') }}"
# aws s3 sync apps/connect/.next/static/ s3://charm.cdn/webapp-assets/_next/static/
run: |
mv .ebextensions .ebextensions_tmp && mv .ebextensions_tmp/connect .ebextensions

- name: Override config with Sunny Awards
if: "${{ contains(github.event.pull_request.labels.*.name, ':rocket: deploy-sunnyawards') }}"
# aws s3 sync apps/sunnyawards/.next/static/ s3://charm.cdn/webapp-assets/_next/static/
run: |
mv .ebextensions .ebextensions_tmp && mv .ebextensions_tmp/sunnyawards .ebextensions

- name: Set the docker compose env variables
uses: mikefarah/yq@master
with:
cmd: |
mv .ebextensions .ebextensions_tmp && mv .ebextensions_tmp/connect .ebextensions
yq -I 4 -i '
with(.option_settings."aws:elasticbeanstalk:application:environment";
.COMPOSE_PROJECT_NAME = "pr${{ github.event.number }}" |
Expand Down Expand Up @@ -498,16 +417,7 @@ jobs:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && failure()
# pass in all steps so we can check if any failed
needs:
[
test-connect,
test-connect-e2e,
test-sunnyawards-e2e,
upload-docker,
upload-static-assets,
upload-docker,
deploy-production
]
needs: [test-connect, test-connect-e2e, upload-docker, upload-static-assets, upload-docker, deploy-production]
steps:
- name: If any of prev jobs failed notify discord
if: contains(needs.*.result, 'failure')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ jobs:
save_cache: true

- name: Build apps
uses: ./.github/actions/build_farcaster
uses: ./.github/actions/build_app
with:
app_name: farcaster

# source https://github.com/orgs/community/discussions/28474
- name: Print head git commit message
Expand All @@ -88,7 +90,9 @@ jobs:
uses: ./.github/actions/install

- name: Build app
uses: ./.github/actions/build_farcaster
uses: ./.github/actions/build_app
with:
app_name: farcaster

- name: Update Dockerfile
run: |
Expand Down Expand Up @@ -125,7 +129,9 @@ jobs:
echo "build_id=$build_id" >> $GITHUB_OUTPUT

- name: Build app
uses: ./.github/actions/build_farcaster
uses: ./.github/actions/build_app
with:
app_name: farcaster

- name: Upload JS source maps to Datadog
env:
Expand All @@ -138,16 +144,15 @@ jobs:
--minified-path-prefix=https://cdn.charmverse.io/_next/static

deploy-production:
name: Deploy ${{ matrix.name }}
name: Deploy to production
# run whether previous jobs were successful or skipped
if: github.ref == 'refs/heads/main' && !(failure() || cancelled())
needs: [upload-docker, upload-static-assets]
runs-on: ubuntu-latest
strategy:
matrix:
include:
- name: Farcaster App
stack: prd-farcaster
- stack: prd-farcaster
ebextensions: farcaster
steps:
- uses: actions/checkout@v4
Expand Down
Loading
Loading