name: Web
on:
  pull_request:
    paths:
      - "package.json"
      - "tsconfig.json"
      - "yarn.lock"
      - "packages/common/**"
      - "packages/ui/**"
      - "packages/web/**"
jobs:
  web:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2.1.0
        with:
          node-version: "14.4.0"
      - id: yarn-cache-path
        run: echo "::set-output name=dir::$(yarn cache dir)"
      - id: cache
        uses: actions/cache@master
        with:
          path: |
            node_modules
            */*/node_modules
            ${{ steps.yarn-cache-path.outputs.dir }}
          key: |
            yarn-v1-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            yarn-v1-${{ runner.os }}-
      - run: |
          yarn install --frozen-lockfile
      - run: |
          yarn run typescript
      - id: secrets
        uses: GoogleCloudPlatform/github-actions/get-secretmanager-secrets@master
        with:
          credentials: ${{ secrets.GCP_CREDENTIALS }}
          secrets: |-
            WEB_ENV:sentrei-master/web_${{ github.event.pull_request.base.ref }}_env
      - working-directory: packages/web
        run: |
          echo '::add-mask::${{ steps.secrets.outputs.WEB_ENV }}'
          echo '${{ steps.secrets.outputs.WEB_ENV }}' > .env
      - working-directory: packages/web
        run: |
          yarn run build
          yarn run cypress:install
          yarn run test
          yarn run analyze
          yarn run relative-ci
        env:
          FIREBASE_CLIENT_EMAIL: dummy
          FIREBASE_PRIVATE_KEY: dummys
          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
          RELATIVE_CI_KEY: ${{ secrets.RELATIVE_CI_KEY }}
          NODE_ENV: test
      - uses: codecov/codecov-action@v1.0.7
        continue-on-error: true
        with:
          file: packages/web/coverage/lcov.info
          name: sentrei
          fail_ci_if_error: true
          flags: web
