<NME> push-main.yml
<BEF> name: CI [main]

on:
  push:
    branches: [main]

permissions:
  lint:
    name: Lint All
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
        with:
    steps:
      - uses: actions/checkout@v3
      - uses: volta-cli/action@v4
      - uses: ./.github/actions/setup-node-modules-cache
        with:
          yarn_lock_md5: ${{ hashFiles('yarn.lock') }}

      - run: yarn --prefer-offline --frozen-lockfile

  lint:
    name: Lint All
    needs: update-cache
    runs-on: ubuntu-latest
    env:
      # we are running into heap out of memory issues with the linting--so
      # increasing the heap size to 8GB
      NODE_OPTIONS: --max-old-space-size=8192
    steps:
      - uses: actions/checkout@v3
      - uses: volta-cli/action@v4
      - uses: ./.github/actions/setup-node-modules-cache
        with:
          yarn_lock_md5: ${{ hashFiles('yarn.lock') }}

      - run: yarn --prefer-offline --frozen-lockfile
      - run: yarn lint

  check_secrets:
    name: Check Secret Access
    needs: update-cache
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: volta-cli/action@v4
      - uses: ./.github/actions/setup-node-modules-cache
        with:
          yarn_lock_md5: ${{ hashFiles('yarn.lock') }}

      - run: yarn --prefer-offline --frozen-lockfile
      - name: Configure staging AWS credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          role-to-assume: arn:aws:iam::680542703984:role/waypoint
          aws-region: us-east-1
      - name: Check access to secrets specified in waypoint.hcl
        uses: ./.github/actions/check-secrets
        with:
          waypoint_config_file: waypoint.hcl
      - name: Configure prod AWS credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          role-to-assume: arn:aws:iam::120317779495:role/waypoint
          aws-region: us-east-1
      - name: Check access to secrets specified in waypoint.prod.hcl
        uses: ./.github/actions/check-secrets
        with:
          waypoint_config_file: waypoint.prod.hcl

  test_all_but_web_client:
    name: hub, did-resolver Build/Test
    needs: lint
    runs-on: ubuntu-latest
    env:
      CARDBOT_TOKEN: ${{ secrets.CARDBOT_TOKEN }}
      CORDE_BOT_TOKEN: ${{ secrets.CORDE_BOT_TOKEN }}
    services:
      postgres:
        image: postgres:13
        env:
          POSTGRES_DB: postgres
          POSTGRES_PASSWORD: postgres
          POSTGRES_USER: postgres
        ports:
          - 5432:5432
        # Set health checks to wait until postgres has started
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
          -v /var/run/postgresql/:/var/run/postgresql
    steps:
      - name: Create database
        run: sudo -u postgres createdb hub_test
      - uses: actions/checkout@v3
      - uses: volta-cli/action@v4
      - uses: ./.github/actions/setup-node-modules-cache
        with:
          yarn_lock_md5: ${{ hashFiles('yarn.lock') }}

      - run: yarn --prefer-offline --frozen-lockfile
      - run: yarn db:test-init
        working-directory: packages/hub
      - run: yarn run npm-run-all --aggregate-output --continue-on-error --parallel test:did-resolver test:hub

  test_boxel_and_web_client:
    name: web-client Build/Lint/Test
    needs: lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: volta-cli/action@v4
      - uses: ./.github/actions/setup-node-modules-cache
        with:
          yarn_lock_md5: ${{ hashFiles('yarn.lock') }}

      - run: yarn --prefer-offline --frozen-lockfile
      - name: Run boxel tests
        env:
          PERCY_TOKEN: ${{ secrets.PERCY_TOKEN_BOXEL }}
        run: yarn test:boxel:percy
      - name: Run ember-helper tests
        run: yarn test:ember-shared
      # using yarn to install @percy/cli suddenly started causing V8 out of
      # memory errors. According to https://stackoverflow.com/a/56568741 likely
      # there is a dependency cycle that yarn can't see through. However, npm
      # has the ability to collapse these cycles. So we are using npm to install
      # percy
      - run: npm install -g @percy/cli
      - name: Run web client tests
        env:
          PERCY_TOKEN: ${{ secrets.PERCY_TOKEN_WEB_CLIENT }}
        run: yarn test:web-client:percy
      - name: Run ssr-web tests
        env:
          PERCY_TOKEN: ${{ secrets.PERCY_TOKEN_SSR_WEB }}
        run: yarn test:ssr-web:percy
      - name: Publish web-client test results
        uses: EnricoMi/publish-unit-test-result-action@v2
        if: always()
        with:
          check_name: "web-client test results"
          files: ci-xml-test-results/web-client.xml
      - name: Publish ssr-web test results
        uses: EnricoMi/publish-unit-test-result-action@v2
        if: always()
        with:
          check_name: "ssr-web test results"
          files: ci-xml-test-results/ssr-web.xml

  change_check:
    name: Check which packages changed
    needs: [test_all_but_web_client, test_boxel_and_web_client]
    runs-on: ubuntu-latest
    outputs:
      hub: ${{ steps.filter.outputs.hub }}
      web_client: ${{ steps.filter.outputs.web_client }}
      boxel: ${{ steps.filter.outputs.boxel }}
      ember-shared: ${{ steps.filter.outputs.ember-shared }}
      cardie: ${{ steps.filter.outputs.cardie }}
      ssr_web: ${{ steps.filter.outputs.ssr_web }}
      safe-tools-client: ${{ steps.filter.outputs.safe-tools-client }}
    steps:
      - uses: actions/checkout@v3
      - uses: dorny/paths-filter@v2
        id: filter
        with:
          filters: |
            hub:
              - 'packages/hub/**'
              - 'packages/did-resolver/**'
              - 'packages/discord-bot/**'
              - 'packages/cardpay-sdk/**'
              - 'packages/did-resolver/**'
              - '.github/workflows/push-main.yml'
              - '.github/actions/deploy-hub/**'
              - 'yarn.lock'
              - 'waypoint.hcl'
            web_client:
              - 'packages/web-client/**'
              - 'packages/boxel/**'
              - 'packages/ember-shared/**'
              - 'packages/cardpay-sdk/**'
              - 'packages/did-resolver/**'
              - '.github/workflows/push-main.yml'
              - '.github/actions/deploy-web-client/**'
              - 'yarn.lock'
            boxel:
              - 'packages/boxel/**'
              - '.github/workflows/push-main.yml'
              - 'yarn.lock'
            cardie:
              - 'packages/cardie/**'
              - '.github/workflows/push-main.yml'
              - 'yarn.lock'
              - 'waypoint.hcl'
            ssr_web:
              - 'packages/ssr-web/**'
              - 'packages/boxel/**'
              - 'packages/cardpay-sdk/**'
              - 'packages/did-resolver/**'
              - '.github/workflows/push-main.yml'
              - '.github/actions/deploy-ssr-web/**'
              - 'yarn.lock'
              - 'waypoint.hcl'
            safe-tools-client:
              - 'packages/safe-tools-client/**'
              - 'packages/boxel/**'
              - 'packages/ember-shared/**'
              - '.github/workflows/push-main.yml'
              - '.github/actions/deploy-safe-tools-client/**'
              - 'yarn.lock'

  build-hub-staging:
    name: Build hub
    needs: change_check
    if: ${{ needs.change_check.outputs.hub == 'true' }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: volta-cli/action@v4
      - uses: ./.github/actions/setup-node-modules-cache
        with:
          yarn_lock_md5: ${{ hashFiles('yarn.lock') }}

      - name: Install dependencies
        run: yarn --prefer-offline --frozen-lockfile
      - name: Build
        run: yarn build
        working-directory: packages/hub
      - name: Tar artifact
        run: tar -cvf artifact.tar packages/hub/dist
      - uses: actions/upload-artifact@v3
        with:
          name: hub-${{ github.sha }}
          path: artifact.tar

  deploy-hub-staging:
    name: Deploy hub to staging cluster via waypoint
    needs: build-hub-staging
    if: ${{ needs.change_check.outputs.hub == 'true' }}
    runs-on: ubuntu-latest
    strategy:
      matrix:
        app: [hub, hub-worker, hub-event-listener]
        include:
          - retain: "0"
          - retain: "1"
            app: hub
    steps:
      - uses: actions/checkout@v3
      - uses: ./.github/actions/setup-node-modules-cache
        with:
          yarn_lock_md5: ${{ hashFiles('yarn.lock') }}

      - uses: actions/download-artifact@v3
        with:
          name: hub-${{ github.sha }}
      - name: Extract artifact
        run: tar -xvf artifact.tar
      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          role-to-assume: arn:aws:iam::680542703984:role/waypoint
          aws-region: us-east-1
      - name: Deploy ${{ matrix.app }}
        uses: ./.github/actions/waypoint-deploy
        with:
          app: ${{ matrix.app }}
          retain: ${{ matrix.retain }}
          environment: staging
          discord_webhook: ${{ secrets.DISCORD_WEBHOOK }}
        env:
          WAYPOINT_SERVER_TOKEN: ${{ secrets.STAGING_WAYPOINT_SERVER_TOKEN }}
          WAYPOINT_SERVER_ADDR: ${{ secrets.STAGING_WAYPOINT_SERVER_ADDR }}

  deploy-web-client-staging:
    name: Deploy web-client to S3 staging bucket
    needs: change_check
    if: ${{ needs.change_check.outputs.web_client == 'true' }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: ./.github/actions/setup-node-modules-cache
        with:
          yarn_lock_md5: ${{ hashFiles('yarn.lock') }}

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          role-to-assume: arn:aws:iam::680542703984:role/web-client
          aws-region: us-east-1
      - name: Deploy web-client
        uses: ./.github/actions/deploy-web-client
        env:
          HUB_URL: https://hub-staging.stack.cards
          SENTRY_AUTH_TOKEN: ${{ secrets.WEB_CLIENT_SENTRY_AUTH_TOKEN }}
          SENTRY_DSN: ${{ secrets.WEB_CLIENT_SENTRY_DSN }}
        with:
          environment: staging
          discord_webhook: ${{ secrets.DISCORD_WEBHOOK }}

  deploy-ssr-web-staging:
    name: Deploy ssr-web
    needs: change_check
    if: ${{ needs.change_check.outputs.ssr_web == 'true' }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: volta-cli/action@v4
      - uses: ./.github/actions/setup-node-modules-cache
        with:
          yarn_lock_md5: ${{ hashFiles('yarn.lock') }}

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          role-to-assume: arn:aws:iam::680542703984:role/waypoint
          aws-region: us-east-1
      - name: Deploy ssr-web
        uses: ./.github/actions/deploy-ssr-web
        env:
          HUB_URL: https://hub-staging.stack.cards
          SENTRY_DSN: ${{ secrets.SSR_WEB_CLIENT_SENTRY_DSN }}
          WAYPOINT_SERVER_TOKEN: ${{ secrets.STAGING_WAYPOINT_SERVER_TOKEN }}
          WAYPOINT_SERVER_ADDR: ${{ secrets.STAGING_WAYPOINT_SERVER_ADDR }}
        with:
          environment: staging
          discord_webhook: ${{ secrets.DISCORD_WEBHOOK }}

  deploy-boxel:
    name: Deploy boxel to S3 bucket
    needs: change_check
    if: ${{ needs.change_check.outputs.boxel == 'true' }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: volta-cli/action@v4
      - uses: ./.github/actions/setup-node-modules-cache
        with:
          yarn_lock_md5: ${{ hashFiles('yarn.lock') }}

      - run: yarn --prefer-offline --frozen-lockfile
      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          role-to-assume: arn:aws:iam::680542703984:role/boxel
          aws-region: us-east-1
      - name: Deploy preview
        run: yarn deploy:boxel
        env:
          S3_PREVIEW_INDEX_BUCKET_NAME: boxel-preview.cardstack.com
          S3_PREVIEW_ASSET_BUCKET_NAME: boxel-preview-assets.cardstack.com
          S3_PREVIEW_ASSET_BUCKET_ENDPOINT: https://s3.us-east-1.amazonaws.com/boxel-preview-assets.cardstack.com
          S3_PREVIEW_REGION: us-east-1
      - name: Send notification to Discord
        if: ${{ always() }}
        uses: ./.github/actions/discord-notification-deploy
        with:
          app: boxel
          status: ${{ job.status }}
          environment: staging
          webhook: ${{ secrets.DISCORD_WEBHOOK }}

  deploy-cardie:
    name: Deploy cardie via waypoint
    needs: change_check
    if: ${{ needs.change_check.outputs.cardie == 'true' }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: volta-cli/action@v4
      - uses: ./.github/actions/setup-node-modules-cache
        with:
          yarn_lock_md5: ${{ hashFiles('yarn.lock') }}

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          role-to-assume: arn:aws:iam::680542703984:role/waypoint
          aws-region: us-east-1
      - name: Deploy cardie
        uses: ./.github/actions/waypoint-deploy
        with:
          app: cardie
          retain: "0"
          environment: staging
          discord_webhook: ${{ secrets.DISCORD_WEBHOOK }}
        env:
          WAYPOINT_SERVER_TOKEN: ${{ secrets.STAGING_WAYPOINT_SERVER_TOKEN }}
          WAYPOINT_SERVER_ADDR: ${{ secrets.STAGING_WAYPOINT_SERVER_ADDR }}

  deploy-safe-tools-client:
    needs: change_check
    if: ${{ needs.change_check.outputs.safe-tools-client == 'true' }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - uses: ./.github/actions/setup-node-modules-cache
        with:
          yarn_lock_md5: ${{ hashFiles('yarn.lock') }}


      - name: Deploy safe-tools-client
        uses: ./.github/actions/deploy-safe-tools-client
        with:
          environment: staging
          discord_webhook: ${{ secrets.DISCORD_WEBHOOK }}

<MSG> updating heap size in push-main script too

<DFF> @@ -8,7 +8,10 @@ jobs:
   lint:
     name: Lint All
     runs-on: ubuntu-latest
-
+    env:
+      # we are running into heap out of memory issues with the linting--so
+      # increasing the heap size to 8GB
+      NODE_OPTIONS: --max-old-space-size=8192
     steps:
       - uses: actions/checkout@v2
         with:

{'addition_count': 4, 'commit_subject': 'updating heap size in push-main script too', 'deletion_count': 1, 'file_extension': '.yml', 'lang': 'github/workflows/push-main', 'license': 'mit', 'repo_name': 'cardstack/cardstack'}