Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements smart merge v2 #4177

Merged
merged 1 commit into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .github/workflows/pr-smart-merge-apply.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
on:
workflow_run:
workflows: ['Smart merge: Generate']
types:
- completed

name: 'Smart merge: Apply'
jobs:
apply:
name: 'Apply the update changeset'
runs-on: ubuntu-latest
if: |
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'

steps:
- uses: actions/checkout@v3
with:
ref: ${{github.event.workflow_run.head_sha}}

- name: 'Download the artifacts'
uses: actions/github-script@v3
with:
script: |
const fs = require(`fs`);

const artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id}},
});

const matchArtifact = artifacts.data.artifacts.filter(artifact => {
return artifact.name == `pr`;
})[0];

const download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: `zip`,
});

fs.writeFileSync(`${{github.workspace}}/pr.zip`, Buffer.from(download.data));

- name: Unpack the artifacts
run: unzip pr.zip

- name: Apply the changeset
run: |
PR_META=$(curl https://api.github.com/repos/yarnpkg/berry/pulls/'${{github.event.inputs.pr}}')

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 --depth=1 pr-source "$PR_REF":local
git checkout local

git merge --no-commit origin/master || true
git apply pr/update.patch
git commit -m 'Auto-merge with master'

git push pr-source local:"$PR_REF"
Original file line number Diff line number Diff line change
@@ -1,41 +1,24 @@
on:
workflow_dispatch:
inputs:
pr:
description: 'The pull request to update'
required: true
pull_request:
types: [labeled]

name: 'Smart master merge'
name: 'Smart merge: Generate'
jobs:
merge:
name: 'Merge master into the PR'
generate:
name: 'Generate an update changeset'
runs-on: ubuntu-latest
if: |
github.event.label.name == 'infra: pending update'

steps:
- uses: actions/checkout@master
with:
ref: master
token: ${{secrets.YARNBOT_TOKEN}}
fetch-depth: 0

- uses: actions/checkout@v3
- 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}}')

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
git fetch --depth=0 origin master

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 +46,17 @@ 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: |
mkdir -p pr
git diff > pr/update.patch

- name: Upload the artifacts
uses: actions/upload-artifact@v2
with:
name: pr
path: pr/
23 changes: 23 additions & 0 deletions .github/workflows/pr-smart-merge-reset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
on:
pull_request_target:
types: [labeled]

name: 'Smart merge: Reset'
jobs:
generate:
name: 'Remove the label'
runs-on: ubuntu-latest
if: |
github.event.label.name == 'infra: pending update'

steps:
- name: 'Remove the label'
uses: actions/github-script@v3
with:
script: |
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.pull_request.number,
name: `infra: pending update`,
});