on: pull_request_target: types: [labeled] name: 'Smart merge' jobs: reset: 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@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@v4 with: ref: ${{github.event.pull_request.head.sha}} fetch-depth: 0 - uses: ./.github/actions/prepare - name: 'Generate the changeset' run: | git fetch origin master 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 # We use a prebuilt binary so that we don't have to deal with new/removed dependencies YARN_ENABLE_STRICT_SETTINGS=0 YARN_IGNORE_PATH=1 node packages/yarnpkg-cli/bundles/yarn.js fi if git diff --name-only --diff-filter=U | grep packages/yarnpkg-pnp/sources/hook.js; then git checkout --theirs packages/yarnpkg-pnp/sources/hook.js yarn build:pnp:hook SHOULD_RUN_AN_INSTALL=1 fi if git diff --name-only --diff-filter=U | grep packages/yarnpkg-pnp/sources/esm-loader/built-loader.js; then git checkout --theirs packages/yarnpkg-pnp/sources/esm-loader/built-loader.js yarn build:pnp:hook SHOULD_RUN_AN_INSTALL=1 fi if [[ "$SHOULD_RUN_AN_INSTALL" == "1" ]]; then yarn install fi if git diff --name-only --diff-filter=U | grep packages/yarnpkg-parsers/sources/grammars/shell.js; then git checkout --theirs packages/yarnpkg-parsers/sources/grammars/shell.js yarn grammar:shell fi fi yarn test:lint --fix - name: Generate the artifacts run: | git config user.name "Yarn Bot" git config user.email nison.mael+yarnbot@gmail.com git diff > merge-conflict-resolution.patch - name: Store the merge conflict resolution uses: actions/upload-artifact@v4 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@v4 with: ref: ${{github.event.pull_request.head.sha}} fetch-depth: 0 - name: Retrieve the merge conflict resolution uses: actions/download-artifact@v4 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 nison.mael+yarnbot@gmail.com 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"