Skip to content

Commit c225c1f

Browse files
committed
Implements smart merge v2 (#4177)
1 parent 26beba7 commit c225c1f

File tree

7 files changed

+145
-50
lines changed

7 files changed

+145
-50
lines changed

.github/workflows/pr-smart-merge.yml

Lines changed: 84 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,47 @@
11
on:
2-
workflow_dispatch:
3-
inputs:
4-
pr:
5-
description: 'The pull request to update'
6-
required: true
2+
pull_request_target:
3+
types: [labeled]
74

8-
name: 'Smart master merge'
5+
name: 'Smart merge'
96
jobs:
10-
merge:
11-
name: 'Merge master into the PR'
7+
reset:
8+
name: 'Remove the label'
129
runs-on: ubuntu-latest
10+
if: |
11+
github.event.label.name == 'infra: pending update'
1312
1413
steps:
15-
- uses: actions/checkout@master
14+
- name: 'Remove the label'
15+
uses: actions/github-script@v6
16+
with:
17+
script: |
18+
await github.rest.issues.removeLabel({
19+
owner: context.repo.owner,
20+
repo: context.repo.repo,
21+
issue_number: context.issue.number,
22+
name: context.payload.label.name,
23+
});
24+
25+
generate:
26+
name: 'Generate an update changeset'
27+
runs-on: ubuntu-latest
28+
needs: reset
29+
permissions:
30+
contents: read
31+
32+
steps:
33+
- uses: actions/checkout@v3
1634
with:
17-
ref: master
18-
token: ${{secrets.YARNBOT_TOKEN}}
35+
ref: ${{github.event.pull_request.head.sha}}
1936
fetch-depth: 0
2037

2138
- uses: ./.github/actions/prepare
2239

23-
- name: 'Update, commit, and upload the artifacts'
40+
- name: 'Generate the changeset'
2441
run: |
25-
PR_META=$(curl https://api.github.com/repos/yarnpkg/berry/pulls/'${{github.event.inputs.pr}}')
42+
git fetch origin master
2643
27-
PR_REPO=$(jq -r .head.repo.full_name <<< "$PR_META")
28-
PR_REF=$(jq -r .head.ref <<< "$PR_META")
29-
30-
git config user.name "Yarn Bot"
31-
git config user.email [email protected]
32-
33-
git remote add pr-source https://'${{secrets.YARNBOT_TOKEN}}'@github.com/"$PR_REPO".git
34-
35-
git fetch pr-source "$PR_REF":local
36-
git checkout local
37-
38-
if ! git merge origin/master; then
44+
if ! git merge --no-commit origin/master; then
3945
export YARN_ENABLE_IMMUTABLE_INSTALLS=0
4046
4147
if git diff --name-only --diff-filter=U | grep .pnp.cjs; then
@@ -63,9 +69,58 @@ jobs:
6369
git checkout --theirs packages/yarnpkg-parsers/sources/grammars/shell.js
6470
yarn grammar:shell
6571
fi
66-
67-
git add .pnp.cjs packages/yarnpkg-pnp/sources/hook.js packages/yarnpkg-pnp/sources/esm-loader/built-loader.js packages/yarnpkg-parsers/sources/grammars/shell.js
68-
git commit -m 'Auto-merge with master'
6972
fi
7073
71-
git push pr-source local:"$PR_REF"
74+
yarn test:lint --fix
75+
76+
- name: Generate the artifacts
77+
run: |
78+
git config user.name "Yarn Bot"
79+
git config user.email [email protected]
80+
81+
git diff > merge-conflict-resolution.patch
82+
83+
- name: Store the merge conflict resolution
84+
uses: actions/upload-artifact@v3
85+
with:
86+
name: merge-conflict-resolution
87+
path: merge-conflict-resolution.patch
88+
89+
apply:
90+
name: 'Apply the update changeset'
91+
runs-on: ubuntu-latest
92+
needs: generate
93+
94+
steps:
95+
- uses: actions/checkout@v3
96+
with:
97+
ref: ${{github.event.pull_request.head.sha}}
98+
fetch-depth: 0
99+
100+
- name: Retrieve the merge conflict resolution
101+
uses: actions/download-artifact@v3
102+
with:
103+
name: merge-conflict-resolution
104+
105+
- name: Apply the changeset
106+
env:
107+
GH_BOT_TOKEN: ${{secrets.YARNBOT_TOKEN}}
108+
GH_REPO_NAME: ${{github.event.pull_request.head.repo.full_name}}
109+
GH_HEAD_REF: ${{github.event.pull_request.head.ref}}
110+
run: |
111+
git config user.name "Yarn Bot"
112+
git config user.email [email protected]
113+
114+
git remote add pr-source https://"${GH_BOT_TOKEN}"@github.com/"${GH_REPO_NAME}".git
115+
116+
git fetch pr-source "$GH_HEAD_REF":local
117+
git checkout local
118+
119+
git fetch origin master
120+
git merge --no-commit origin/master || true
121+
git add -A
122+
123+
git apply --allow-empty merge-conflict-resolution.patch
124+
git commit --allow-empty -m 'Auto-merge with master'
125+
126+
git push pr-source local:"$GH_HEAD_REF"

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ yarn-error.log
1515

1616
junit.xml
1717

18+
# This file is generated by the Smart Merge workflow
19+
/merge-conflict-resolution.patch
20+
1821
# The tarballs generated by "yarn pack" are never kept either
1922
package.tgz
2023

packages/yarnpkg-parsers/sources/grammars/shell.js

Lines changed: 52 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/yarnpkg-parsers/sources/grammars/shell.pegjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ GlobText
176176

177177
EnvVariable
178178
= [a-zA-Z0-9_]+ { return text() }
179+
/ [A-Za-z0-9_]+ { return text() }
179180

180181
Identifier
181182
= [$@*?#a-zA-Z0-9_-]+ { return text() }

packages/yarnpkg-pnp/sources/hook.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/yarnpkg-pnp/sources/loader/_entryPoint.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ declare var $$SETUP_STATE: (hrs: typeof hydrateRuntimeState, basePath?: NativePa
1919
const localFs: typeof fs = {...fs};
2020
const nodeFs = new NodeFS(localFs);
2121

22+
// This is just a test, I'll remove it asap
23+
(nodeFs as any).__test = true;
24+
2225
const defaultRuntimeState = $$SETUP_STATE(hydrateRuntimeState);
2326
const defaultPnpapiResolution = __filename;
2427

test.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test

0 commit comments

Comments
 (0)