Skip to content

Commit 9e96a8b

Browse files
committed
fixup! chore(ci): add conflict resolver to Update Nock file workflow
1 parent 2f796d3 commit 9e96a8b

1 file changed

Lines changed: 29 additions & 10 deletions

File tree

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

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@ jobs:
3434
if: ${{ !inputs.head_sha }}
3535
run: |
3636
set -x
37-
[ "$(gh pr view "$GITHUB_SERVER/$GITHUB_REPOSITORY/pull/$PR_ID" \
38-
--json headRepositoryOwner --jq '.headRepositoryOwner.name') = "$GITHUB_REPOSITORY_OWNER" ]
37+
[ "$(gh pr view "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/pull/$PR_ID" \
38+
--json headRepositoryOwner --jq '.headRepositoryOwner.name')" = "$GITHUB_REPOSITORY_OWNER" ]
3939
env:
4040
PR_ID: ${{ inputs.pr_id }}
4141
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4242

4343
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
4444
with:
45-
ref: refs/pulls/${{ inputs.pr_id }}/head
45+
ref: refs/pull/${{ inputs.pr_id }}/head
46+
fetch-depth: ${{ !inputs.fix_conflicts && 1 || 0 }}
4647

4748
- name: Verify if provided SHA matches PR head
4849
if: ${{ inputs.head_sha }}
@@ -52,16 +53,31 @@ jobs:
5253
env:
5354
EXPECTED: ${{ inputs.head_sha }}
5455

55-
- name: Git config
56+
- name: Get PR info
57+
id: pr_info
5658
run: |
57-
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
58-
git config --global user.name "github-actions[bot]"
59+
{
60+
echo 'DATA<<""EOF""'
61+
gh api \
62+
-H "Accept: application/vnd.github+json" \
63+
/repos/$GITHUB_REPOSITORY/pulls/$PR_ID \
64+
--jq '{ clone_url: .head.repo.clone_url, base_ref: .base.ref, head_ref: .head.ref }'
65+
echo '""EOF""'
66+
} >> "$GITHUB_OUTPUT"
67+
env:
68+
PR_ID: ${{ inputs.pr_id }}
69+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70+
71+
- name: Setup git author
72+
run: |
73+
git config --local user.email "github-bot@iojs.org"
74+
git config --local user.name "Node.js GitHub Bot"
5975
6076
- name: Merge base branch
6177
if: ${{ inputs.fix_conflicts }}
62-
run: |
63-
git fetch "$GITHUB_SERVER/$GITHUB_REPOSITORY.git" HEAD
64-
git merge FETCH_HEAD --no-edit -s ours
78+
run: git merge "origin/$BASE_BRANCH" --no-edit -X theirs
79+
env:
80+
BASE_BRANCH: ${{ fromJson(steps.pr_info.outputs.DATA).base_ref }}
6581

6682
- name: Install Node
6783
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
@@ -110,7 +126,10 @@ jobs:
110126
111127
- name: Push changes
112128
if: ${{ steps.contains-changes.outputs.result == 'yes' || inputs.fix_conflicts }}
113-
run: git push
129+
run: git push "$REMOTE" "HEAD:refs/heads/$REMOTE_REF"
130+
env:
131+
REMOTE: ${{ fromJson(steps.pr_info.outputs.DATA).clone_url }}
132+
REMOTE_REF: ${{ fromJson(steps.pr_info.outputs.DATA).head_ref }}
114133

115134
- name: Upload `tests/nocks.db` in case of failure
116135
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2

0 commit comments

Comments
 (0)