From 1a8654055142a1800a9e47c693264acdefd30f30 Mon Sep 17 00:00:00 2001 From: Greg Nazario Date: Tue, 10 Oct 2023 15:44:52 -0700 Subject: [PATCH] [ci] Update github actions for formatting and unit tests Splits Unit tests from E2E tests, formatting, linting, and build to ensure consistency across pull requests. --- .github/actions/run-build/action.yaml | 19 +++++++++++++++++++ .github/actions/run-fmt/action.yaml | 19 +++++++++++++++++++ .github/actions/run-lint/action.yaml | 19 +++++++++++++++++++ .github/actions/run-unit-tests/action.yaml | 19 +++++++++++++++++++ .github/workflows/run-build.yaml | 19 +++++++++++++++++++ .github/workflows/run-fmt.yaml | 19 +++++++++++++++++++ .github/workflows/run-lint.yaml | 19 +++++++++++++++++++ .github/workflows/run-unit-tests.yaml | 19 +++++++++++++++++++ package.json | 2 ++ 9 files changed, 154 insertions(+) create mode 100644 .github/actions/run-build/action.yaml create mode 100644 .github/actions/run-fmt/action.yaml create mode 100644 .github/actions/run-lint/action.yaml create mode 100644 .github/actions/run-unit-tests/action.yaml create mode 100644 .github/workflows/run-build.yaml create mode 100644 .github/workflows/run-fmt.yaml create mode 100644 .github/workflows/run-lint.yaml create mode 100644 .github/workflows/run-unit-tests.yaml diff --git a/.github/actions/run-build/action.yaml b/.github/actions/run-build/action.yaml new file mode 100644 index 000000000..46eb8aa5e --- /dev/null +++ b/.github/actions/run-build/action.yaml @@ -0,0 +1,19 @@ +name: "Run optimized SDK build" +description: | + Run build for Browser, Node, and Types + +runs: + using: composite + steps: + # Install node and pnpm. + - uses: actions/setup-node@v3 + with: + node-version-file: .node-version + registry-url: "https://registry.npmjs.org" + - uses: pnpm/action-setup@v2 + with: + version: 8.9.0 + + # Run package install and build + - run: pnpm install --frozen-lockfile && pnpm build + shell: bash diff --git a/.github/actions/run-fmt/action.yaml b/.github/actions/run-fmt/action.yaml new file mode 100644 index 000000000..5501c25a8 --- /dev/null +++ b/.github/actions/run-fmt/action.yaml @@ -0,0 +1,19 @@ +name: "Verify SDK formatting" +description: | + Run prettier on the codebase to ensure consistency + +runs: + using: composite + steps: + # Install node and pnpm. + - uses: actions/setup-node@v3 + with: + node-version-file: .node-version + registry-url: "https://registry.npmjs.org" + - uses: pnpm/action-setup@v2 + with: + version: 8.9.0 + + # Verify that the format is correct + - run: pnpm install --frozen-lockfile && pnpm _fmt --check + shell: bash diff --git a/.github/actions/run-lint/action.yaml b/.github/actions/run-lint/action.yaml new file mode 100644 index 000000000..14da27d80 --- /dev/null +++ b/.github/actions/run-lint/action.yaml @@ -0,0 +1,19 @@ +name: "Lint SDK Code" +description: | + Run eslint on the codebase to ensure consistency + +runs: + using: composite + steps: + # Install node and pnpm. + - uses: actions/setup-node@v3 + with: + node-version-file: .node-version + registry-url: "https://registry.npmjs.org" + - uses: pnpm/action-setup@v2 + with: + version: 8.9.0 + + # Run eslint + - run: pnpm install --frozen-lockfile && pnpm lint + shell: bash diff --git a/.github/actions/run-unit-tests/action.yaml b/.github/actions/run-unit-tests/action.yaml new file mode 100644 index 000000000..4b1a07eb1 --- /dev/null +++ b/.github/actions/run-unit-tests/action.yaml @@ -0,0 +1,19 @@ +name: "SDK Unit Tests" +description: | + Run the SDK unit tests locally + +runs: + using: composite + steps: + # Install node and pnpm. + - uses: actions/setup-node@v3 + with: + node-version-file: .node-version + registry-url: "https://registry.npmjs.org" + - uses: pnpm/action-setup@v2 + with: + version: 8.9.0 + + # Run unit tests + - run: pnpm install --frozen-lockfile && pnpm unit-test + shell: bash diff --git a/.github/workflows/run-build.yaml b/.github/workflows/run-build.yaml new file mode 100644 index 000000000..e44715be2 --- /dev/null +++ b/.github/workflows/run-build.yaml @@ -0,0 +1,19 @@ +env: + GIT_SHA: ${{ github.event.pull_request.head.sha || github.sha }} + +name: "Run SDK optimized build" +on: + pull_request: + types: [labeled, opened, synchronize, reopened, auto_merge_enabled] + push: + branches: + - main + +jobs: + run-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ env.GIT_SHA }} + - uses: ./.github/actions/run-build diff --git a/.github/workflows/run-fmt.yaml b/.github/workflows/run-fmt.yaml new file mode 100644 index 000000000..8cc34042c --- /dev/null +++ b/.github/workflows/run-fmt.yaml @@ -0,0 +1,19 @@ +env: + GIT_SHA: ${{ github.event.pull_request.head.sha || github.sha }} + +name: "Run SDK code format check" +on: + pull_request: + types: [labeled, opened, synchronize, reopened, auto_merge_enabled] + push: + branches: + - main + +jobs: + run-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ env.GIT_SHA }} + - uses: ./.github/actions/run-fmt diff --git a/.github/workflows/run-lint.yaml b/.github/workflows/run-lint.yaml new file mode 100644 index 000000000..3fcee8f44 --- /dev/null +++ b/.github/workflows/run-lint.yaml @@ -0,0 +1,19 @@ +env: + GIT_SHA: ${{ github.event.pull_request.head.sha || github.sha }} + +name: "Run SDK code linting" +on: + pull_request: + types: [labeled, opened, synchronize, reopened, auto_merge_enabled] + push: + branches: + - main + +jobs: + run-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ env.GIT_SHA }} + - uses: ./.github/actions/run-lint diff --git a/.github/workflows/run-unit-tests.yaml b/.github/workflows/run-unit-tests.yaml new file mode 100644 index 000000000..bf19ac94b --- /dev/null +++ b/.github/workflows/run-unit-tests.yaml @@ -0,0 +1,19 @@ +env: + GIT_SHA: ${{ github.event.pull_request.head.sha || github.sha }} + +name: "Run SDK unit tests" +on: + pull_request: + types: [labeled, opened, synchronize, reopened, auto_merge_enabled] + push: + branches: + - main + +jobs: + run-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ env.GIT_SHA }} + - uses: ./.github/actions/run-unit-tests diff --git a/package.json b/package.json index f1fee60c2..76048f6ca 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,8 @@ "fmt": "pnpm _fmt --write", "lint": "eslint \"**/*.ts\"", "test": "pnpm jest", + "unit-test": "pnpm jest tests/unit", + "e2e-test": "pnpm jest tests/e2e", "indexer-codegen": "graphql-codegen --config ./src/types/codegen.yaml" }, "dependencies": {