diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 3c9eb97f0cd..d9f533a7eef 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -29,358 +29,26 @@ on: - master jobs: - start-prod-server: - name: Test Production Server + deploy: runs-on: ubuntu-latest - timeout-minutes: 10 - strategy: - matrix: - node: [ 22 ] - - services: - postgres: - image: hicommonwealth/cw_postgres:latest - env: - POSTGRES_USER: commonwealth - POSTGRES_DB: common_test - POSTGRES_PASSWORD: edgeware - # Set health checks to wait until postgres has started - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - # Maps tcp port 5432 on service container to the host - - 5432:5432 - redis: - image: redis:latest - ports: - - 6379:6379 - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.event.inputs.pr_number && format('refs/pull/{0}/head', github.event.inputs.pr_number) || github.ref }} - - uses: ./.github/actions/setup - with: - node-version: ${{ matrix.node }} - - - uses: ./.github/actions/e2e - - - name: Build server - run: pnpm -F commonwealth build - - - name: Run serial e2e tests - run: | - pnpm -F commonwealth bootstrap-test-db && - (cd packages/commonwealth && node --import=extensionless/register --enable-source-maps ./build/server.js) & - (pnpm -F commonwealth wait-server && pnpm -F commonwealth test-e2e-serial --forbid-only) - - name: Archive code coverage results - uses: actions/upload-artifact@v4 - with: - name: code-coverage-report - path: coverage - - # Lint with recommendations - commonwealth-code-quality-recommendations: - name: Code Quality Recommendations - runs-on: ubuntu-latest - timeout-minutes: 10 - strategy: - matrix: - node: [ 22 ] - - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - ref: ${{ github.event.inputs.pr_number && format('refs/pull/{0}/head', github.event.inputs.pr_number) || github.ref }} - - uses: ./.github/actions/setup - with: - node-version: ${{ matrix.node }} - - - name: Run linter - run: pnpm lint-branch-warnings - - # Lint and Typecheck - commonwealth-code-quality: - name: Code Quality checks - runs-on: ubuntu-latest - timeout-minutes: 10 - strategy: - matrix: - node: [ 22 ] + - uses: actions/checkout@v2 - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - ref: ${{ github.event.inputs.pr_number && format('refs/pull/{0}/head', github.event.inputs.pr_number) || github.ref }} - - uses: ./.github/actions/setup - with: - node-version: ${{ matrix.node }} + - name: Start timer + run: echo "::set-output name=start::$(date +%s)" + id: timer_start - - name: Assert pnpm-lock.yaml is correct + - name: Install Heroku CLI run: | - if ! git diff --quiet; then - echo 'You need to update the pnpm-lock.yaml file (potentially after installing node-gyp)' - exit 1 - fi - - - name: build - run: pnpm -r build - - - name: check-types - run: pnpm -r check-types - - # To disable eslint-diff just comment the following two lines - - name: Run eslint-diff - run: pnpm -r run lint-diff - - - name: Run eslint-diff-canary to make sure eslint-diff is functioning properly - run: pnpm -F commonwealth run lint-diff-canary - - # fun the *old* linter last because I want to try to migrate away from - # this and JUST to eslint-diff but if this fails we still might be able - # to salvage the branch - - name: Run linter - run: pnpm lint-branch - + curl https://cli-assets.heroku.com/install.sh | sh - detect-broken-ts-expect-error: - name: Detect Broken TS expect errors - runs-on: ubuntu-latest - timeout-minutes: 10 - strategy: - matrix: - node: [ 22 ] - - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - ref: ${{ github.event.inputs.pr_number && format('refs/pull/{0}/head', github.event.inputs.pr_number) || github.ref }} - - uses: ./.github/actions/setup - with: - node-version: ${{ matrix.node }} - - - name: Assert pnpm-lock.yaml is correct + - name: End timer and show duration run: | - if ! git diff --quiet; then - echo 'You need to update the pnpm-lock.yaml file (potentially after installing node-gyp)' - exit 1 - fi - - - name: build - run: pnpm -r build - - - name: run detect-broken-ts-expect-error.sh - run: cd packages/commonwealth && ./scripts/detect-broken-ts-expect-error.sh + end=$(date +%s) + duration=$((end - ${{ steps.timer_start.outputs.start }})) + echo "Duration: ${duration} seconds" - # These tests run quickly, so run them in a separate job - commonwealth-integration-test: - name: Commonwealth Integration Tests - runs-on: ubuntu-latest - timeout-minutes: 20 - strategy: - matrix: - node: [ 22 ] - - services: - postgres: - image: hicommonwealth/cw_postgres:latest - env: - POSTGRES_USER: commonwealth - POSTGRES_DB: common_test - POSTGRES_PASSWORD: edgeware - # Set health checks to wait until postgres has started - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - # Maps tcp port 5432 on service container to the host - - 5432:5432 - redis: - image: redis:latest - ports: - - 6379:6379 - rabbitmq: - image: rabbitmq:3.11-management - ports: - - 5672:5672 - - 15672:15672 - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - ref: ${{ github.event.inputs.pr_number && format('refs/pull/{0}/head', github.event.inputs.pr_number) || github.ref }} - - uses: ./.github/actions/setup - with: - node-version: ${{ matrix.node }} - - # TODO: use devmode instead to avoid building - - name: Build - run: pnpm -r build - - - name: Run integration tests - run: pnpm -F commonwealth test-integration --allowOnly=false - - commonwealth-unit-tests: - name: Commonwealth Unit Tests - runs-on: ubuntu-latest - timeout-minutes: 20 - strategy: - matrix: - node: [ 22 ] - - services: - postgres: - image: hicommonwealth/cw_postgres:latest - env: - POSTGRES_USER: commonwealth - POSTGRES_DB: common_test - POSTGRES_PASSWORD: edgeware - # Set health checks to wait until postgres has started - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - # Maps tcp port 5432 on service container to the host - - 5432:5432 - redis: - image: redis:latest - ports: - - 6379:6379 - rabbitmq: - image: rabbitmq:3.11-management - ports: - - 5672:5672 - - 15672:15672 - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - ref: ${{ github.event.inputs.pr_number && format('refs/pull/{0}/head', github.event.inputs.pr_number) || github.ref }} - - uses: ./.github/actions/setup - with: - node-version: ${{ matrix.node }} - - - name: Run unit tests - run: pnpm -r test -- --allowOnly=false - - - name: Change permissions of coverage files + - name: Deploy to Heroku run: | - chmod -R 755 ./libs/adapters/coverage/lcov.info - chmod -R 755 ./libs/model/coverage/lcov.info - chmod -R 755 ./libs/sitemaps/coverage/lcov.info - - - name: Coveralls parallel - uses: coverallsapp/github-action@v2 - with: - flag-name: unit-test-coverage - parallel: true - files: libs/adapters/coverage/lcov.info libs/model/coverage/lcov.info libs/sitemaps/coverage/lcov.info - - - commonwealth-evm-tests: - name: EVM Devnet Tests - runs-on: ubuntu-latest - timeout-minutes: 10 - strategy: - matrix: - node: [ 22 ] - - services: - postgres: - image: hicommonwealth/cw_postgres:latest - env: - POSTGRES_USER: commonwealth - POSTGRES_DB: common_test - POSTGRES_PASSWORD: edgeware - # Set health checks to wait until postgres has started - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - # Maps tcp port 5432 on service container to the host - - 5432:5432 - redis: - image: redis:latest - ports: - - 6379:6379 - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.event.inputs.pr_number && format('refs/pull/{0}/head', github.event.inputs.pr_number) || github.ref }} - - uses: ./.github/actions/setup - with: - node-version: ${{ matrix.node }} - - - name: Install Foundry - uses: foundry-rs/foundry-toolchain@v1 - - - name: Run EVM Devnet tests - run: pnpm -F commonwealth test-devnet:evm --allowOnly=false - -# Removed until we get image caching set up otherwise it will fail due to dockerhub rate limiting -# commonwealth-e2e-evm-tests: -# name: EVM devnet integration Tests -# runs-on: ubuntu-latest -# timeout-minutes: 10 -# strategy: -# matrix: -# node: [ 22 ] -# -# services: -# postgres: -# image: hicommonwealth/cw_postgres:latest -# env: -# POSTGRES_USER: commonwealth -# POSTGRES_DB: common_test -# POSTGRES_PASSWORD: edgeware -# # Set health checks to wait until postgres has started -# options: >- -# --health-cmd pg_isready -# --health-interval 10s -# --health-timeout 5s -# --health-retries 5 -# ports: -# # Maps tcp port 5432 on service container to the host -# - 5432:5432 -# redis: -# image: redis:latest -# ports: -# - 6379:6379 -# steps: -# - uses: actions/checkout@v4 -# - uses: ./.github/actions/setup -# with: -# node-version: ${{ matrix.node }} -# -# - name: Run EVM devnet integration tests -# run: pnpm -F commonwealth test-devnet:integration --allowOnly=false - - report-coverage: - name: Upload Test Coverage Report - runs-on: ubuntu-latest - timeout-minutes: 5 - needs: [ commonwealth-unit-tests ] - if: always() - strategy: - matrix: - node: [ 22 ] - - steps: - - name: Coveralls Finished - uses: coverallsapp/github-action@v2 - with: - parallel-finished: true + chmod +x ./scripts/deploy-to-heroku.sh + ./scripts/deploy-to-heroku.sh "${{ secrets.HEROKU_EMAIL }}" "${{ secrets.HEROKU_API_TOKEN }}" commonwealth-frick \ No newline at end of file diff --git a/scripts/deploy-to-heroku.sh b/scripts/deploy-to-heroku.sh index 81e31d22c54..87b807521e9 100755 --- a/scripts/deploy-to-heroku.sh +++ b/scripts/deploy-to-heroku.sh @@ -9,6 +9,15 @@ if [ "$#" -ne 3 ]; then exit 1 fi +start_step() { + STEP_START=$(date +%s) +} + +end_step() { + STEP_END=$(date +%s) + echo "[$1] took $((STEP_END - STEP_START)) seconds" +} + email=$1 api_key=$2 app_name=$3 @@ -22,10 +31,21 @@ machine git.heroku.com password ${api_key} EOF + +echo "===> heroku container:login" +start_step + heroku container:login +end_step "heroku container:login" + +echo "===> heroku git:remote --app ${app_name}" +start_step + heroku git:remote --app ${app_name} +end_step "heroku git:remote" + env_path=./packages/commonwealth/deploy/environments/.env.public.${app_name} if [ ! -f ${env_path} ]; then echo "Error: ${env_path} not found" @@ -34,9 +54,15 @@ fi cp ${env_path} .env + +echo "===> docker build -f Dockerfile.datadog" +start_step + # Needed for commonwealth_base docker build -f Dockerfile.datadog -t datadog-base . +end_step "docker build datadog-base" + deploy_heroku_app() { local app_path=$1 local app_name=$2 @@ -47,18 +73,35 @@ deploy_heroku_app() { heroku_tag=registry.heroku.com/${app_name}/${base_name} + echo "===> docker build ${dockerfile}" + start_step + docker build -f ${dockerfile} -t ${heroku_tag}:latest . + end_step "docker build ${base_name}" + + + echo "===> docker push ${heroku_tag}" + start_step echo docker image ls docker push ${heroku_tag}:latest + end_step "docker push ${base_name}" + process_types="${process_types} ${base_name}" done + echo "===> heroku container:release ${process_types} -a ${app_name}" + start_step process_types=$(echo $process_types | xargs) heroku container:release ${process_types} -a ${app_name} + end_step "heroku release" } +echo "===> docker build commonwealth" +start_step docker build . --target commonwealth -t commonwealth -f Dockerfile.commonwealth_base +end_step "docker build commonwealth" + deploy_heroku_app "./packages/commonwealth/deploy/dockerfiles" ${app_name} \ No newline at end of file