bemusic/bemuse

View on GitHub
.github/workflows/ci.yml

Summary

Maintainability
Test Coverage
name: CI

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
  workflow_dispatch:

env:
  NODE_FLAGS: --max_old_space_size=4096

concurrency:
  group: ci-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v3
      - name: Set up project
        uses: ./.github/actions/setup-project
      - name: Build
        run: |
          rm -rf dist
          node build-scripts build
        env:
          SCOREBOARD_SERVER: ${{ secrets.SCOREBOARD_SERVER }}
      - name: Compress build output
        if: always()
        run: tar -cvzf dist.tar.gz dist
      - name: Checks
        run: node build-scripts pre-deploy
      - name: Release
        if: github.event_name == 'push'
        id: release
        run: |
          node build-scripts release --confirm
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Upload artifact
        if: always()
        uses: actions/upload-artifact@v3
        with:
          name: bemuse-build-${{ github.sha }}
          path: dist.tar.gz
    outputs:
      released-tag: ${{ steps.release.outputs.tag }}
  deploy:
    uses: ./.github/workflows/deploy-production.yml
    needs: build
    secrets: inherit
    if: needs.build.outputs.released-tag
    with:
      tag: ${{ needs.build.outputs.released-tag }}
  e2e:
    runs-on: ubuntu-latest
    needs: build
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v3
      - name: Set up project
        uses: ./.github/actions/setup-project
      - name: Download build
        uses: actions/download-artifact@v3
        with:
          name: bemuse-build-${{ github.sha }}
          path: '.'
      - name: Extract build
        run: tar -xvzf dist.tar.gz
      - name: Install browsers
        run: |
          cd e2e
          npx playwright install --with-deps
      - name: Run E2E tests
        run: |
          cd e2e
          npx playwright test
      - name: Upload test report
        uses: actions/upload-artifact@v3
        if: always()
        with:
          name: playwright-report
          path: e2e/playwright-report
  typecheck:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Set up project
        uses: ./.github/actions/setup-project
      - name: Build dependencies
        run: node common/scripts/install-run-rush.js build --to-except bemuse
      - name: Typecheck
        run: node ../common/scripts/install-run-rushx.js typecheck
        working-directory: bemuse
  tidy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Set up project
        uses: ./.github/actions/setup-project
      - name: Build
        run: node common/scripts/install-run-rush.js build --to-except bemuse
      - name: Lint and fix all auto-fixable problems
        run: node common/scripts/install-run-rush.js lint --fix --verbose
        if: always()
      - name: Make sure all source files are formatted using Prettier
        run: node common/scripts/install-run-rush.js format-all
        if: always()
      - name: Semgrep
        uses: ./.github/actions/semgrep
        if: always()
      - name: Format README file
        run: node common/scripts/install-run-rush.js format-readme
        if: always()
      - run: git add --update
        if: always()
      - uses: dtinth/patch-generator-action@main
        if: always()
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Set up project
        uses: ./.github/actions/setup-project
      - name: Build
        run: node common/scripts/install-run-rush.js build --to-except bemuse
      - name: Test
        run: node ../common/scripts/install-run-rushx.js test
        working-directory: bemuse
      - uses: codecov/codecov-action@v2
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
  test_packages:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Set up project
        uses: ./.github/actions/setup-project
      - name: Build
        run: node common/scripts/install-run-rush.js build --to-except bemuse
      - name: Test Packages
        run: node common/scripts/install-run-rush.js test --to-except bemuse
      - uses: codecov/codecov-action@v2
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
  changelog:
    runs-on: ubuntu-latest
    if: github.event_name == 'pull_request'
    env:
      AUTHOR: ${{ github.event.pull_request.user.login }}
      PR: ${{ github.event.pull_request.number }}
      PR_NEW_FILE_URL:
        https://github.com/${{ github.event.pull_request.head.repo.full_name
        }}/new/${{ github.event.pull_request.head.ref }}
    steps:
      - name: Generate changelog file
        uses: actions/github-script@v6
        with:
          script: |
            const path = `changelog/pr-${process.env.PR}.md`
            const contents = [
              '---',
              'author: ' + process.env.AUTHOR,
              'category: feature/internals/bugfix/improvement',
              'type: major/minor/patch',
              'pr: ' + process.env.PR,
              '---',
              '',
              '(Write your changelog entry here)',
            ].join('\n')
            const url = `${process.env.PR_NEW_FILE_URL}?filename=${encodeURIComponent(path)}&value=${encodeURIComponent(contents)}`
            const summary = `[Click here to create a changelog entry.](${url})`
            require('fs').appendFileSync(process.env.GITHUB_STEP_SUMMARY, summary)
            console.log('To create a changelog entry, create a file at', path)
            console.log('')
            console.log('Example contents:')
            console.log('')
            console.log(contents)
            console.log('')
            console.log(url)