Skip to content

Update Nock files

Update Nock files #62

name: Update Nock files
on:
workflow_dispatch:
inputs:
pr_id:
description: PR ID
type: number
required: true
env:
YARN_ENABLE_GLOBAL_CACHE: false
jobs:
build-and-update-nock-files:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: refs/pull/${{ inputs.pr_id }}/head
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Get the Yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(corepack yarn config get cacheFolder)" >> $GITHUB_OUTPUT
shell: bash
- uses: actions/cache@v4
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: echo "result=$(git --no-pager diff --quiet -- tests/nocks.db || echo "yes")" >> $GITHUB_OUTPUT
shell: bash
- name: Commit changes
if: ${{ steps.contains-changes.outputs.result == 'yes' }}
run: |
git add tests/nocks.db
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git commit -m "update Nock files"
- name: Push changes
if: ${{ steps.contains-changes.outputs.result == 'yes' }}
run: >
gh api
-H "Accept: application/vnd.github+json"
/repos/${{ github.repository }}/pulls/${{ inputs.pr_id }}
--jq '"git push " + .head.repo.clone_url + " HEAD:refs/heads/" + .head.ref' | sh
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload `tests/nocks.db` in case of failure
uses: actions/upload-artifact@v4
if: ${{ failure() && steps.contains-changes.outputs.result == 'yes' }}
with:
name: nock
path: |
tests/nocks.db