-
Notifications
You must be signed in to change notification settings - Fork 0
103 lines (99 loc) · 3.99 KB
/
yarn-unlock.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: Yarn Unlocker
# Short-cut for the common case of a PR having a merge conflict with only `yarn.lock`.
# Responds to a comment on a pull request containing "/yarn unlock"
# Test-merges the PR. If there's only one conflict, that being yarn.lock,
# it runs `yarn` (which will fix it) and pushes the merge commit.
on:
issue_comment:
types: [created]
permissions:
contents: write
issues: write
pull-requests: write
jobs:
merge-yarn-lock:
if: contains(github.event.comment.html_url, '/pull/') && contains(github.event.comment.body, '/yarn unlock')
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
id: comment
with:
script: |
const comment = await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Trying to merge yarn.lock... follow along at https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${{ github.run_id }}`
})
return comment.data.id
- uses: actions/checkout@v4
with:
ref: refs/pull/${{ github.event.issue.number }}/head
fetch-depth: 0
- name: Use Node.js 18.x
uses: actions/setup-node@v4
with:
node-version: 18.x
cache: "yarn"
cache-dependency-path: "yarn.lock"
- run: yarn install --immutable --inline-builds
- id: merge
run: |
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git merge origin/main > ${{ runner.temp }}/merge.log || true
# If there are no conflicts, we're done here
if ! grep -q 'CONFLICT' ${{ runner.temp }}/merge.log; then
echo needs-merge=false >> "$GITHUB_OUTPUT"
exit 1
fi
# Abort *unless* there is only one conflict, that being yarn.lock
if [ "$(grep -c 'CONFLICT' ${{ runner.temp }}/merge.log)" -eq 1 ] && grep -q 'Merge conflict in yarn.lock' ${{ runner.temp }}/merge.log; then
exit 0
fi
echo cannot-fix=true >> "$GITHUB_OUTPUT"
exit 1
- if: failure() && steps.merge.outputs.needs-merge == 'false'
uses: actions/github-script@v7
with:
script: |
github.rest.issues.updateComment({
comment_id: ${{ steps.comment.outputs.result }},
owner: context.repo.owner,
repo: context.repo.repo,
body: 'No conflicts found.'
})
- if: failure() && steps.merge.outputs.cannot-fix == 'true'
uses: actions/github-script@v7
with:
script: |
github.rest.issues.updateComment({
comment_id: ${{ steps.comment.outputs.result }},
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Cannot fix conflicts. Please merge manually.'
})
- run: |
yarn install --no-immutable
git add yarn.lock
git commit -m 'chore: merge yarn.lock'
git push origin HEAD
- uses: actions/github-script@v7
with:
script: |
github.rest.issues.updateComment({
comment_id: ${{ steps.comment.outputs.result }},
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Merged yarn.lock!'
})
- if: failure() && !steps.merge.outputs.needs-merge && !steps.merge.outputs.cannot-fix
uses: actions/github-script@v7
with:
script: |
github.rest.issues.updateComment({
comment_id: ${{ steps.comment.outputs.result }},
owner: context.repo.owner,
repo: context.repo.repo,
body: `Something went wrong. Please look at [the logs](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${{ github.run_id }}).`
})