-
-
Notifications
You must be signed in to change notification settings - Fork 250
134 lines (115 loc) · 4.43 KB
/
update-nock-files.yml
File metadata and controls
134 lines (115 loc) · 4.43 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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
merge_base:
description: Merge base branch (any conflicts will be forced resolved)
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: Get PR info
id: pr_info
run: |
{
echo 'DATA<<""EOF""'
gh api \
-H "Accept: application/vnd.github+json" \
"/repos/$GITHUB_REPOSITORY/pulls/$PR_ID" \
--jq '{ repo: .head.repo.full_name, clone_url: .head.repo.clone_url, head_sha: .head.sha, head_ref: .head.ref, base_ref: .base.ref }'
echo '""EOF""'
} >> "$GITHUB_OUTPUT"
env:
PR_ID: ${{ inputs.pr_id }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Validate HEAD SHA
if: ${{ fromJson(steps.pr_info.outputs.DATA).repo != github.repository || inputs.head_sha }}
run: |
set -x
[ "$EXPECTED" = "$ACTUAL" ]
env:
ACTUAL: ${{ fromJson(steps.pr_info.outputs.DATA).head_sha }}
EXPECTED: ${{ inputs.head_sha }}
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
ref: ${{ fromJson(steps.pr_info.outputs.DATA).head_sha }}
fetch-depth: ${{ !inputs.merge_base && 1 || 0 }}
- name: Setup git author
run: |
git config --local user.email "github-bot@iojs.org"
git config --local user.name "Node.js GitHub Bot"
- name: Merge base branch
if: ${{ inputs.merge_base }}
run: |
git merge "origin/$BASE_BRANCH" --no-ff --no-verify --no-edit -X ours
git checkout HEAD^ -- tests/nocks.db
git commit --amend --no-verify --no-edit
env:
BASE_BRANCH: ${{ fromJson(steps.pr_info.outputs.DATA).base_ref }}
- 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/after.sql
cp tests/nocks.db tests/nocks.db.new
git checkout HEAD -- tests/nocks.db
sqlite3 tests/nocks.db .dump > /tmp/before.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.merge_base }}
run: git push "$REMOTE" "HEAD:refs/heads/$REMOTE_REF"
env:
REMOTE: ${{ fromJson(steps.pr_info.outputs.DATA).clone_url }}
REMOTE_REF: ${{ fromJson(steps.pr_info.outputs.DATA).head_ref }}
- 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