name: Repository CI on: pull_request: types: [opened, synchronize, reopened, ready_for_review] permissions: contents: read concurrency: group: '${{ github.workflow }}-${{ github.head_ref }}' cancel-in-progress: true jobs: changeset: name: Changeset runs-on: ubuntu-latest # The dependabot-changeset.yml workflow will trigger a new commit after # Dependabot updates, which will re-trigger this workflow. Other jobs below # depend on this job, and will be skipped too. If Dependabot updates non NPM # dependencies (Dockerfile, GitHub Actions), this workflow should not be # affected (build/verify/test are not using the docker images) and can be # skipped. Note that in case, dependabot-changeset.yml will not trigger a # new commit, so this workflow will not be re-triggered. This is expected. if: > github.event.pull_request.draft == false && github.event.sender.login != 'dependabot[bot]' steps: # Temporary until fixed runner images roll out: # https://github.com/actions/runner-images/issues/15018 - name: Update Ubuntu CA certificates run: | sudo apt-get update -qq sudo apt-get install --only-upgrade --no-install-recommends -y ca-certificates - uses: actions/checkout@v7 with: fetch-depth: 0 # needed for git diff against base branch - uses: pnpm/action-setup@v6 - uses: actions/setup-node@v7 with: cache: pnpm node-version-file: package.json - run: pnpm install --frozen-lockfile --ignore-scripts env: PUPPETEER_SKIP_DOWNLOAD: true - if: github.head_ref != 'changeset-release/main' run: pnpm changeset status --since=origin/${{ github.base_ref }} build: name: Build runs-on: ubuntu-latest # Ensure a changeset is present before we spend time building and testing. needs: changeset steps: # Temporary until fixed runner images roll out: # https://github.com/actions/runner-images/issues/15018 - name: Update Ubuntu CA certificates run: | sudo apt-get update -qq sudo apt-get install --only-upgrade --no-install-recommends -y ca-certificates - uses: actions/checkout@v7 - uses: pnpm/action-setup@v6 - uses: actions/setup-node@v7 with: cache: pnpm node-version-file: package.json - run: pnpm install --frozen-lockfile env: PUPPETEER_SKIP_DOWNLOAD: true # The "api" package generates its client with the legacy, slow `gen-api`. # Its `lex:gen` is mtime-guarded (only re-runs when some lexicon is newer # than ./src/client/index.ts), but on a clean checkout ./src/client is # absent, so it would always run. Cache it keyed on api's lexicon inputs # and, on a hit, bump ./src/client/index.ts past the just-checked-out # lexicon sources so the guard correctly reports nothing newer and skips # `gen-api`. `lex install --ci` does not re-touch the committed/fetched # lexicon files, so the guard stays satisfied through the build. - uses: actions/cache@v6 id: gen-api-cache with: path: packages/api/src/client key: gen-api-${{ hashFiles('packages/api/package.json', 'packages/api/lexicons.json', 'packages/lex-cli/src/**/*.ts') }} - if: steps.gen-api-cache.outputs.cache-hit == 'true' run: touch packages/api/src/client/index.ts - run: pnpm build - uses: actions/upload-artifact@v7 with: name: build-artifacts retention-days: 2 path: | packages/*/dist packages/*/*/dist packages/*/src/proto packages/*/src/lexicons packages/lex/*/src/lexicons packages/lex/*/tests/lexicons packages/oauth/*/src/lexicons packages/oauth/*/src/locales/*/messages.ts packages/api/src/client packages/api/src/moderation/const/labels.ts test: name: Test needs: build runs-on: ubuntu-22.04 # Puppeteer does not work in recent Ubuntu versions without a workaround due # to sandboxing issues. Using "ubuntu-latest" results in the following # error: # # No usable sandbox! If you are running on Ubuntu 23.10+ or another Linux # distro that has disabled unprivileged user namespaces with AppArmor, see # https://chromium.googlesource.com/chromium/src/+/main/docs/security/apparmor-userns-restrictions.md. # Otherwise see # https://chromium.googlesource.com/chromium/src/+/main/docs/linux/suid_sandbox_development.md # for more information on developing with the (older) SUID sandbox. If you # want to live dangerously and need an immediate workaround, you can try # using --no-sandbox. strategy: fail-fast: false matrix: shard: [1/8, 2/8, 3/8, 4/8, 5/8, 6/8, 7/8, 8/8] steps: # Temporary until fixed runner images roll out: # https://github.com/actions/runner-images/issues/15018 - name: Update Ubuntu CA certificates run: | sudo apt-get update -qq sudo apt-get install --only-upgrade --no-install-recommends -y ca-certificates - uses: actions/checkout@v7 - uses: pnpm/action-setup@v6 - uses: actions/setup-node@v7 with: cache: pnpm # @NOTE Keep tests on Node 22 for compatibility; 22.23.4 is the minimum # release containing the required security fixes. node-version: '^22.23.4' - run: echo "CURRENT_MONTH=$(date +'%Y-%m')" >> "$GITHUB_ENV" - uses: actions/cache@v6 name: Cache Puppeteer browser binaries with: path: ~/.cache/puppeteer key: ${{ env.CURRENT_MONTH }}-${{ runner.os }}-${{ runner.arch }} - run: pnpm install --frozen-lockfile - uses: actions/download-artifact@v8 with: name: build-artifacts path: packages - run: pnpm test:withFlags --maxWorkers=1 --shard=${{ matrix.shard }} --passWithNoTests verify: name: Verify needs: build runs-on: ubuntu-latest steps: # Temporary until fixed runner images roll out: # https://github.com/actions/runner-images/issues/15018 - name: Update Ubuntu CA certificates run: | sudo apt-get update -qq sudo apt-get install --only-upgrade --no-install-recommends -y ca-certificates - uses: actions/checkout@v7 - uses: pnpm/action-setup@v6 - uses: actions/setup-node@v7 with: cache: pnpm node-version-file: package.json - run: pnpm install --frozen-lockfile env: PUPPETEER_SKIP_DOWNLOAD: true - uses: actions/download-artifact@v8 with: name: build-artifacts path: packages - run: pnpm verify