Skip to content

Commit

Permalink
chore: configuration for merge queues (#5592)
Browse files Browse the repository at this point in the history
  • Loading branch information
ovflowd committed Aug 2, 2023
1 parent d7abc6d commit 099470b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
branches:
- main
pull_request:
merge_group:

defaults:
run:
Expand Down Expand Up @@ -53,7 +54,7 @@ jobs:
shell: cmd
run: echo C:\Program Files\Git\usr\bin>>"%GITHUB_PATH%"

- name: Git Checkout (`head_sha`)
- name: Git Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
with:
# We only need to fetch the last commit from the head_ref
Expand All @@ -62,8 +63,6 @@ jobs:
# this ensures that our bundle analysis script always runs and that we always ensure next.js is building
# regardless of having code changes or not
fetch-depth: 1
# We checkout the head.sha to get the latest commit, instead of head.ref that gives the current ref of the branch
ref: ${{ github.event.pull_request.head.sha }}

- name: Restore Build Cache
uses: actions/cache/restore@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8
Expand All @@ -86,7 +85,7 @@ jobs:
node-version-file: '.nvmrc'
cache: 'npm'

- name: Install NPM packages (`head_sha`)
- name: Install NPM packages
# We want to avoid NPM from running the Audit Step and Funding messages on a CI environment
# We also use `npm i` instead of `npm ci` so that the node_modules/.cache folder doesn't get deleted
# We also use `--omit=dev` to avoid installing devDependencies as we don't need them during the build step
Expand All @@ -106,18 +105,21 @@ jobs:
NEXT_TELEMETRY_DISABLED: 1

- name: Analyse Build
if: github.event_name == 'pull_request'
# We generate a Bundle Analysis Report
# See https://github.com/hashicorp/nextjs-bundle-analysis
run: npx --package=nextjs-bundle-analysis@0.5.0 report

- name: Upload Build Analysis
if: github.event_name == 'pull_request'
# We upload the Bundle Analysis Artifact so it can be used on another Workflow
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce
with:
name: bundle-analysis
path: .next/analyze/__bundle_analysis.json

- name: Save Build Cache
if: github.event_name == 'pull_request'
uses: actions/cache/save@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8
with:
path: |
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/pull-request-target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# for the full list of available actions. If you want to add a new one, please reach out a maintainer with Admin permissions.
# REVIEWERS, please always double-check security practices before merging a PR that contains Workflow changes!!
# AUTHORS, please only use actions with explicit SHA references, and avoid using `@master` or `@main` references or `@version` tags.
# MERGE QUEUE NOTE: This Workflow does not run on `merge_group` trigger, as this Workflow is not required for Merge Queue's
# The main purpose of this Workflow is to decorate the Pull Request with important information for a Pull Request
# On a merge queue the Pull Request already got approved!

name: Pull Requests Target Checks

Expand Down
32 changes: 20 additions & 12 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ name: Pull Request Checks

on:
pull_request:
merge_group:

defaults:
run:
Expand All @@ -34,7 +35,12 @@ jobs:
# Which should include the "merge" commit reference
# In other words, the GitHub Action will always have the full history of the current PR
# We need all the commits of the PR so that `turbo --filter` works correctly
run: echo "fetch_depth=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "$GITHUB_OUTPUT"
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "fetch_depth=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "$GITHUB_OUTPUT"
else
echo "fetch_depth=1" >> "$GITHUB_OUTPUT"
fi
- name: Provide Turborepo Arguments
id: turborepo_arguments
Expand All @@ -47,21 +53,24 @@ jobs:
# See https://turbo.build/repo/docs/reference/command-line-reference/run#--filter
# See https://turbo.build/repo/docs/reference/command-line-reference/run#--cache-dir
# See https://turbo.build/repo/docs/reference/command-line-reference/run#--force
run: echo "turbo_args=--filter=\"[HEAD~${{ github.event.pull_request.commits }}...HEAD]\" --cache-dir=.turbo/cache" >> "$GITHUB_OUTPUT"
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "turbo_args=--filter=\"[HEAD~${{ github.event.pull_request.commits }}...HEAD]\" --cache-dir=.turbo/cache" >> "$GITHUB_OUTPUT"
else
echo "turbo_args=--cache-dir=.turbo/cache" >> "$GITHUB_OUTPUT"
fi
lint:
name: Lint
runs-on: ubuntu-latest
needs: [base]

steps:
- name: Git Checkout (`head_sha`)
- name: Git Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
with:
# Here we apply the Environment Variable created above on the "Calculate Commits to Checkout"
fetch-depth: ${{ needs.base.outputs.fetch_depth }}
# We checkout the head.sha to get the latest commit, instead of head.ref that gives the current ref of the branch
ref: ${{ github.event.pull_request.head.sha }}

- name: Restore Lint Cache
uses: actions/cache/restore@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8
Expand All @@ -82,7 +91,7 @@ jobs:
node-version-file: '.nvmrc'
cache: 'npm'

- name: Install NPM packages (`head_sha`)
- name: Install NPM packages
# We want to avoid NPM from running the Audit Step and Funding messages on a CI environment
# We also use `npm i` instead of `npm ci` so that the node_modules/.cache folder doesn't get deleted
run: npm i --no-audit --no-fund --ignore-scripts --userconfig=/dev/null
Expand All @@ -98,6 +107,7 @@ jobs:
run: npx --package=turbo@latest -- turbo prettier ${{ needs.base.outputs.turbo_args }}

- name: Save Lint Cache
if: github.event_name == 'pull_request'
uses: actions/cache/save@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8
with:
path: |
Expand All @@ -111,15 +121,11 @@ jobs:
needs: [base]

steps:
- name: Git Checkout (`head_sha`)
- name: Git Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
with:
# Here we apply the Environment Variable created above on the "Calculate Commits to Checkout"
fetch-depth: ${{ needs.base.outputs.fetch_depth }}
# Since we use the `pull_request_target` event we want to checkout the current ref as by default this
# command will checkout `main` instead of the current pull_request ref
# We checkout the head.sha to get the latest commit, instead of head.ref that gives the current ref of the branch
ref: ${{ github.event.pull_request.head.sha }}

- name: Restore Tests Cache
uses: actions/cache/restore@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8
Expand All @@ -140,7 +146,7 @@ jobs:
node-version-file: '.nvmrc'
cache: 'npm'

- name: Install NPM packages (`head_sha`)
- name: Install NPM packages
# We want to avoid NPM from running the Audit Step and Funding messages on a CI environment
# We also use `npm i` instead of `npm ci` so that the node_modules/.cache folder doesn't get deleted
run: npm i --no-audit --no-fund --userconfig=/dev/null
Expand All @@ -151,6 +157,7 @@ jobs:
run: npx --package=turbo@latest -- turbo test:unit ${{ needs.base.outputs.turbo_args }} -- --ci --coverage

- name: Upload Coverage Report
if: github.event_name == 'pull_request'
# We upload the Coverage Report so it can be used on another Workflow
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce
with:
Expand All @@ -165,6 +172,7 @@ jobs:
run: npx --package=turbo@latest -- turbo test:storybook:local ${{ needs.base.outputs.turbo_args }} -- --ci

- name: Save Tests Cache
if: github.event_name == 'pull_request'
uses: actions/cache/save@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8
with:
path: |
Expand Down

0 comments on commit 099470b

Please sign in to comment.