From fe26544b5e446f51778d603ca0948392ddd43238 Mon Sep 17 00:00:00 2001 From: Yuri Date: Wed, 17 Jan 2024 13:18:59 +0100 Subject: [PATCH] Add github actions to build and run tests on pull requests --- .github/workflows/build-and-test.yml | 89 ++++++++++++++++++++++++++++ .github/workflows/pull-request.yml | 16 +++++ package.json | 1 + 3 files changed, 106 insertions(+) create mode 100644 .github/workflows/build-and-test.yml create mode 100644 .github/workflows/pull-request.yml diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 0000000..c8e04b4 --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,89 @@ +name: Build and test +on: + workflow_call: + workflow_dispatch: + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + + - uses: pnpm/action-setup@v2 + name: Install pnpm + with: + version: 8 + run_install: true + + - name: Lint code + run: pnpm format && bun lint:fix + + - uses: stefanzweifel/git-auto-commit-action@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + commit_message: 'chore: format' + commit_user_name: 'github-actions[bot]' + commit_user_email: 'github-actions[bot]@users.noreply.github.com' + + build: + name: Build + needs: lint + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - name: Clone repository + uses: actions/checkout@v4 + + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + + - uses: pnpm/action-setup@v2 + name: Install pnpm + with: + version: 8 + run_install: true + + - name: Build + run: pnpm run build + + test: + name: Test + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Clone repository + uses: actions/checkout@v4 + + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + + - uses: pnpm/action-setup@v2 + name: Install pnpm + with: + version: 8 + run_install: true + + - name: Build + run: pnpm run build + + - name: Run tests + uses: nick-fields/retry@v2 + with: + timeout_minutes: 10 + max_attempts: 3 + command: pnpm run test:ci diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 0000000..b66acac --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,16 @@ +name: Pull request +on: + pull_request: + types: [opened, reopened, synchronize, ready_for_review] + branches: + - '!rc' + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + verify: + name: Build and test + uses: ./.github/workflows/build-and-test.yml + secrets: inherit diff --git a/package.json b/package.json index 37d41cb..23e3b77 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "lint": "biome check .", "lint:fix": "pnpm lint --apply", "test": "vitest", + "test:ci": "CI=true vitest --coverage --retry=3 --bail=1 --pool=forks", "test:watch": "pnpm run test --watch", "test:build": "pnpm run --r --parallel test:build", "test:cov": "vitest run --coverage",