Skip to content

Commit

Permalink
Implements smart merge v2 (yarnpkg#4177)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanis authored and trivikr committed Mar 9, 2022
1 parent 3edfba5 commit 9c6d6c0
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
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"
File renamed without changes.
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`,
});

0 comments on commit 9c6d6c0

Please sign in to comment.