From 68a65f8c563de44928b597d1f2e7c659e4ce004f Mon Sep 17 00:00:00 2001 From: lingbopro Date: Mon, 20 Jan 2025 20:47:12 +0800 Subject: [PATCH] ci: add test workflow --- .../workflows/{build.yaml => build-test.yaml} | 9 +- .github/workflows/reusable-test.yaml | 89 +++++++++++++++++++ 2 files changed, 97 insertions(+), 1 deletion(-) rename .github/workflows/{build.yaml => build-test.yaml} (58%) create mode 100644 .github/workflows/reusable-test.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build-test.yaml similarity index 58% rename from .github/workflows/build.yaml rename to .github/workflows/build-test.yaml index 62899e2..659a921 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build-test.yaml @@ -1,4 +1,4 @@ -name: Build +name: Build + Test on: push: @@ -14,3 +14,10 @@ jobs: build: name: Build uses: ./.github/workflows/reusable-build.yaml + test: + name: Test + needs: build + uses: ./.github/workflows/reusable-test.yaml + with: + result-artifact-url: ${{ needs.build.outputs.artifact-url }} + run-coverage: true diff --git a/.github/workflows/reusable-test.yaml b/.github/workflows/reusable-test.yaml new file mode 100644 index 0000000..a0b7021 --- /dev/null +++ b/.github/workflows/reusable-test.yaml @@ -0,0 +1,89 @@ +name: Test (reusable) + +on: + workflow_call: + inputs: + node-version: + description: 'Node.js version' + type: string + required: false + default: 22.x + pnpm-version: + description: 'pnpm version' + type: string + required: false + default: 9.12.3 + result-artifact-url: + description: 'Artifact URL of the build result (dist folder)' + type: string + required: true + run-coverage: + description: 'Run coverage tests' + type: boolean + required: false + default: false + outputs: + coverage-report-artifact-url: + description: Artifact URL of the coverage report + value: ${{ jobs.test-coverage.outputs.coverage-report-artifact-url }} + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up pnpm ${{ inputs.pnpm-version }} + uses: pnpm/action-setup@v4 + with: + version: ${{ inputs.pnpm-version }} + run_install: false + - name: Set up Node.js ${{ inputs.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node-version }} + cache: pnpm + - name: Install dependencies + run: pnpm install + - name: Download build result + uses: actions/download-artifact@v4 + with: + name: build-result + path: ./ + - name: Run tests + run: pnpm test + test-coverage: + name: Coverage test + runs-on: ubuntu-latest + if: ${{ inputs.run-coverage }} + outputs: + coverage-report-artifact-url: ${{ steps.upload-artifact.outputs.artifact-url }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up pnpm ${{ inputs.pnpm-version }} + uses: pnpm/action-setup@v4 + with: + version: ${{ inputs.pnpm-version }} + run_install: false + - name: Set up Node.js ${{ inputs.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node-version }} + cache: pnpm + - name: Install dependencies + run: pnpm install + - name: Download build result + uses: actions/download-artifact@v4 + with: + name: build-result + path: ./ + - name: Run coverage tests + run: pnpm test:coverage + - name: Upload coverage report + id: upload-artifact + uses: actions/upload-artifact@v4 + with: + name: coverage-report + path: ./coverage/lcov-report