From 84a30c3d2028ff70c5fb864eeca081b295e6adaa Mon Sep 17 00:00:00 2001 From: AriPerkkio Date: Mon, 26 Jun 2023 13:40:21 +0300 Subject: [PATCH] ci: initial workflows --- .github/renovate.json5 | 15 ++ .github/workflows/ci.yml | 38 +++++ .github/workflows/ecosystem-ci-from-pr.yml | 173 ++++++++++++++++++++ .github/workflows/ecosystem-ci-selected.yml | 73 +++++++++ .github/workflows/ecosystem-ci.yml | 76 +++++++++ 5 files changed, 375 insertions(+) create mode 100644 .github/renovate.json5 create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/ecosystem-ci-from-pr.yml create mode 100644 .github/workflows/ecosystem-ci-selected.yml create mode 100644 .github/workflows/ecosystem-ci.yml diff --git a/.github/renovate.json5 b/.github/renovate.json5 new file mode 100644 index 0000000..f93d67b --- /dev/null +++ b/.github/renovate.json5 @@ -0,0 +1,15 @@ +{ + "extends": ["config:base", "schedule:weekly", "group:allNonMajor"], + "labels": ["dependencies"], + "ignorePaths": [], + "pin": false, + "rangeStrategy": "bump", + "node": false, + "packageRules": [ + { + "depTypeList": ["peerDependencies", "engines"], + "enabled": false, + }, + ], + "ignoreDeps": [], +} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..366a3ab --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,38 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + ci: + timeout-minutes: 10 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + - run: corepack enable + - run: pnpm --version + - uses: actions/setup-node@v3 + with: + node-version: 18 + cache: "pnpm" + cache-dependency-path: "**/pnpm-lock.yaml" + - name: install + run: pnpm install --frozen-lockfile --prefer-offline + - name: format + run: pnpm format + - name: lint + run: pnpm run lint + - name: audit + if: (${{ success() }} || ${{ failure() }}) + run: pnpm audit + - name: test + if: (${{ success() }} || ${{ failure() }}) + run: pnpm test:self diff --git a/.github/workflows/ecosystem-ci-from-pr.yml b/.github/workflows/ecosystem-ci-from-pr.yml new file mode 100644 index 0000000..d7c325e --- /dev/null +++ b/.github/workflows/ecosystem-ci-from-pr.yml @@ -0,0 +1,173 @@ +# integration tests for vitest ecosystem - run from pr comments +name: vitest-ecosystem-ci-from-pr + +env: + # 7 GiB by default on GitHub, setting to 6 GiB + # https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources + NODE_OPTIONS: --max-old-space-size=6144 + +on: + workflow_dispatch: + inputs: + prNumber: + description: "PR number (e.g. 9887)" + required: true + type: string + branchName: + description: "vitest branch to use" + required: true + type: string + default: "main" + repo: + description: "vitest repository to use" + required: true + type: string + default: "vitest-dev/vitest" + suite: + description: "testsuite to run. runs all testsuits when `-`." + required: false + type: choice + options: + - "-" + - vite + - vitest-sonar-reporter +jobs: + init: + runs-on: ubuntu-latest + outputs: + comment-id: ${{ steps.create-comment.outputs.result }} + steps: + - id: generate-token + uses: tibdex/github-app-token@v1 + with: + app_id: ${{ secrets.PR_GITHUB_APP_ID }} + private_key: ${{ secrets.PR_GITHUB_APP_PRIVATE_KEY }} + repository: "${{ github.repository_owner }}/vitest" + - id: create-comment + uses: actions/github-script@v6 + with: + github-token: ${{ steps.generate-token.outputs.token }} + result-encoding: string + script: | + const url = `${context.serverUrl}//${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}` + const urlLink = `[Open](${url})` + + const { data: comment } = await github.rest.issues.createComment({ + issue_number: context.payload.inputs.prNumber, + owner: context.repo.owner, + repo: 'vitest', + body: `⏳ Triggered ecosystem CI: ${urlLink}` + }) + return comment.id + + execute-selected-suite: + timeout-minutes: 30 + runs-on: ubuntu-latest + needs: init + if: "inputs.suite != '-'" + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + - uses: denoland/setup-deno@v1 + with: + deno-version: v1.x + continue-on-error: true + - run: corepack enable + - run: pnpm --version + - run: pnpm i --frozen-lockfile + - run: >- + pnpm tsx ecosystem-ci.ts + --branch ${{ inputs.branchName }} + --repo ${{ inputs.repo }} + ${{ inputs.suite }} + + execute-all: + timeout-minutes: 30 + runs-on: ubuntu-latest + needs: init + if: "inputs.suite == '-'" + strategy: + matrix: + suite: + - vite + - vitest-sonar-reporter + fail-fast: false + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + - uses: denoland/setup-deno@v1 + with: + deno-version: v1.x + continue-on-error: true + - run: corepack enable + - run: pnpm --version + - run: pnpm i --frozen-lockfile + - run: >- + pnpm tsx ecosystem-ci.ts + --branch ${{ inputs.branchName }} + --repo ${{ inputs.repo }} + ${{ matrix.suite }} + + update-comment: + runs-on: ubuntu-latest + needs: [init, execute-selected-suite, execute-all] + if: always() + steps: + - id: generate-token + uses: tibdex/github-app-token@v1 + with: + app_id: ${{ secrets.PR_GITHUB_APP_ID }} + private_key: ${{ secrets.PR_GITHUB_APP_PRIVATE_KEY }} + repository: "${{ github.repository_owner }}/vitest" + - uses: actions/github-script@v6 + with: + github-token: ${{ steps.generate-token.outputs.token }} + script: | + const { data: { jobs } } = await github.rest.actions.listJobsForWorkflowRun({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.runId, + per_page: 100 + }); + + const selectedSuite = context.payload.inputs.suite + let result + if (selectedSuite !== "-") { + const { conclusion, html_url } = jobs.find(job => job.name === "execute-selected-suite") + result = [{ suite: selectedSuite, conclusion, link: html_url }] + } else { + result = jobs + .filter(job => job.name.startsWith('execute-all ')) + .map(job => { + const suite = job.name.replace(/^execute-all \(([^)]+)\)$/, "$1") + return { suite, conclusion: job.conclusion, link: job.html_url } + }) + } + + const url = `${context.serverUrl}//${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}` + const urlLink = `[Open](${url})` + + const conclusionEmoji = { + success: ":white_check_mark:", + failure: ":x:", + cancelled: ":stop_button:" + } + + const body = ` + 📝 Ran ecosystem CI: ${urlLink} + + | suite | result | + |-------|--------| + ${result.map(r => `| [${r.suite}](${r.link}) | ${conclusionEmoji[r.conclusion]} ${r.conclusion} |`).join("\n")} + ` + + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: 'vitest', + comment_id: ${{ needs.init.outputs.comment-id }}, + body + }) diff --git a/.github/workflows/ecosystem-ci-selected.yml b/.github/workflows/ecosystem-ci-selected.yml new file mode 100644 index 0000000..cc5cbeb --- /dev/null +++ b/.github/workflows/ecosystem-ci-selected.yml @@ -0,0 +1,73 @@ +# integration tests for vitest ecosystem - single run of selected testsuite +name: vitest-ecosystem-ci-selected + +env: + # 7 GiB by default on GitHub, setting to 6 GiB + # https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources + NODE_OPTIONS: --max-old-space-size=6144 + +on: + workflow_dispatch: + inputs: + refType: + description: "type of vitest ref to use" + required: true + type: choice + options: + - branch + - tag + - commit + - release + default: "branch" + ref: + description: "vitest ref to use" + required: true + type: string + default: "main" + repo: + description: "vitest repository to use" + required: true + type: string + default: "vitest-dev/vitest" + suite: + description: "testsuite to run" + required: true + type: choice + options: + - vitest-sonar-reporter + - vite +jobs: + execute-selected-suite: + timeout-minutes: 30 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + id: setup-node + - uses: denoland/setup-deno@v1 + with: + deno-version: v1.x + id: setup-deno + continue-on-error: true + - run: corepack enable + - run: pnpm --version + - run: pnpm i --frozen-lockfile + - run: >- + pnpm tsx ecosystem-ci.ts + --${{ inputs.refType }} ${{ inputs.ref }} + --repo ${{ inputs.repo }} + ${{ inputs.suite }} + id: ecosystem-ci-run + - if: always() + run: pnpm tsx discord-webhook.ts + env: + WORKFLOW_NAME: ci-selected + REF_TYPE: ${{ inputs.refType }} + REF: ${{ inputs.ref }} + REPO: ${{ inputs.repo }} + SUITE: ${{ inputs.suite }} + STATUS: ${{ job.status }} + DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/ecosystem-ci.yml b/.github/workflows/ecosystem-ci.yml new file mode 100644 index 0000000..b29acb8 --- /dev/null +++ b/.github/workflows/ecosystem-ci.yml @@ -0,0 +1,76 @@ +# integration tests for vitest ecosystem projects - scheduled or manual run for all suites +name: vitest-ecosystem-ci + +env: + # 7 GiB by default on GitHub, setting to 6 GiB + # https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources + NODE_OPTIONS: --max-old-space-size=6144 + +on: + schedule: + - cron: "0 5 * * 1,3,5" # monday,wednesday,friday 5AM + workflow_dispatch: + inputs: + refType: + description: "type of ref" + required: true + type: choice + options: + - branch + - tag + - commit + - release + default: "branch" + ref: + description: "vitest ref to use" + required: true + type: string + default: "main" + repo: + description: "vite repository to use" + required: true + type: string + default: "vitest-dev/vitest" + repository_dispatch: + types: [ecosystem-ci] +jobs: + test-ecosystem: + timeout-minutes: 30 + runs-on: ubuntu-latest + strategy: + matrix: + suite: + - vitest-sonar-reporter + - vite + fail-fast: false + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + id: setup-node + - uses: denoland/setup-deno@v1 + with: + deno-version: v1.x + id: setup-deno + continue-on-error: true + - run: corepack enable + - run: pnpm --version + - run: pnpm i --frozen-lockfile + - run: >- + pnpm tsx ecosystem-ci.ts + --${{ inputs.refType || github.event.client_payload.refType || 'branch' }} ${{ inputs.ref || github.event.client_payload.ref || 'main' }} + --repo ${{ inputs.repo || github.event.client_payload.repo || 'vitest-dev/vitest' }} + ${{ matrix.suite }} + id: ecosystem-ci-run + - if: always() + run: pnpm tsx discord-webhook.ts + env: + WORKFLOW_NAME: ci + REF_TYPE: ${{ inputs.refType || github.event.client_payload.refType || 'branch' }} + REF: ${{ inputs.ref || github.event.client_payload.ref || 'main' }} + REPO: ${{ inputs.repo || github.event.client_payload.repo || 'vitest-dev/vitest' }} + SUITE: ${{ matrix.suite }} + STATUS: ${{ job.status }} + DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}