Update Nock files #39
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@v3 | |
with: | |
ref: refs/pull/${{ inputs.pr_id }}/head | |
- name: Install Node | |
uses: actions/setup-node@v3 | |
with: | |
# Let's use the oldest version supported to be sure the V8 | |
# serialization is compatible with all supported versions. | |
node-version: 16.x | |
- 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@v3 | |
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 -r tests/nock | |
- 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/nock || echo "yes")" >> $GITHUB_OUTPUT | |
shell: bash | |
- name: Commit changes | |
if: ${{ steps.contains-changes.outputs.result == 'yes' }} | |
run: | | |
git add tests/nock/ | |
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/nock` in case of failure | |
uses: actions/upload-artifact@v3 | |
if: ${{ failure() && steps.contains-changes.outputs.result == 'yes' }} | |
with: | |
name: nock | |
path: | | |
tests/nock |