From 72c642a53adb3d5964d061029c7e557f8dc5b049 Mon Sep 17 00:00:00 2001 From: Tine Kondo Date: Fri, 15 Mar 2024 07:56:56 +0000 Subject: [PATCH] chore(ci): setup nx agents and improve other CI workflows --- .github/actions/setup/action.yml | 52 +++++++++++++++++++++++ .github/workflows/ci.yml | 37 ++++++++++++++++ .github/workflows/run-e2e-tests.yml | 61 --------------------------- .github/workflows/run-smoke-tests.yml | 48 --------------------- .github/workflows/run-unit-tests.yml | 33 --------------- .github/workflows/smoke-tests.yml | 35 +++++++++++++++ nx.json | 2 +- 7 files changed, 125 insertions(+), 143 deletions(-) create mode 100644 .github/actions/setup/action.yml create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/run-e2e-tests.yml delete mode 100644 .github/workflows/run-smoke-tests.yml delete mode 100644 .github/workflows/run-unit-tests.yml create mode 100644 .github/workflows/smoke-tests.yml diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml new file mode 100644 index 00000000..115ba578 --- /dev/null +++ b/.github/actions/setup/action.yml @@ -0,0 +1,52 @@ +name: 'Setup Build Tools and Dependencies' +description: Setup node, pnpm, java, flutter, cache, and install dependencies + +inputs: + node-version: # id of input + description: 'Node version' + required: false + default: 20 + +runs: + using: 'composite' + steps: + - name: Derive appropriate SHAs for base and head for `nx affected` commands + uses: nrwl/nx-set-shas@v4 + + - name: Setup PNPM + uses: pnpm/action-setup@v2 + with: + version: 8.2 + + - name: Setup Node.js ${{ inputs.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node-version }} + cache: 'pnpm' + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: 17 + + - name: Setup Flutter + uses: subosito/flutter-action@v2 + with: + channel: 'stable' + cache: true + cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:' # optional, change this to force refresh cache + cache-path: '${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:' # optional, change this to specify the cache path + architecture: x64 # optional, x64 or arm64 + + - name: Cache node_modules + id: cache-modules + uses: actions/cache@v4 + with: + lookup-only: true + path: '**/node_modules' + key: pnpm-${{ hashFiles('pnpm-lock.yaml') }} + + - name: Install packages + run: pnpm install --frozen-lockfile + shell: bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..7381901a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,37 @@ +name: CI + +on: + push: + branches: + - develop + pull_request: + +# Needed for nx-set-shas when run on the main branch +permissions: + actions: read + contents: read + +jobs: + develop: + runs-on: ubuntu-latest + env: + NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} + timeout-minutes: 60 + steps: + - name: Checkout Repo + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + # Connect your workspace on nx.app and uncomment this to enable task distribution. + # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "e2e" targets have been requested + - run: pnpm exec nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="e2e-ci" + + - name: Setup node, pnpm, java, flutter, cache, and install dependencies + uses: ./.github/actions/setup + + # This line is needed for nx affected to work when CI is running on a PR + - run: git branch --track develop origin/develop + + - run: pnpm exec nx-cloud record -- nx format:check + - run: pnpm exec nx affected -t lint test build e2e-ci --exclude=smoke --codeCoverage diff --git a/.github/workflows/run-e2e-tests.yml b/.github/workflows/run-e2e-tests.yml deleted file mode 100644 index 93cfe588..00000000 --- a/.github/workflows/run-e2e-tests.yml +++ /dev/null @@ -1,61 +0,0 @@ -name: Run e2e Tests - -on: - push: - branches: [develop] - pull_request: - branches: [develop] -concurrency: - group: ${{ github.workflow }}-${{ github.event.number || github.ref }} - cancel-in-progress: true -jobs: - run_e2e: - name: Run e2e Tests - runs-on: ${{ matrix.os }} - timeout-minutes: 60 - strategy: - matrix: - os: [ubuntu-latest] - node-version: [18] - env: - NX_BRANCH: ${{ github.event.number || github.ref }} - NX_RUN_GROUP: ${{ github.run_id }} - steps: - - name: Checkout Repo - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Derive appropriate SHAs for base and head for `nx affected` commands - uses: nrwl/nx-set-shas@v3 - with: - main-branch-name: 'develop' - - - run: | - echo "BASE: ${{ env.NX_BASE }}" - echo "HEAD: ${{ env.NX_HEAD }}" - - - name: Use Java - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: 17 - - - name: Use Flutter - uses: subosito/flutter-action@v2 - with: - channel: 'stable' - cache: true - cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:' # optional, change this to force refresh cache - cache-path: '${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:' # optional, change this to specify the cache path - architecture: x64 # optional, x64 or arm64 - - - name: Install node, pnpm, and dependencies - uses: ./.github/actions/install-dependencies - - - name: Run e2e tests - env: - NX_E2E_CI_CACHE_KEY: e2e-gha-${{ matrix.os }}-${{ matrix.node-version }} - NX_RUN_GROUP: ${{ github.run_id }}-${{ matrix.os }}-${{ matrix.node-version }} - run: | - pnpm e2e diff --git a/.github/workflows/run-smoke-tests.yml b/.github/workflows/run-smoke-tests.yml deleted file mode 100644 index 836ad1ca..00000000 --- a/.github/workflows/run-smoke-tests.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: Nightly Smoke Tests - -on: - # Trigger manually or on schedule - workflow_dispatch: - schedule: - - cron: '0 0 * * *' - -jobs: - run_smoke_tests: - name: Run Smoke Tests - runs-on: ${{ matrix.os }} - timeout-minutes: 60 - strategy: - matrix: - os: [ubuntu-latest, macos-latest] - node-version: [18] - steps: - - name: Checkout Repo - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Use Java - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: 17 - - - name: Use Flutter - uses: subosito/flutter-action@v2 - with: - channel: 'stable' - cache: true - cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:' # optional, change this to force refresh cache - cache-path: '${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:' # optional, change this to specify the cache path - architecture: x64 # optional, x64 or arm64 - - - name: Install node, pnpm, and dependencies - uses: ./.github/actions/install-dependencies - with: - node-version: ${{ matrix.node-version }} - - - name: Run smoke tests - env: - NX_E2E_CI_CACHE_KEY: smoke-gha-${{ matrix.os }}-${{ matrix.node-version }} - NX_RUN_GROUP: ${{ github.run_id }}-${{ matrix.os }}-${{ matrix.node-version }} - run: pnpm nx test smoke --verbose diff --git a/.github/workflows/run-unit-tests.yml b/.github/workflows/run-unit-tests.yml deleted file mode 100644 index 5a85da49..00000000 --- a/.github/workflows/run-unit-tests.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Run Unit Tests - -on: - push: - branches: [develop] - pull_request: - branches: [develop] - -jobs: - run_unit: - name: Run Unit Tests - runs-on: ${{ matrix.os }} - timeout-minutes: 60 - strategy: - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - node-version: [18] - env: - NX_BRANCH: ${{ github.event.number }} - NX_RUN_GROUP: ${{ github.run_id }} - steps: - - name: Checkout Repo - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Install node, pnpm, and dependencies - uses: ./.github/actions/install-dependencies - with: - node-version: ${{ matrix.node-version }} - - - name: Run unit tests - run: pnpm run affected:test --base=origin/develop --parallel=6 --exclude=smoke --verbose --codeCoverage diff --git a/.github/workflows/smoke-tests.yml b/.github/workflows/smoke-tests.yml new file mode 100644 index 00000000..d73f2ab2 --- /dev/null +++ b/.github/workflows/smoke-tests.yml @@ -0,0 +1,35 @@ +name: Nightly Smoke Tests + +on: + # Trigger manually or on schedule + workflow_dispatch: + schedule: + - cron: '0 0 * * *' + +jobs: + run_smoke_tests: + name: Smoke Tests + runs-on: ${{ matrix.os }} + env: + NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} + timeout-minutes: 60 + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + node-version: [20] + steps: + - name: Checkout Repo + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup node, pnpm, java, flutter, and dependencies + uses: ./.github/actions/setup + with: + node-version: ${{ matrix.node-version }} + + - name: Run smoke tests + env: + NX_E2E_CI_CACHE_KEY: smoke-gha-${{ matrix.os }}-${{ matrix.node-version }} + NX_RUN_GROUP: ${{ github.run_id }}-${{ matrix.os }}-${{ matrix.node-version }} + run: pnpm nx test smoke --verbose diff --git a/nx.json b/nx.json index 001d5e37..a17646d6 100644 --- a/nx.json +++ b/nx.json @@ -80,7 +80,7 @@ "!{projectRoot}/src/test-setup.[jt]s" ] }, - "nxCloudAccessToken": "OTMwZTE2ZDgtODg2NS00Y2M1LTg0OTMtNGU3ZmI0NzY4YTUyfHJlYWQtd3JpdGU=", + "nxCloudAccessToken": "ZDRmZDczZWUtMDU2My00YzQ0LTlkMWEtZjM2YjZlZWNmNGIxfHJlYWQ=", "parallel": 1, "plugins": [] }