From 7a21119d1779d8082c47b221eb79bcdcf9a91e19 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 15 Sep 2024 20:33:06 +0200 Subject: [PATCH 1/3] [ticket/17394] Check mergeability of 3.3.x PRs PHPBB-17394 --- .github/workflows/tests.yml | 51 +++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 893c4c4a28..9b55e69771 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -596,3 +596,54 @@ jobs: if: ${{ matrix.type == 'functional' }} run: | phpBB/vendor/bin/phpunit --configuration .github/phpunit-psql-windows-github.xml --verbose --stop-on-error --group functional + + merge-check: + if: github.event.pull_request.base.ref == '3.3.x' + runs-on: ubuntu-latest + steps: + - name: Checkout the repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 # Ensure full history is fetched + + - name: Set up Git user + run: | + git config --global user.name "github-actions" + git config --global user.email "github-actions@github.com" + + - name: Fetch all branches + run: git fetch origin + + - name: Simulate merging PR into 3.3.x + id: simulate_merge + run: | + git checkout 3.3.x + git merge --no-ff ${{ github.event.pull_request.head.sha }} --no-commit --no-ff || exit 1 + + - name: Attempt to merge updated 3.3.x into master + id: merge_master + run: | + git checkout master + if git merge --no-ff origin/3.3.x --no-commit --no-ff; then + echo "::set-output name=mergeable::true" + else + echo "::set-output name=mergeable::false" + git merge --abort + fi + + - name: Post comment on PR + if: always() # Ensure this step always runs, regardless of merge result + uses: peter-evans/create-or-update-comment@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + issue-number: ${{ github.event.pull_request.number }} + body: | + The attempt to merge branch `3.3.x` into `master` has completed after considering the changes in this PR. + + - Merge result: ${{ steps.merge_master.outputs.mergeable == 'true' && 'Success' || 'Conflict' }} + + If there is a conflict, a separate PR will be needed to merge `3.3.x` into `master`. + + - name: Mark job as succeeded + if: always() + run: echo "Merge check completed. Ignoring the result to avoid failed status." From 15556319d951903725cd574d3da7e71b808ab246 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 16 Sep 2024 20:13:16 +0200 Subject: [PATCH 2/3] [ticket/17394] Try using pull_request_target event PHPBB-17394 --- .github/workflows/tests.yml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9b55e69771..6e9b83993a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,10 +13,15 @@ on: - 3.3.x - master - 'prep-release-*' + pull_request_target: + branches: + - 3.3.x + - master jobs: # Basic checks, e.g. parse errors, commit messages, etc. basic-checks: + if: github.event_name != 'pull_request_target' runs-on: ubuntu-22.04 strategy: matrix: @@ -88,6 +93,7 @@ jobs: # Tests for MySQL and MariaDB mysql-tests: + if: github.event_name != 'pull_request_target' runs-on: ubuntu-22.04 strategy: matrix: @@ -231,6 +237,7 @@ jobs: # Tests for PostgreSQL postgres-tests: + if: github.event_name != 'pull_request_target' runs-on: ubuntu-22.04 strategy: matrix: @@ -351,6 +358,7 @@ jobs: # Other database types, namely sqlite3 and mssql other-tests: + if: github.event_name != 'pull_request_target' runs-on: ubuntu-22.04 strategy: matrix: @@ -454,6 +462,7 @@ jobs: # Test with IIS & PostgreSQL on Windows windows-tests: + if: github.event_name != 'pull_request_target' runs-on: windows-latest strategy: matrix: @@ -598,7 +607,7 @@ jobs: phpBB/vendor/bin/phpunit --configuration .github/phpunit-psql-windows-github.xml --verbose --stop-on-error --group functional merge-check: - if: github.event.pull_request.base.ref == '3.3.x' + if: github.event_name == 'pull_request_target' && github.event.pull_request.base.ref == '3.3.x' runs-on: ubuntu-latest steps: - name: Checkout the repository @@ -618,13 +627,13 @@ jobs: id: simulate_merge run: | git checkout 3.3.x - git merge --no-ff ${{ github.event.pull_request.head.sha }} --no-commit --no-ff || exit 1 + git merge --no-ff ${{ github.event.pull_request.head.sha }} || exit 1 - name: Attempt to merge updated 3.3.x into master id: merge_master run: | git checkout master - if git merge --no-ff origin/3.3.x --no-commit --no-ff; then + if git merge --no-ff origin/3.3.x --no-commit; then echo "::set-output name=mergeable::true" else echo "::set-output name=mergeable::false" From e406308244fa7c29633b956bd7b95ec3d8903375 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 16 Sep 2024 20:17:29 +0200 Subject: [PATCH 3/3] [ticket/17394] Specify pull_request_target types PHPBB-17394 --- .github/workflows/tests.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6e9b83993a..36cc997d8b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,6 +14,7 @@ on: - master - 'prep-release-*' pull_request_target: + types: [ opened, synchronize, reopened ] branches: - 3.3.x - master @@ -634,9 +635,9 @@ jobs: run: | git checkout master if git merge --no-ff origin/3.3.x --no-commit; then - echo "::set-output name=mergeable::true" + echo "mergeable=true" >> $GITHUB_OUTPUT else - echo "::set-output name=mergeable::false" + echo "mergeable=false" >> $GITHUB_OUTPUT git merge --abort fi @@ -649,9 +650,9 @@ jobs: body: | The attempt to merge branch `3.3.x` into `master` has completed after considering the changes in this PR. - - Merge result: ${{ steps.merge_master.outputs.mergeable == 'true' && 'Success' || 'Conflict' }} + - Merge result: ${{ steps.merge_master.outputs.mergeable == 'true' && 'Success ✅' || 'Conflict ❌' }} - If there is a conflict, a separate PR will be needed to merge `3.3.x` into `master`. + ${{ steps.merge_master.outputs.mergeable == 'false' && 'A separate PR will be needed to merge `3.3.x` into `master`.' || 'This PR is ready to be merged.' }} - name: Mark job as succeeded if: always()