Skip to content

Update Nock file

Update Nock file #85

name: Update Nock file
on:
workflow_dispatch:
inputs:
pr_id:
description: PR ID
type: number
required: true
head_sha:
description: Commit SHA of the head of the PR branch (only required for PRs from forks)
type: string
required: false
fix_conflicts:
description: Tick this if there are conflicts on the nock file on the targeted PR
type: boolean
required: false
env:
YARN_ENABLE_GLOBAL_CACHE: false
permissions:
contents: read
jobs:
build-and-update-nock-files:
permissions:
contents: write
pull-requests: read
runs-on: ubuntu-latest
steps:
- name: Reject if SHA was not provided for PR from forks
if: ${{ !inputs.head_sha }}
run: |
set -x
[ "$(gh pr view "$GITHUB_SERVER/$GITHUB_REPOSITORY/pull/$PR_ID" \
--json headRepositoryOwner --jq '.headRepositoryOwner.name') = "$GITHUB_REPOSITORY_OWNER" ]
env:
PR_ID: ${{ inputs.pr_id }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
ref: refs/pulls/${{ inputs.pr_id }}/head
- name: Verify if provided SHA matches PR head
if: ${{ inputs.head_sha }}
run: |
set -x
[ "$EXPECTED" = "$(git rev-parse HEAD)" ]
env:
EXPECTED: ${{ inputs.head_sha }}
- name: Git config
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Merge base branch
if: ${{ inputs.fix_conflicts }}
run: |
git fetch "$GITHUB_SERVER/$GITHUB_REPOSITORY.git" HEAD
git merge FETCH_HEAD --no-edit -s ours
- name: Install Node
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
with:
node-version: lts/*
env:
SKIP_YARN_COREPACK_CHECK: 1
- name: Get the Yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(corepack yarn config get cacheFolder)" >> "$GITHUB_OUTPUT"
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: ${{steps.yarn-cache-dir-path.outputs.dir}}
key: ${{runner.os}}-yarn-${{hashFiles('**/yarn.lock')}}
restore-keys: |
${{runner.os}}-yarn-
- run: corepack yarn install --immutable
- run: corepack yarn build # We need the stubs to run the tests
- name: Remove old Nock files to avoid conflicts
run: rm tests/nocks.db
- run: corepack yarn test
env:
NOCK_ENV: record
- name: Check if anything has changed
id: contains-changes
run: |
sqlite3 tests/nocks.db .dump > /tmp/before.sql
cp tests/nocks.db tests/nocks.db.new
git checkout HEAD -- tests/nocks.db
sqlite3 tests/nocks.db .dump > /tmp/after.sql
echo "result=$(git --no-pager diff --quiet --no-index /tmp/before.sql /tmp/after.sql || echo "yes")" >> "$GITHUB_OUTPUT"
mv tests/nocks.db.new tests/nocks.db
shell: bash
- name: Commit changes
if: ${{ steps.contains-changes.outputs.result == 'yes' }}
run: |
git add tests/nocks.db
git commit -m "update Nock files"
- name: Push changes
if: ${{ steps.contains-changes.outputs.result == 'yes' || inputs.fix_conflicts }}
run: git push
- name: Upload `tests/nocks.db` in case of failure
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
if: ${{ failure() && steps.contains-changes.outputs.result == 'yes' }}
with:
name: nock
path: |
tests/nocks.db