Skip to content

Commit

Permalink
Implements smart merge v2 (#4177)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanis committed Mar 7, 2022
1 parent 26beba7 commit c225c1f
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 50 deletions.
113 changes: 84 additions & 29 deletions .github/workflows/pr-smart-merge.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,47 @@
on:
workflow_dispatch:
inputs:
pr:
description: 'The pull request to update'
required: true
pull_request_target:
types: [labeled]

name: 'Smart master merge'
name: 'Smart merge'
jobs:
merge:
name: 'Merge master into the PR'
reset:
name: 'Remove the label'
runs-on: ubuntu-latest
if: |
github.event.label.name == 'infra: pending update'
steps:
- uses: actions/checkout@master
- name: 'Remove the label'
uses: actions/github-script@v6
with:
script: |
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: context.payload.label.name,
});
generate:
name: 'Generate an update changeset'
runs-on: ubuntu-latest
needs: reset
permissions:
contents: read

steps:
- uses: actions/checkout@v3
with:
ref: master
token: ${{secrets.YARNBOT_TOKEN}}
ref: ${{github.event.pull_request.head.sha}}
fetch-depth: 0

- uses: ./.github/actions/prepare

- name: 'Update, commit, and upload the artifacts'
- name: 'Generate the changeset'
run: |
PR_META=$(curl https://api.github.com/repos/yarnpkg/berry/pulls/'${{github.event.inputs.pr}}')
git fetch origin master
PR_REPO=$(jq -r .head.repo.full_name <<< "$PR_META")
PR_REF=$(jq -r .head.ref <<< "$PR_META")
git config user.name "Yarn Bot"
git config user.email [email protected]
git remote add pr-source https://'${{secrets.YARNBOT_TOKEN}}'@github.com/"$PR_REPO".git
git fetch pr-source "$PR_REF":local
git checkout local
if ! git merge origin/master; then
if ! git merge --no-commit origin/master; then
export YARN_ENABLE_IMMUTABLE_INSTALLS=0
if git diff --name-only --diff-filter=U | grep .pnp.cjs; then
Expand Down Expand Up @@ -63,9 +69,58 @@ jobs:
git checkout --theirs packages/yarnpkg-parsers/sources/grammars/shell.js
yarn grammar:shell
fi
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
git commit -m 'Auto-merge with master'
fi
git push pr-source local:"$PR_REF"
yarn test:lint --fix
- name: Generate the artifacts
run: |
git config user.name "Yarn Bot"
git config user.email [email protected]
git diff > merge-conflict-resolution.patch
- name: Store the merge conflict resolution
uses: actions/upload-artifact@v3
with:
name: merge-conflict-resolution
path: merge-conflict-resolution.patch

apply:
name: 'Apply the update changeset'
runs-on: ubuntu-latest
needs: generate

steps:
- uses: actions/checkout@v3
with:
ref: ${{github.event.pull_request.head.sha}}
fetch-depth: 0

- name: Retrieve the merge conflict resolution
uses: actions/download-artifact@v3
with:
name: merge-conflict-resolution

- name: Apply the changeset
env:
GH_BOT_TOKEN: ${{secrets.YARNBOT_TOKEN}}
GH_REPO_NAME: ${{github.event.pull_request.head.repo.full_name}}
GH_HEAD_REF: ${{github.event.pull_request.head.ref}}
run: |
git config user.name "Yarn Bot"
git config user.email [email protected]
git remote add pr-source https://"${GH_BOT_TOKEN}"@github.com/"${GH_REPO_NAME}".git
git fetch pr-source "$GH_HEAD_REF":local
git checkout local
git fetch origin master
git merge --no-commit origin/master || true
git add -A
git apply --allow-empty merge-conflict-resolution.patch
git commit --allow-empty -m 'Auto-merge with master'
git push pr-source local:"$GH_HEAD_REF"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ yarn-error.log

junit.xml

# This file is generated by the Smart Merge workflow
/merge-conflict-resolution.patch

# The tarballs generated by "yarn pack" are never kept either
package.tgz

Expand Down
72 changes: 52 additions & 20 deletions packages/yarnpkg-parsers/sources/grammars/shell.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/yarnpkg-parsers/sources/grammars/shell.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ GlobText

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

Identifier
= [$@*?#a-zA-Z0-9_-]+ { return text() }
Expand Down
2 changes: 1 addition & 1 deletion packages/yarnpkg-pnp/sources/hook.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions packages/yarnpkg-pnp/sources/loader/_entryPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ declare var $$SETUP_STATE: (hrs: typeof hydrateRuntimeState, basePath?: NativePa
const localFs: typeof fs = {...fs};
const nodeFs = new NodeFS(localFs);

// This is just a test, I'll remove it asap
(nodeFs as any).__test = true;

const defaultRuntimeState = $$SETUP_STATE(hydrateRuntimeState);
const defaultPnpapiResolution = __filename;

Expand Down
1 change: 1 addition & 0 deletions test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test

1 comment on commit c225c1f

@merceyz
Copy link
Member

@merceyz merceyz commented on c225c1f Mar 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some leftover tests in here @arcanis

Please sign in to comment.