From 69604577dc40e6d61d57b4868839194bf16aaf02 Mon Sep 17 00:00:00 2001 From: XDEV Renovate Bot Date: Sun, 26 May 2024 02:24:16 +0000 Subject: [PATCH 01/18] Update dependency maven to v3.9.7 --- .mvn/wrapper/maven-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties index 7f15621..f800e78 100644 --- a/.mvn/wrapper/maven-wrapper.properties +++ b/.mvn/wrapper/maven-wrapper.properties @@ -14,4 +14,4 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.7/apache-maven-3.9.7-bin.zip From f22a35b6327ac7f8c9af16da8b377c5a6770dc5f Mon Sep 17 00:00:00 2001 From: XDEV Renovate Bot Date: Mon, 27 May 2024 02:21:47 +0000 Subject: [PATCH 02/18] Update dependency com.puppycrawl.tools:checkstyle to v10.17.0 --- template-placeholder-demo/pom.xml | 2 +- template-placeholder/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/template-placeholder-demo/pom.xml b/template-placeholder-demo/pom.xml index b319445..f40d02e 100644 --- a/template-placeholder-demo/pom.xml +++ b/template-placeholder-demo/pom.xml @@ -90,7 +90,7 @@ com.puppycrawl.tools checkstyle - 10.16.0 + 10.17.0 diff --git a/template-placeholder/pom.xml b/template-placeholder/pom.xml index b9369a7..36e4236 100644 --- a/template-placeholder/pom.xml +++ b/template-placeholder/pom.xml @@ -230,7 +230,7 @@ com.puppycrawl.tools checkstyle - 10.16.0 + 10.17.0 From 457533698cb76fa8c50b82b99365e23737b843f0 Mon Sep 17 00:00:00 2001 From: AB Date: Mon, 27 May 2024 11:05:40 +0200 Subject: [PATCH 03/18] Only run sonar workflow when secret is present Fixes https://github.com/xdev-software/standard-maven-template/issues/57 --- .github/workflows/sonar.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index 1c9b0f8..061abbd 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -27,7 +27,7 @@ jobs: sonar: name: SonarCloud Scan runs-on: ubuntu-latest - if: ${{ github.event_name != 'pull_request' || !startsWith(github.head_ref, 'renovate/') }} + if: ${{ !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'renovate/')) && secrets.SONAR_TOKEN != '' }} steps: - uses: actions/checkout@v4 with: From 403faee28d7778d19d589fa22e5f502bf4e8ed87 Mon Sep 17 00:00:00 2001 From: AB Date: Mon, 27 May 2024 16:08:06 +0200 Subject: [PATCH 04/18] Secrets are not available in if So let's startup a job before and check it there... You know because efficient design --- .github/workflows/sonar.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index 061abbd..917868b 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -24,10 +24,22 @@ env: SONARCLOUD_HOST: https://sonarcloud.io jobs: + token-check: + runs-on: ubuntu-latest + outputs: + hasToken: ${{ steps.check-token.outputs.has }} + steps: + - id: check-token + run: | + [ -z $SONAR_TOKEN ] && echo "has=false" || echo "has=true" >> "$GITHUB_OUTPUT" + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + sonar: name: SonarCloud Scan runs-on: ubuntu-latest - if: ${{ !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'renovate/')) && secrets.SONAR_TOKEN != '' }} + needs: token-check + if: ${{ !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'renovate/')) && needs.token-check.outputs.hasToken }} steps: - uses: actions/checkout@v4 with: From d562e83d8ff58946f6ef75dcc86ab6ac9c139928 Mon Sep 17 00:00:00 2001 From: XDEV Renovate Bot Date: Tue, 28 May 2024 02:21:58 +0000 Subject: [PATCH 05/18] Update dependency org.sonatype.plugins:nexus-staging-maven-plugin to v1.7.0 --- template-placeholder/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template-placeholder/pom.xml b/template-placeholder/pom.xml index 36e4236..7a44509 100644 --- a/template-placeholder/pom.xml +++ b/template-placeholder/pom.xml @@ -205,7 +205,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.13 + 1.7.0 true ossrh From bef3a777eee48445b3c7c806da17ba7df91d156c Mon Sep 17 00:00:00 2001 From: AB Date: Tue, 28 May 2024 08:23:59 +0200 Subject: [PATCH 06/18] Don't run sonar token check when not required --- .github/workflows/sonar.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index 917868b..7824917 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -26,6 +26,7 @@ env: jobs: token-check: runs-on: ubuntu-latest + if: ${{ !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'renovate/')) }} outputs: hasToken: ${{ steps.check-token.outputs.has }} steps: @@ -35,11 +36,10 @@ jobs: env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - sonar: - name: SonarCloud Scan + sonar-scan: runs-on: ubuntu-latest needs: token-check - if: ${{ !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'renovate/')) && needs.token-check.outputs.hasToken }} + if: ${{ needs.token-check.outputs.hasToken }} steps: - uses: actions/checkout@v4 with: From 8d48e75a2b3bc9535431421a4cd8bfb19c517530 Mon Sep 17 00:00:00 2001 From: AB Date: Tue, 28 May 2024 08:47:01 +0200 Subject: [PATCH 07/18] Compact/Flatten pom on release --- template-placeholder/pom.xml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/template-placeholder/pom.xml b/template-placeholder/pom.xml index 36e4236..d832697 100644 --- a/template-placeholder/pom.xml +++ b/template-placeholder/pom.xml @@ -179,6 +179,23 @@ ossrh + + org.codehaus.mojo + flatten-maven-plugin + 1.6.0 + + ossrh + + + + flatten + process-resources + + flatten + + + + org.apache.maven.plugins maven-gpg-plugin From a16ac0640bc49566cf4ecfcbcfb3d0c35db03c9f Mon Sep 17 00:00:00 2001 From: AB Date: Tue, 28 May 2024 14:09:40 +0200 Subject: [PATCH 08/18] Standardize job names --- .github/workflows/release.yml | 16 ++++++++-------- .github/workflows/test-deploy.yml | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4ad042f..a1e3e8b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,7 +12,7 @@ permissions: pull-requests: write jobs: - check_code: # Validates the code + check-code: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -45,9 +45,9 @@ jobs: exit 1 fi - prepare_release: + prepare-release: runs-on: ubuntu-latest - needs: [check_code] + needs: [check-code] outputs: upload_url: ${{ steps.create_release.outputs.upload_url }} steps: @@ -106,9 +106,9 @@ jobs: ``` - publish_central: # Publish the code to central + publish-maven: runs-on: ubuntu-latest - needs: [prepare_release] + needs: [prepare-release] steps: - uses: actions/checkout@v4 @@ -139,7 +139,7 @@ jobs: publish-pages: runs-on: ubuntu-latest - needs: [prepare_release] + needs: [prepare-release] steps: - uses: actions/checkout@v4 @@ -166,9 +166,9 @@ jobs: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./${{ env.PRIMARY_MAVEN_MODULE }}/target/site - after_release: + after-release: runs-on: ubuntu-latest - needs: [publish_central] + needs: [publish-maven] steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index cdd96cc..9c07de2 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -7,7 +7,7 @@ env: PRIMARY_MAVEN_MODULE: ${{ github.event.repository.name }} jobs: - publish_central: # Publish the code to central + publish-maven: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 From 4de451fa872278bcc682a234014fce0c08e8df88 Mon Sep 17 00:00:00 2001 From: AB Date: Tue, 28 May 2024 14:11:12 +0200 Subject: [PATCH 09/18] Substitute using repo name --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a1e3e8b..9a3c5da 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -93,8 +93,8 @@ jobs: release_name: v${{ steps.version.outputs.release }} commitish: master body: | - ## [Changelog](https://github.com/xdev-software/${{ env.PRIMARY_MAVEN_MODULE }}/blob/develop/CHANGELOG.md#${{ steps.version.outputs.releasenumber }}) - See [Changelog#v${{ steps.version.outputs.release }}](https://github.com/xdev-software/${{ env.PRIMARY_MAVEN_MODULE }}/blob/develop/CHANGELOG.md#${{ steps.version.outputs.releasenumber }}) for more information. + ## [Changelog](https://github.com/${{ github.repository }}/blob/develop/CHANGELOG.md#${{ steps.version.outputs.releasenumber }}) + See [Changelog#v${{ steps.version.outputs.release }}](https://github.com/${{ github.repository }}/blob/develop/CHANGELOG.md#${{ steps.version.outputs.releasenumber }}) for more information. ## Installation Add the following lines to your pom: From 21769fcb17f890c24d9db4909552aa431b0ba947 Mon Sep 17 00:00:00 2001 From: AB Date: Tue, 28 May 2024 14:11:53 +0200 Subject: [PATCH 10/18] Normalize workflow names --- .github/workflows/{checkBuild.yml => check-build.yml} | 0 README.md | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{checkBuild.yml => check-build.yml} (100%) diff --git a/.github/workflows/checkBuild.yml b/.github/workflows/check-build.yml similarity index 100% rename from .github/workflows/checkBuild.yml rename to .github/workflows/check-build.yml diff --git a/README.md b/README.md index 8da47a0..eccf80b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![Latest version](https://img.shields.io/maven-central/v/software.xdev/template-placeholder?logo=apache%20maven)](https://mvnrepository.com/artifact/software.xdev/template-placeholder) -[![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/template-placeholder/checkBuild.yml?branch=develop)](https://github.com/xdev-software/template-placeholder/actions/workflows/checkBuild.yml?query=branch%3Adevelop) +[![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/template-placeholder/check-build.yml?branch=develop)](https://github.com/xdev-software/template-placeholder/actions/workflows/check-build.yml?query=branch%3Adevelop) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=xdev-software_template-placeholder&metric=alert_status)](https://sonarcloud.io/dashboard?id=xdev-software_template-placeholder) # template-placeholder From 7ab86667b9fe51602690b0df081c47848195a834 Mon Sep 17 00:00:00 2001 From: XDEV Renovate Bot Date: Sat, 1 Jun 2024 02:28:02 +0000 Subject: [PATCH 11/18] Update dependency org.apache.maven.plugins:maven-site-plugin to v4.0.0-M15 --- template-placeholder/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template-placeholder/pom.xml b/template-placeholder/pom.xml index a1a300d..7a5c2dc 100644 --- a/template-placeholder/pom.xml +++ b/template-placeholder/pom.xml @@ -90,7 +90,7 @@ org.apache.maven.plugins maven-site-plugin - 4.0.0-M14 + 4.0.0-M15 org.apache.maven.plugins From 3b682e831f3f596ed23ba3ff2a643ea4ac6301fd Mon Sep 17 00:00:00 2001 From: XDEV Renovate Bot Date: Sat, 1 Jun 2024 02:28:04 +0000 Subject: [PATCH 12/18] Update dependency org.apache.maven.plugins:maven-javadoc-plugin to v3.7.0 --- template-placeholder/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template-placeholder/pom.xml b/template-placeholder/pom.xml index a1a300d..0046bdb 100644 --- a/template-placeholder/pom.xml +++ b/template-placeholder/pom.xml @@ -143,7 +143,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.6.3 + 3.7.0 attach-javadocs From 0a48eeec49daec9938b1f9758a14eff4b82be2be Mon Sep 17 00:00:00 2001 From: AB Date: Mon, 3 Jun 2024 14:45:56 +0200 Subject: [PATCH 13/18] Update update-from-template.yml https://github.com/xdev-software/java-template/issues/8 --- .github/workflows/update-from-template.yml | 209 +++++++++++++++++++-- 1 file changed, 193 insertions(+), 16 deletions(-) diff --git a/.github/workflows/update-from-template.yml b/.github/workflows/update-from-template.yml index 41a1bcd..3157785 100644 --- a/.github/workflows/update-from-template.yml +++ b/.github/workflows/update-from-template.yml @@ -11,9 +11,15 @@ on: schedule: - cron: '55 2 * * 1' workflow_dispatch: + inputs: + no_automatic_merge: + type: boolean + description: 'No automatic merge' + default: false env: UPDATE_BRANCH: update-from-template + UPDATE_BRANCH_MERGED: update-from-template-merged REMOTE_URL: https://github.com/xdev-software/java-template.git REMOTE_BRANCH: master @@ -36,11 +42,11 @@ jobs: - name: Init Git run: | - git config --global user.email "actions@github.com" - git config --global user.name "GitHub Actions" + git config --global user.email "111048771+xdev-gh-bot@users.noreply.github.com" + git config --global user.name "XDEV Bot" - - name: Main workflow - id: main + - name: Manage branches + id: manage-branches run: | echo "Adding remote template-repo" git remote add template ${{ env.REMOTE_URL }} @@ -48,8 +54,9 @@ jobs: echo "Fetching remote template repo" git fetch template - echo "Deleting local branch that will contain the updates - if present" + echo "Deleting local branches that will contain the updates - if present" git branch -D ${{ env.UPDATE_BRANCH }} || true + git branch -D ${{ env.UPDATE_BRANCH_MERGED }} || true echo "Checking if the remote template repo has new commits" git rev-list ..template/${{ env.REMOTE_BRANCH }} @@ -57,10 +64,12 @@ jobs: if [ $(git rev-list --count ..template/${{ env.REMOTE_BRANCH }}) -eq 0 ]; then echo "There are no commits new commits on the template repo" - echo "Deleting origin branch that contains the updates - if present" + echo "Deleting origin branch(es) that contain the updates - if present" git push -f origin --delete ${{ env.UPDATE_BRANCH }} || true + git push -f origin --delete ${{ env.UPDATE_BRANCH_MERGED }} || true - echo "abort=1" >> $GITHUB_OUTPUT + echo "create_update_branch_pr=0" >> $GITHUB_OUTPUT + echo "create_update_branch_merged_pr=0" >> $GITHUB_OUTPUT exit 0 fi @@ -73,21 +82,189 @@ jobs: echo "Pushing update branch" git push -f -u origin ${{ env.UPDATE_BRANCH }} - echo "Getting current branch" - current_branch=$(git branch --show-current) - echo "Current branch is $current_branch" - echo "current_branch=$current_branch" >> $GITHUB_OUTPUT + echo "Getting base branch" + base_branch=$(git branch --show-current) + echo "Base branch is $base_branch" + echo "base_branch=$base_branch" >> $GITHUB_OUTPUT - echo "abort=0" >> $GITHUB_OUTPUT + echo "Trying to create auto-merged branch ${{ env.UPDATE_BRANCH_MERGED }}" + git branch ${{ env.UPDATE_BRANCH_MERGED }} ${{ env.UPDATE_BRANCH }} + git checkout ${{ env.UPDATE_BRANCH_MERGED }} - - name: pull-request - if: steps.main.outputs.abort == 0 + echo "Merging branch $base_branch into ${{ env.UPDATE_BRANCH_MERGED }}" + git merge $base_branch && merge_exit_code=$? || merge_exit_code=$? + if [ $merge_exit_code -ne 0 ]; then + echo "Auto merge failed! Manual merge required" + echo "::notice ::Auto merge failed - Manual merge required" + + echo "Cleaning up failed merge" + git merge --abort + git checkout $base_branch + git branch -D ${{ env.UPDATE_BRANCH_MERGED }} || true + + echo "Deleting auto-merge branch - if present" + git push -f origin --delete ${{ env.UPDATE_BRANCH_MERGED }} || true + + echo "create_update_branch_pr=1" >> $GITHUB_OUTPUT + echo "create_update_branch_merged_pr=0" >> $GITHUB_OUTPUT + exit 0 + fi + + echo "Post processing: Trying to automatically fill in template variables" + find . -type f \ + -not -path "./.git/**" \ + -not -path "./.github/workflows/update-from-template.yml" -print0 \ + | xargs -0 sed -i "s/template-placeholder/${GITHUB_REPOSITORY#*/}/g" + + git status + git add --all + + if [[ "$(git status --porcelain)" != "" ]]; then + echo "Filled in template; Committing" + + git commit -m "Fill in template" + fi + + echo "Pushing auto-merged branch" + git push -f -u origin ${{ env.UPDATE_BRANCH_MERGED }} + + echo "update_branch_merged_commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT + + echo "Restoring base branch $base_branch" + git checkout $base_branch + + echo "create_update_branch_pr=0" >> $GITHUB_OUTPUT + echo "create_update_branch_merged_pr=1" >> $GITHUB_OUTPUT + + - name: PR update_branch + if: steps.manage-branches.outputs.create_update_branch_pr == 1 env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }} run: | gh_pr_up() { gh pr create -H "${{ env.UPDATE_BRANCH }}" "$@" || (git checkout "${{ env.UPDATE_BRANCH }}" && gh pr edit "$@") } - gh_pr_up -B "${{ steps.main.outputs.current_branch }}" \ + gh_pr_up -B "${{ steps.manage-branches.outputs.base_branch }}" \ --title "Update from template" \ --body "An automated PR to sync changes from the template into this repo" + + - name: PR update_branch_merged + if: steps.manage-branches.outputs.create_update_branch_merged_pr == 1 + env: + GH_TOKEN: ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }} + run: | + gh_pr_up() { + gh pr create -H "${{ env.UPDATE_BRANCH_MERGED }}" "$@" || (git checkout "${{ env.UPDATE_BRANCH_MERGED }}" && gh pr edit "$@") + } + gh_pr_up -B "${{ steps.manage-branches.outputs.base_branch }}" \ + --title "Update from template (auto-merged)" \ + --body "An automated PR to sync changes from the template into this repo" + + - name: Checking if auto-merge for PR update_branch_merged can be done + id: auto-merge-check + if: steps.manage-branches.outputs.create_update_branch_merged_pr == 1 + env: + GH_TOKEN: ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }} + run: | + not_failed_conclusion="skipped|neutral|success" + not_relevant_app_slug="dependabot" + + echo "Waiting for workflows to start..." + sleep 60s + + for i in {1..15}; do + echo "Checking if PR can be auto-merged. Try: $i" + + echo "Fetching checks" + cs_response=$(curl -sL \ + --fail-with-body \ + --connect-timeout 60 \ + --max-time 120 \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer $GH_TOKEN" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/${{ github.repository }}/commits/${{ steps.manage-branches.outputs.update_branch_merged_commit }}/check-suites) + + cs_data=$(echo $cs_response | jq '.check_suites[] | { conclusion: .conclusion, slug: .app.slug, check_runs_url: .check_runs_url }') + echo $cs_data + + if [[ -z "$cs_data" ]]; then + echo "No check suite data - Assuming that there are no checks to run" + + echo "perform=1" >> $GITHUB_OUTPUT + exit 0 + fi + + cs_failed=$(echo $cs_data | jq --arg x "$not_failed_conclusion" 'select ((.conclusion == null or (.conclusion | test($x))) | not)') + if [[ -z "$cs_failed" ]]; then + echo "No check failed so far; Checking if relevant checks are still running" + + cs_relevant_still_running=$(echo $cs_data | jq --arg x "$not_relevant_app_slug" 'select (.conclusion == null and (.slug | test($x) | not))') + if [[ -z $cs_relevant_still_running ]]; then + echo "All relevant checks finished - PR can be merged" + + echo "perform=1" >> $GITHUB_OUTPUT + exit 0 + else + echo "Relevant checks are still running" + echo $cs_relevant_still_running + fi + else + echo "Detected failed check" + echo $cs_failed + + echo "perform=0" >> $GITHUB_OUTPUT + exit 0 + fi + + echo "Waiting before next run..." + sleep 60s + done + + echo "Timed out" + echo "perform=0" >> $GITHUB_OUTPUT + + - name: Auto-merge update_branch_merged + if: steps.auto-merge-check.outputs.perform == 1 + run: | + base_branch="${{ steps.manage-branches.outputs.base_branch }}" + echo "Restoring base branch $base_branch" + git checkout $base_branch + + echo "Fetching..." + git fetch + + expected_commit="${{ steps.manage-branches.outputs.update_branch_merged_commit }}" + actual_commit=$(git rev-parse origin/${{ env.UPDATE_BRANCH_MERGED }}) + if [[ "$expected_commit" != "$actual_commit" ]]; then + echo "Branch ${{ env.UPDATE_BRANCH_MERGED }} contains unexpected commit $actual_commit" + echo "Expected: $expected_commit" + + exit 0 + fi + + echo "Ensuring that current branch $base_branch is up-to-date" + git pull + + echo "Merging ${{ env.UPDATE_BRANCH_MERGED }} into $base_branch" + git merge ${{ env.UPDATE_BRANCH_MERGED }} && merge_exit_code=$? || merge_exit_code=$? + if [ $merge_exit_code -ne 0 ]; then + echo "Unexpected merge failure $merge_exit_code - Requires manual resolution" + + exit 0 + fi + + if [[ "${{ inputs.no_automatic_merge }}" == "true" ]]; then + echo "Exiting due no_automatic_merge" + + exit 0 + fi + + echo "Pushing" + git push + + echo "Cleaning up" + git branch -D ${{ env.UPDATE_BRANCH }} || true + git branch -D ${{ env.UPDATE_BRANCH_MERGED }} || true + git push -f origin --delete ${{ env.UPDATE_BRANCH }} || true + git push -f origin --delete ${{ env.UPDATE_BRANCH_MERGED }} || true From b68fe4193432c2559bcc8480d1b502b8e3bfe188 Mon Sep 17 00:00:00 2001 From: AB Date: Mon, 3 Jun 2024 14:59:51 +0200 Subject: [PATCH 14/18] Ignore github pages --- .github/workflows/update-from-template.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-from-template.yml b/.github/workflows/update-from-template.yml index 3157785..1d60c77 100644 --- a/.github/workflows/update-from-template.yml +++ b/.github/workflows/update-from-template.yml @@ -167,7 +167,7 @@ jobs: GH_TOKEN: ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }} run: | not_failed_conclusion="skipped|neutral|success" - not_relevant_app_slug="dependabot" + not_relevant_app_slug="dependabot|github-pages" echo "Waiting for workflows to start..." sleep 60s From dbbac6832830f480103f195afd7382812a0c7ddc Mon Sep 17 00:00:00 2001 From: AB Date: Mon, 3 Jun 2024 15:17:07 +0200 Subject: [PATCH 15/18] Update update-from-template.yml https://github.com/xdev-software/java-template/issues/8 --- .github/workflows/update-from-template.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/update-from-template.yml b/.github/workflows/update-from-template.yml index 1d60c77..cf23b4f 100644 --- a/.github/workflows/update-from-template.yml +++ b/.github/workflows/update-from-template.yml @@ -1,9 +1,10 @@ name: Update from Template # This workflow keeps the repo up to date with changes from the template repo (REMOTE_URL) -# It duplicates the REMOTE_BRANCH (into UPDATE_BRANCH) and tries to merge it into the +# It duplicates the REMOTE_BRANCH (into UPDATE_BRANCH) and tries to merge it into # this repos default branch (which is checked out here) # Note that this requires a PAT (Personal Access Token) - at best from a servicing account +# PAT permissions: read:discussion, read:org, repo, workflow # Also note that you should have at least once merged the template repo into the current repo manually # otherwise a "refusing to merge unrelated histories" error might occur. @@ -135,8 +136,9 @@ jobs: echo "create_update_branch_pr=0" >> $GITHUB_OUTPUT echo "create_update_branch_merged_pr=1" >> $GITHUB_OUTPUT + echo "try_close_update_branch_pr=1" >> $GITHUB_OUTPUT - - name: PR update_branch + - name: Create/Update PR update_branch if: steps.manage-branches.outputs.create_update_branch_pr == 1 env: GH_TOKEN: ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }} @@ -147,8 +149,16 @@ jobs: gh_pr_up -B "${{ steps.manage-branches.outputs.base_branch }}" \ --title "Update from template" \ --body "An automated PR to sync changes from the template into this repo" + + # Ensure that only a single PR is open (otherwise confusion and spam) + - name: Close PR update_branch + if: steps.manage-branches.outputs.try_close_update_branch_pr == 1 + env: + GH_TOKEN: ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }} + run: | + gh pr close "${{ env.UPDATE_BRANCH }}" || true - - name: PR update_branch_merged + - name: Create/Update PR update_branch_merged if: steps.manage-branches.outputs.create_update_branch_merged_pr == 1 env: GH_TOKEN: ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }} From a96e946f81379f189a57e3188d9e2e23d472e4c3 Mon Sep 17 00:00:00 2001 From: AB Date: Mon, 3 Jun 2024 16:48:26 +0200 Subject: [PATCH 16/18] Update update-from-template.yml Split into 2 jobs to help with expected executor starvation --- .github/workflows/update-from-template.yml | 49 ++++++++++++++++------ 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/.github/workflows/update-from-template.yml b/.github/workflows/update-from-template.yml index cf23b4f..cfebf39 100644 --- a/.github/workflows/update-from-template.yml +++ b/.github/workflows/update-from-template.yml @@ -31,7 +31,9 @@ permissions: jobs: update: runs-on: ubuntu-latest - + outputs: + update_branch_merged_commit: ${{ steps.manage-branches.outputs.update_branch_merged_commit }} + create_update_branch_merged_pr: ${{ steps.manage-branches.outputs.create_update_branch_merged_pr }} steps: - uses: actions/checkout@v4 with: @@ -169,20 +171,41 @@ jobs: gh_pr_up -B "${{ steps.manage-branches.outputs.base_branch }}" \ --title "Update from template (auto-merged)" \ --body "An automated PR to sync changes from the template into this repo" + + # Wait a moment so that checks of PR have higher prio than following job + sleep 3 + + # Split into two jobs to help with executor starvation + auto-merge: + needs: [update] + if: needs.update.outputs.create_update_branch_merged_pr == 1 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + # Required because otherwise there are always changes detected when executing diff/rev-list + fetch-depth: 0 + # If no PAT is used the following error occurs on a push: + # refusing to allow a GitHub App to create or update workflow `.github/workflows/xxx.yml` without `workflows` permission + token: ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }} + + - name: Init Git + run: | + git config --global user.email "111048771+xdev-gh-bot@users.noreply.github.com" + git config --global user.name "XDEV Bot" - name: Checking if auto-merge for PR update_branch_merged can be done id: auto-merge-check - if: steps.manage-branches.outputs.create_update_branch_merged_pr == 1 env: GH_TOKEN: ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }} run: | not_failed_conclusion="skipped|neutral|success" not_relevant_app_slug="dependabot|github-pages" - echo "Waiting for workflows to start..." - sleep 60s + echo "Waiting for checks to start..." + sleep 40s - for i in {1..15}; do + for i in {1..20}; do echo "Checking if PR can be auto-merged. Try: $i" echo "Fetching checks" @@ -193,7 +216,7 @@ jobs: -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer $GH_TOKEN" \ -H "X-GitHub-Api-Version: 2022-11-28" \ - https://api.github.com/repos/${{ github.repository }}/commits/${{ steps.manage-branches.outputs.update_branch_merged_commit }}/check-suites) + https://api.github.com/repos/${{ github.repository }}/commits/${{ needs.update.outputs.update_branch_merged_commit }}/check-suites) cs_data=$(echo $cs_response | jq '.check_suites[] | { conclusion: .conclusion, slug: .app.slug, check_runs_url: .check_runs_url }') echo $cs_data @@ -228,7 +251,7 @@ jobs: fi echo "Waiting before next run..." - sleep 60s + sleep 30s done echo "Timed out" @@ -237,14 +260,14 @@ jobs: - name: Auto-merge update_branch_merged if: steps.auto-merge-check.outputs.perform == 1 run: | - base_branch="${{ steps.manage-branches.outputs.base_branch }}" - echo "Restoring base branch $base_branch" - git checkout $base_branch + echo "Getting base branch" + base_branch=$(git branch --show-current) + echo "Base branch is $base_branch" echo "Fetching..." git fetch - expected_commit="${{ steps.manage-branches.outputs.update_branch_merged_commit }}" + expected_commit="${{ needs.update.outputs.update_branch_merged_commit }}" actual_commit=$(git rev-parse origin/${{ env.UPDATE_BRANCH_MERGED }}) if [[ "$expected_commit" != "$actual_commit" ]]; then echo "Branch ${{ env.UPDATE_BRANCH_MERGED }} contains unexpected commit $actual_commit" @@ -256,8 +279,8 @@ jobs: echo "Ensuring that current branch $base_branch is up-to-date" git pull - echo "Merging ${{ env.UPDATE_BRANCH_MERGED }} into $base_branch" - git merge ${{ env.UPDATE_BRANCH_MERGED }} && merge_exit_code=$? || merge_exit_code=$? + echo "Merging origin/${{ env.UPDATE_BRANCH_MERGED }} into $base_branch" + git merge origin/${{ env.UPDATE_BRANCH_MERGED }} && merge_exit_code=$? || merge_exit_code=$? if [ $merge_exit_code -ne 0 ]; then echo "Unexpected merge failure $merge_exit_code - Requires manual resolution" From 8aef4988554ac2fe092b93900105d55be9664e4e Mon Sep 17 00:00:00 2001 From: AB Date: Mon, 3 Jun 2024 17:03:16 +0200 Subject: [PATCH 17/18] Update update-from-template.yml --- .github/workflows/update-from-template.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/update-from-template.yml b/.github/workflows/update-from-template.yml index cfebf39..57a6cdd 100644 --- a/.github/workflows/update-from-template.yml +++ b/.github/workflows/update-from-template.yml @@ -200,7 +200,7 @@ jobs: GH_TOKEN: ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }} run: | not_failed_conclusion="skipped|neutral|success" - not_relevant_app_slug="dependabot|github-pages" + not_relevant_app_slug="dependabot|github-pages|sonarcloud" echo "Waiting for checks to start..." sleep 40s @@ -254,8 +254,8 @@ jobs: sleep 30s done - echo "Timed out" - echo "perform=0" >> $GITHUB_OUTPUT + echo "Timed out - Assuming executor starvation - Forcing merge" + echo "perform=1" >> $GITHUB_OUTPUT - name: Auto-merge update_branch_merged if: steps.auto-merge-check.outputs.perform == 1 From e48734d3d797a563dd75eb0fa8c6c5af2bd52b50 Mon Sep 17 00:00:00 2001 From: AB Date: Tue, 4 Jun 2024 08:33:31 +0200 Subject: [PATCH 18/18] Update update-from-template.yml Handle PR merges before workflow finishes --- .github/workflows/update-from-template.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/update-from-template.yml b/.github/workflows/update-from-template.yml index 57a6cdd..756607d 100644 --- a/.github/workflows/update-from-template.yml +++ b/.github/workflows/update-from-template.yml @@ -208,6 +208,13 @@ jobs: for i in {1..20}; do echo "Checking if PR can be auto-merged. Try: $i" + echo "Checking if update-branch-merged exists" + git fetch + if [[ $(git rev-parse origin/${{ env.UPDATE_BRANCH_MERGED }}) ]]; then + echo "Branch origin/${{ env.UPDATE_BRANCH_MERGED }} is missing" + exit 0 + fi + echo "Fetching checks" cs_response=$(curl -sL \ --fail-with-body \ @@ -266,6 +273,10 @@ jobs: echo "Fetching..." git fetch + if [[ $(git rev-parse origin/${{ env.UPDATE_BRANCH_MERGED }}) ]]; then + echo "Branch origin/${{ env.UPDATE_BRANCH_MERGED }} is missing" + exit 0 + fi expected_commit="${{ needs.update.outputs.update_branch_merged_commit }}" actual_commit=$(git rev-parse origin/${{ env.UPDATE_BRANCH_MERGED }})