From 345d66ba23ba4a6fbfb2ef47861442288098f983 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Tue, 9 Jan 2024 13:34:10 -0700 Subject: [PATCH] reusable --- .github/workflows/examples.yml | 185 ++---------------------- .github/workflows/merge_queue.yml | 4 +- .github/workflows/reusable/examples.yml | 176 ++++++++++++++++++++++ .github/workflows/reusable/test.yml | 43 ++++++ .github/workflows/test.yml | 50 ++----- 5 files changed, 246 insertions(+), 212 deletions(-) create mode 100644 .github/workflows/reusable/examples.yml create mode 100644 .github/workflows/reusable/test.yml diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 249e460d1..2a0161e88 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -1,178 +1,19 @@ -name: "Build examples" - -on: [push, pull_request, workflow_call] +name: Build examples + +on: + # We cannot filter by path as this is a required check. See + # https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/troubleshooting-required-status-checks#handling-skipped-but-required-checks + push: + branches: + - main + pull_request: + # Recommended by Graphite: https://graphite.dev/docs/github-configuration-guidelines#github-actions + types: [opened, synchronize, reopened] concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: - nextjs-13-pages-wrap: - name: "Next.js 13 + Page Router + withArcjet" - runs-on: ubuntu-latest - steps: - # Environment security - - name: Step Security - uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1 - with: - egress-policy: audit - - # Checkout - # Most toolchains require checkout first - - name: Checkout - uses: actions/checkout@v4 - - # Language toolchains - - name: Install Node - uses: actions/setup-node@v4.0.0 - with: - node-version: 20 - - # Workflow - - - name: Install dependencies - run: npm ci - - - name: Install example dependencies - working-directory: examples/nextjs-13-pages-wrap - run: npm ci - - - name: Build - working-directory: examples/nextjs-13-pages-wrap - run: npm run build - - nextjs-14-app-dir-rl: - name: "Next.js 14 + App Router + Rate Limit" - runs-on: ubuntu-latest - steps: - # Environment security - - name: Step Security - uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1 - with: - egress-policy: audit - - # Checkout - # Most toolchains require checkout first - - name: Checkout - uses: actions/checkout@v4 - - # Language toolchains - - name: Install Node - uses: actions/setup-node@v4.0.0 - with: - node-version: 20 - - # Workflow - - - name: Install dependencies - run: npm ci - - - name: Install example dependencies - working-directory: examples/nextjs-14-app-dir-rl - run: npm ci - - - name: Build - working-directory: examples/nextjs-14-app-dir-rl - run: npm run build - - nextjs-14-app-dir-validate-email: - name: "Next.js 14 + App Router + Validate Email" - runs-on: ubuntu-latest - steps: - # Environment security - - name: Step Security - uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1 - with: - egress-policy: audit - - # Checkout - # Most toolchains require checkout first - - name: Checkout - uses: actions/checkout@v4 - - # Language toolchains - - name: Install Node - uses: actions/setup-node@v4.0.0 - with: - node-version: 20 - - # Workflow - - - name: Install dependencies - run: npm ci - - - name: Install example dependencies - working-directory: examples/nextjs-14-app-dir-validate-email - run: npm ci - - - name: Build - working-directory: examples/nextjs-14-app-dir-validate-email - run: npm run build - - nextjs-14-openai: - name: "Next.js 14 + OpenAI" - runs-on: ubuntu-latest - steps: - # Environment security - - name: Step Security - uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1 - with: - egress-policy: audit - - # Checkout - # Most toolchains require checkout first - - name: Checkout - uses: actions/checkout@v4 - - # Language toolchains - - name: Install Node - uses: actions/setup-node@v4.0.0 - with: - node-version: 20 - - # Workflow - - - name: Install dependencies - run: npm ci - - - name: Install example dependencies - working-directory: examples/nextjs-14-openai - run: npm ci - - - name: Build - working-directory: examples/nextjs-14-openai - run: npm run build - - nextjs-14-pages-wrap: - name: "Next.js 14 + Page Router + withArcjet" - runs-on: ubuntu-latest - steps: - # Environment security - - name: Step Security - uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1 - with: - egress-policy: audit - - # Checkout - # Most toolchains require checkout first - - name: Checkout - uses: actions/checkout@v4 - - # Language toolchains - - name: Install Node - uses: actions/setup-node@v4.0.0 - with: - node-version: 20 - - # Workflow - - - name: Install dependencies - run: npm ci - - - name: Install example dependencies - working-directory: examples/nextjs-14-pages-wrap - run: npm ci - - - name: Build - working-directory: examples/nextjs-14-pages-wrap - run: npm run build + examples: + uses: ./.github/workflows/reusable/examples.yml diff --git a/.github/workflows/merge_queue.yml b/.github/workflows/merge_queue.yml index 167426585..1c7fc6425 100644 --- a/.github/workflows/merge_queue.yml +++ b/.github/workflows/merge_queue.yml @@ -8,8 +8,8 @@ on: jobs: test: name: Merge queue - Run tests - uses: ./.github/workflows/test.yml + uses: ./.github/workflows/reusable/test.yml examples: name: Merge queue - Build examples - uses: ./.github/workflows/examples.yml + uses: ./.github/workflows/reusable/examples.yml diff --git a/.github/workflows/reusable/examples.yml b/.github/workflows/reusable/examples.yml new file mode 100644 index 000000000..3e0928d4f --- /dev/null +++ b/.github/workflows/reusable/examples.yml @@ -0,0 +1,176 @@ +# Our reusable workflow files only use the `workflow_call` event and don't +# specify a `concurrency` limit so those things can be managed by the caller. +name: Reusable examples workflow + +on: [workflow_call] + +jobs: + nextjs-13-pages-wrap: + name: "Next.js 13 + Page Router + withArcjet" + runs-on: ubuntu-latest + steps: + # Environment security + - name: Step Security + uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1 + with: + egress-policy: audit + + # Checkout + # Most toolchains require checkout first + - name: Checkout + uses: actions/checkout@v4 + + # Language toolchains + - name: Install Node + uses: actions/setup-node@v4.0.0 + with: + node-version: 20 + + # Workflow + + - name: Install dependencies + run: npm ci + + - name: Install example dependencies + working-directory: examples/nextjs-13-pages-wrap + run: npm ci + + - name: Build + working-directory: examples/nextjs-13-pages-wrap + run: npm run build + + nextjs-14-app-dir-rl: + name: "Next.js 14 + App Router + Rate Limit" + runs-on: ubuntu-latest + steps: + # Environment security + - name: Step Security + uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1 + with: + egress-policy: audit + + # Checkout + # Most toolchains require checkout first + - name: Checkout + uses: actions/checkout@v4 + + # Language toolchains + - name: Install Node + uses: actions/setup-node@v4.0.0 + with: + node-version: 20 + + # Workflow + + - name: Install dependencies + run: npm ci + + - name: Install example dependencies + working-directory: examples/nextjs-14-app-dir-rl + run: npm ci + + - name: Build + working-directory: examples/nextjs-14-app-dir-rl + run: npm run build + + nextjs-14-app-dir-validate-email: + name: "Next.js 14 + App Router + Validate Email" + runs-on: ubuntu-latest + steps: + # Environment security + - name: Step Security + uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1 + with: + egress-policy: audit + + # Checkout + # Most toolchains require checkout first + - name: Checkout + uses: actions/checkout@v4 + + # Language toolchains + - name: Install Node + uses: actions/setup-node@v4.0.0 + with: + node-version: 20 + + # Workflow + + - name: Install dependencies + run: npm ci + + - name: Install example dependencies + working-directory: examples/nextjs-14-app-dir-validate-email + run: npm ci + + - name: Build + working-directory: examples/nextjs-14-app-dir-validate-email + run: npm run build + + nextjs-14-openai: + name: "Next.js 14 + OpenAI" + runs-on: ubuntu-latest + steps: + # Environment security + - name: Step Security + uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1 + with: + egress-policy: audit + + # Checkout + # Most toolchains require checkout first + - name: Checkout + uses: actions/checkout@v4 + + # Language toolchains + - name: Install Node + uses: actions/setup-node@v4.0.0 + with: + node-version: 20 + + # Workflow + + - name: Install dependencies + run: npm ci + + - name: Install example dependencies + working-directory: examples/nextjs-14-openai + run: npm ci + + - name: Build + working-directory: examples/nextjs-14-openai + run: npm run build + + nextjs-14-pages-wrap: + name: "Next.js 14 + Page Router + withArcjet" + runs-on: ubuntu-latest + steps: + # Environment security + - name: Step Security + uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1 + with: + egress-policy: audit + + # Checkout + # Most toolchains require checkout first + - name: Checkout + uses: actions/checkout@v4 + + # Language toolchains + - name: Install Node + uses: actions/setup-node@v4.0.0 + with: + node-version: 20 + + # Workflow + + - name: Install dependencies + run: npm ci + + - name: Install example dependencies + working-directory: examples/nextjs-14-pages-wrap + run: npm ci + + - name: Build + working-directory: examples/nextjs-14-pages-wrap + run: npm run build diff --git a/.github/workflows/reusable/test.yml b/.github/workflows/reusable/test.yml new file mode 100644 index 000000000..c30c2d10a --- /dev/null +++ b/.github/workflows/reusable/test.yml @@ -0,0 +1,43 @@ +# Our reusable workflow files only use the `workflow_call` event and don't +# specify a `concurrency` limit so those things can be managed by the caller. +name: Reusable test workflow + +on: [workflow_call] + +jobs: + test: + name: "Run tests (OS: ${{matrix.os}}, Node: ${{ matrix.node }})" + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + node: [18, 20] + os: [ubuntu-latest] + steps: + # Environment security + - name: Step Security + uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1 + with: + egress-policy: audit + + # Checkout + # Most toolchains require checkout first + - name: Checkout + uses: actions/checkout@v4 + + # Language toolchains + - name: Install Node + uses: actions/setup-node@v4.0.0 + with: + node-version: ${{ matrix.node }} + + # Workflow + + - name: Install dependencies + run: npm ci + + - name: Lint + run: npm run lint + + - name: Run tests + run: npm test diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2390181fe..8b5c381ee 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,14 @@ -name: "Run tests" - -on: [push, pull_request, workflow_call] +name: Run tests + +on: + # We cannot filter by path as this is a required check. See + # https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/troubleshooting-required-status-checks#handling-skipped-but-required-checks + push: + branches: + - main + pull_request: + # Recommended by Graphite: https://graphite.dev/docs/github-configuration-guidelines#github-actions + types: [opened, synchronize, reopened] concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -8,38 +16,4 @@ concurrency: jobs: test: - name: "Run tests (OS: ${{matrix.os}}, Node: ${{ matrix.node }})" - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - node: [18, 20] - os: [ubuntu-latest] - steps: - # Environment security - - name: Step Security - uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1 - with: - egress-policy: audit - - # Checkout - # Most toolchains require checkout first - - name: Checkout - uses: actions/checkout@v4 - - # Language toolchains - - name: Install Node - uses: actions/setup-node@v4.0.0 - with: - node-version: ${{ matrix.node }} - - # Workflow - - - name: Install dependencies - run: npm ci - - - name: Lint - run: npm run lint - - - name: Run tests - run: npm test + uses: ./.github/workflows/reusable/test.yml