Skip to content

Commit ec42596

Browse files
authored
chore(ci): add conflict resolver to Update Nock file workflow (#766)
1 parent 1ba315d commit ec42596

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

.github/workflows/update-nock-files.yml

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Update Nock files
1+
name: Update Nock file
22

33
on:
44
workflow_dispatch:
@@ -11,14 +11,22 @@ on:
1111
description: Commit SHA of the head of the PR branch (only required for PRs from forks)
1212
type: string
1313
required: false
14+
merge_base:
15+
description: Merge base branch (any conflicts will be forced resolved)
16+
type: boolean
17+
required: false
1418

1519
env:
1620
YARN_ENABLE_GLOBAL_CACHE: false
1721

22+
permissions:
23+
contents: read
24+
1825
jobs:
1926
build-and-update-nock-files:
2027
permissions:
2128
contents: write
29+
pull-requests: read
2230
runs-on: ubuntu-latest
2331

2432
steps:
@@ -29,23 +37,41 @@ jobs:
2937
echo 'DATA<<""EOF""'
3038
gh api \
3139
-H "Accept: application/vnd.github+json" \
32-
/repos/${{ github.repository }}/pulls/${{ inputs.pr_id }} \
33-
--jq '{ repo: .head.repo.full_name, clone_url: .head.repo.clone_url, head_sha: .head.sha, head_ref: .head.ref }'
40+
"/repos/$GITHUB_REPOSITORY/pulls/$PR_ID" \
41+
--jq '{ repo: .head.repo.full_name, clone_url: .head.repo.clone_url, head_sha: .head.sha, head_ref: .head.ref, base_ref: .base.ref }'
3442
echo '""EOF""'
3543
} >> "$GITHUB_OUTPUT"
3644
env:
45+
PR_ID: ${{ inputs.pr_id }}
3746
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
3848
- name: Validate HEAD SHA
3949
if: ${{ fromJson(steps.pr_info.outputs.DATA).repo != github.repository || inputs.head_sha }}
40-
run: >
41-
[[ "$EXPECTED" == "$ACTUAL" ]] || exit 1
50+
run: |
51+
set -x
52+
[ "$EXPECTED" = "$ACTUAL" ]
4253
env:
4354
ACTUAL: ${{ fromJson(steps.pr_info.outputs.DATA).head_sha }}
4455
EXPECTED: ${{ inputs.head_sha }}
4556

4657
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
4758
with:
4859
ref: ${{ fromJson(steps.pr_info.outputs.DATA).head_sha }}
60+
fetch-depth: ${{ !inputs.merge_base && 1 || 0 }}
61+
62+
- name: Setup git author
63+
run: |
64+
git config --local user.email "github-bot@iojs.org"
65+
git config --local user.name "Node.js GitHub Bot"
66+
67+
- name: Merge base branch
68+
if: ${{ inputs.merge_base }}
69+
run: |
70+
git merge "origin/$BASE_BRANCH" --no-ff --no-verify --no-edit -X ours
71+
git checkout HEAD^ -- tests/nocks.db
72+
git commit --amend --no-verify --no-edit
73+
env:
74+
BASE_BRANCH: ${{ fromJson(steps.pr_info.outputs.DATA).base_ref }}
4975

5076
- name: Install Node
5177
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
@@ -78,10 +104,10 @@ jobs:
78104
- name: Check if anything has changed
79105
id: contains-changes
80106
run: |
81-
sqlite3 tests/nocks.db .dump > /tmp/before.sql
107+
sqlite3 tests/nocks.db .dump > /tmp/after.sql
82108
cp tests/nocks.db tests/nocks.db.new
83109
git checkout HEAD -- tests/nocks.db
84-
sqlite3 tests/nocks.db .dump > /tmp/after.sql
110+
sqlite3 tests/nocks.db .dump > /tmp/before.sql
85111
echo "result=$(git --no-pager diff --quiet --no-index /tmp/before.sql /tmp/after.sql || echo "yes")" >> "$GITHUB_OUTPUT"
86112
mv tests/nocks.db.new tests/nocks.db
87113
shell: bash
@@ -90,12 +116,10 @@ jobs:
90116
if: ${{ steps.contains-changes.outputs.result == 'yes' }}
91117
run: |
92118
git add tests/nocks.db
93-
git config --global user.email "actions@github.com"
94-
git config --global user.name "GitHub Actions"
95119
git commit -m "update Nock files"
96120
97121
- name: Push changes
98-
if: ${{ steps.contains-changes.outputs.result == 'yes' }}
122+
if: ${{ steps.contains-changes.outputs.result == 'yes' || inputs.merge_base }}
99123
run: git push "$REMOTE" "HEAD:refs/heads/$REMOTE_REF"
100124
env:
101125
REMOTE: ${{ fromJson(steps.pr_info.outputs.DATA).clone_url }}

0 commit comments

Comments
 (0)