|
1 | 1 | 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] |
7 | 4 |
|
8 | | -name: 'Smart master merge' |
| 5 | +name: 'Smart merge' |
9 | 6 | jobs: |
10 | | - merge: |
11 | | - name: 'Merge master into the PR' |
| 7 | + reset: |
| 8 | + name: 'Remove the label' |
12 | 9 | runs-on: ubuntu-latest |
| 10 | + if: | |
| 11 | + github.event.label.name == 'infra: pending update' |
13 | 12 |
|
14 | 13 | 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 |
16 | 34 | with: |
17 | | - ref: master |
18 | | - token: ${{secrets.YARNBOT_TOKEN}} |
| 35 | + ref: ${{github.event.pull_request.head.sha}} |
19 | 36 | fetch-depth: 0 |
20 | 37 |
|
21 | 38 | - uses: ./.github/actions/prepare |
22 | 39 |
|
23 | | - - name: 'Update, commit, and upload the artifacts' |
| 40 | + - name: 'Generate the changeset' |
24 | 41 | run: | |
25 | | - PR_META=$(curl https://api.github.com/repos/yarnpkg/berry/pulls/'${{github.event.inputs.pr}}') |
| 42 | + git fetch origin master |
26 | 43 |
|
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 |
39 | 45 | export YARN_ENABLE_IMMUTABLE_INSTALLS=0 |
40 | 46 |
|
41 | 47 | if git diff --name-only --diff-filter=U | grep .pnp.cjs; then |
|
63 | 69 | git checkout --theirs packages/yarnpkg-parsers/sources/grammars/shell.js |
64 | 70 | yarn grammar:shell |
65 | 71 | 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' |
69 | 72 | fi |
70 | 73 |
|
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" |
0 commit comments