From 3ca40140a5e152f42eed57bfbebf445553b46cba Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 2 Sep 2022 11:08:05 +0200 Subject: [PATCH] chore: add GHA to update Nock files (#175) --- .github/workflows/update-nock-files.yml | 76 +++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 .github/workflows/update-nock-files.yml diff --git a/.github/workflows/update-nock-files.yml b/.github/workflows/update-nock-files.yml new file mode 100644 index 0000000..451ec5f --- /dev/null +++ b/.github/workflows/update-nock-files.yml @@ -0,0 +1,76 @@ +name: Update Nock files + +on: + workflow_dispatch: + inputs: + pr_id: + description: PR ID + type: number + required: true + +jobs: + build: + 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: 14.x + + - name: Get the Yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(corepack yarn config get cacheFolder)" + + - 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 "::set-output name=result::$(git --no-pager diff --quiet -- tests/nock || echo "yes")" + + - name: Commit changes + if: ${{ steps.contains-changes.outputs.result == 'yes' }} + run: | + git add tests/nock/ + git config --global user.email "actions@github.com" + 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