-
Notifications
You must be signed in to change notification settings - Fork 173
79 lines (65 loc) · 2.27 KB
/
update-nock-files.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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