From c0209908f6a4e85cd661e6e8914eaf503d29dd81 Mon Sep 17 00:00:00 2001 From: Alan Lu Date: Tue, 5 Mar 2024 03:01:40 +0800 Subject: [PATCH] ci: update ci workflow --- .github/workflows/ci.yml | 139 +++++++++++++++------------------------ package.json | 4 +- turbo.json | 3 +- 3 files changed, 59 insertions(+), 87 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 44175c3..bdb3876 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,120 +5,89 @@ on: - pull_request jobs: - build: - name: Build + lint: + timeout-minutes: 10 + name: "Lint" runs-on: ubuntu-latest - steps: - name: Checkout uses: actions/checkout@v4 - - name: Use Node.js 20.x - uses: actions/setup-node@v4 - with: - node-version: 20.x - - name: Install pnpm uses: pnpm/action-setup@v3 with: version: 8 - run_install: false - - - name: Get pnpm store directory - shell: bash - run: | - echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV - - - name: Setup pnpm cache - uses: actions/cache@v4 - with: - path: ${{ env.STORE_PATH }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- - - - name: Install dependencies - run: pnpm install --frozen-lockfile - - - name: Build packages - run: pnpm run build - - lint: - name: Lint - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Use Node.js 20.x + - name: Use Node.js 20 uses: actions/setup-node@v4 with: - node-version: 20.x + node-version: 20 + cache: "pnpm" - - name: Install pnpm - uses: pnpm/action-setup@v3 - with: - version: 8 - run_install: false - - - name: Get pnpm store directory - shell: bash - run: | - echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + - name: Install deps + run: pnpm install - - name: Setup pnpm cache - uses: actions/cache@v4 - with: - path: ${{ env.STORE_PATH }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- + - name: Build + run: pnpm run build - - name: Install dependencies - run: pnpm install --frozen-lockfile + - name: Lint + run: pnpm run lint - - name: Lint code - run: npx turbo lint + - name: TypeCheck + run: pnpm run typecheck test: - name: Test - runs-on: ubuntu-latest - + timeout-minutes: 20 + runs-on: ${{ matrix.os }} strategy: matrix: - node-version: ['18.x', '20.x'] - + os: [ubuntu-latest] + node_version: [18, 20] + include: + # Active LTS + other OS + - os: macos-latest + node_version: 20 + - os: windows-latest + node_version: 20 + fail-fast: false + + name: "Build & Test: node-${{ matrix.node_version }}, ${{ matrix.os }}" steps: - name: Checkout uses: actions/checkout@v4 + with: + # Assume PRs are less than 50 commits + fetch-depth: 50 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v4 + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v42.0.5 with: - node-version: ${{ matrix.node-version }} + files: | + docs/** + .github/** + !.github/workflows/ci.yml + **.md - name: Install pnpm + if: steps.changed-files.outputs.only_changed != 'true' uses: pnpm/action-setup@v3 - with: - version: 8 - run_install: false - - name: Get pnpm store directory - shell: bash - run: | - echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV - - - name: Setup pnpm cache - uses: actions/cache@v4 + - name: Set node version to ${{ matrix.node_version }} + if: steps.changed-files.outputs.only_changed != 'true' + uses: actions/setup-node@v4 with: - path: ${{ env.STORE_PATH }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- + node-version: ${{ matrix.node_version }} + cache: "pnpm" - - name: Install dependencies - run: pnpm install --frozen-lockfile + - name: Install deps + if: steps.changed-files.outputs.only_changed != 'true' + run: pnpm install + + - name: Build + if: steps.changed-files.outputs.only_changed != 'true' + run: pnpm run build - - name: Run tests - run: npx turbo test + - name: Test unit + if: steps.changed-files.outputs.only_changed != 'true' + run: pnpm run test diff --git a/package.json b/package.json index 90a467b..b7377e8 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "name": "@alanlu-dev/web-kit", + "type": "module", "private": true, "packageManager": "pnpm@8.15.4", "description": "A monorepo starter template", @@ -23,9 +24,10 @@ "modules:clean": "npx rimraf --glob ./**/node_modules && rm -rf pnpm-lock.yaml", "pnpm:clean": "pnpm store prune", "build": "turbo run build", - "check": "turbo run test lint --parallel", + "check": "turbo run test lint typecheck --parallel", "test": "turbo run test", "lint": "turbo run lint", + "typecheck": "turbo run typecheck", "nuxt-demo": "pnpm --filter=@alanlu-dev/nuxt-demo", "commit": "czg", "changeset": "changeset", diff --git a/turbo.json b/turbo.json index 6b37681..9e7814f 100644 --- a/turbo.json +++ b/turbo.json @@ -16,6 +16,7 @@ "outputs": ["coverage/**"], "inputs": ["src/**/*.tsx", "src/**/*.ts", "test/**/*.ts", "test/**/*.tsx"] }, - "lint": {} + "lint": {}, + "typecheck": {} } }