belgattitude/httpx

View on GitHub
.github/workflows/ci-packages.yml

Summary

Maintainability
Test Coverage
name: CI-packages

on:
  push:
    branches:
     - main
  pull_request:
    types: [opened, synchronize, reopened, ready_for_review]
    branches:
      - '**'

permissions:
  contents: read

jobs:
  test-packages:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [18.x, 20.x, 22.x]
    env:
      NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
    steps:
      - uses: actions/checkout@v4
        with:
          # Fetch all git history so that yarn workspaces --since can compare with the correct commits
          # @link https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches
          fetch-depth: 0

      - name: โš™๏ธ Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}

      - name: ๐Ÿ“ฅ Monorepo install
        uses: ./.github/actions/yarn-nm-install

      - name: โš™๏ธ Nx setup - SHAs for base and head for `nx affected` commands
        id: nx-set-shas
        uses: nrwl/nx-set-shas@v4

      - run: |
          echo "BASE: ${{ steps.nx-set-shas.outputs.base }}"
          echo "HEAD: ${{ steps.nx-set-shas.outputs.head }}"

      - name: Cache rotation keys
        id: cache-rotation
        shell: bash
        run: |
          echo "YEAR_MONTH=$(/bin/date -u "+%Y%m")" >> $GITHUB_OUTPUT

      - name: โ™ป๏ธ Restore packages cache
        uses: actions/cache@v4
        with:
          path: |
            ${{ github.workspace }}/.cache
          key: ${{ runner.os }}-packages-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-${{ hashFiles('yarn.lock') }}-${{ hashFiles('packages/**.[jt]sx?', 'integrations/**.[jt]sx?') }}
          restore-keys: |
            ${{ runner.os }}-packages-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-${{ hashFiles('yarn.lock') }}-

      - name: ๐Ÿ•ต๏ธ Typecheck
        if: matrix.node-version == '20.x'
        run: yarn nx run-many --target=typecheck --exclude='examples/**' --exclude='docs'

      - name: ๐Ÿ”ฌ ESLint checks
        if: matrix.node-version == '20.x'
        run: yarn nx run-many --target=lint --exclude='examples/**' --exclude='docs'

      - name: ๐Ÿงช Unit tests (no-coverage - node !== 20.x)
        if: matrix.node-version != '20.x'
        run: yarn nx run-many --target=test-unit --exclude='examples/**' --exclude='docs'

      - name: ๐Ÿงช Unit tests (coverage - only node 20.x)
        if: matrix.node-version == '20.x'
        run: yarn nx run-many --target=test-unit-coverage --exclude='examples/**' --exclude='docs'

      #- name: โ˜‚๏ธ Codecov upload (only node-20)
      #  if: matrix.node-version == '20.x'
      #  working-directory: ${{ github.workspace }}
      #  run: |
      #    bash .github/scripts/install-codecov.sh
      #    yarn g:ci-coverage-upload
      #  shell: bash
      #  env:
      #    CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

      - name: โ˜‚๏ธ Codecov upload (only node-20)
        uses: codecov/codecov-action@v4
        if: matrix.node-version == '20.x'
        with:
          fail_ci_if_error: true # optional (default = false)
          #files: ./coverage1.xml,./coverage2.xml # optional
          #flags: unittests # optional
          flags: httpx-exception-unit,httpx-dsn-parser-unit,httpx-memo-intl-unit,httpx-plain-object-unit,httpx-assert-unit,httpx-json-api-unit,httpx-treeu-unit
          #name: codecov-umbrella # optional
          verbose: true # optional (default = false)
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

      - name: ๐Ÿงช Unit tests (edge-runtime)
        if: matrix.node-version == '20.x'
        run: yarn nx run-many --target=test-unit-edge --exclude='examples/**' --exclude='docs'

      - name: ๐Ÿงช Unit tests (cloudflare - only node 20.x)
        if: matrix.node-version == '20.x'
        run: yarn nx run-many --target=test-unit-cloudflare --exclude='examples/**' --exclude='docs'

      - name: โš™๏ธ Install Playwright Chrome (only node 20.x)
        if: matrix.node-version == '20.x'
        run: yarn playwright install chrome

      # @todo make this working
      #- name: ๐Ÿงช Unit tests (playwright chrome - only node 20.x)
      #  if: matrix.node-version == '20.x'
      #  run: yarn nx run-many --target=test-unit-browser --exclude='examples/**' --exclude='docs'

      - name: ๐Ÿ— Build packages
        run: yarn nx run-many --target=build --exclude='examples/**' --exclude='docs'

      - name: ๐Ÿ“ Check build for size-limits
        if: matrix.node-version == '20.x'
        run: yarn nx run-many --target=check-size --exclude='examples/**' --exclude='docs'

      - name: ๐Ÿ›Ÿ Check build for ecmascript compliance
        if: matrix.node-version == '20.x'
        run: yarn nx run-many --target=check-dist --exclude='examples/**' --exclude='docs'

      - name: ๐Ÿ›Ÿ Check publishable dist (arethetypeswrong)
        if: matrix.node-version == '20.x'
        run: yarn nx run-many --target=check-pub --exclude='examples/**' --exclude='docs'

      - name: ๐Ÿ“„ Check doc can be built
        if: matrix.node-version == '20.x'
        run: yarn nx run-many --target=docgen --exclude='examples/**' --exclude='docs'