Skip to content

Commit d45d8f8

Browse files
committed
Merge remote-tracking branch 'origin/update-from-template' into develop
2 parents 0119c07 + 100b498 commit d45d8f8

File tree

7 files changed

+239
-35
lines changed

7 files changed

+239
-35
lines changed
File renamed without changes.

.github/workflows/release.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ permissions:
1212
pull-requests: write
1313

1414
jobs:
15-
check_code: # Validates the code
15+
check-code:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- uses: actions/checkout@v4
@@ -45,9 +45,9 @@ jobs:
4545
exit 1
4646
fi
4747
48-
prepare_release:
48+
prepare-release:
4949
runs-on: ubuntu-latest
50-
needs: [check_code]
50+
needs: [check-code]
5151
outputs:
5252
upload_url: ${{ steps.create_release.outputs.upload_url }}
5353
steps:
@@ -93,8 +93,8 @@ jobs:
9393
release_name: v${{ steps.version.outputs.release }}
9494
commitish: master
9595
body: |
96-
## [Changelog](https://github.com/xdev-software/${{ env.PRIMARY_MAVEN_MODULE }}/blob/develop/CHANGELOG.md#${{ steps.version.outputs.releasenumber }})
97-
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.
96+
## [Changelog](https://github.com/${{ github.repository }}/blob/develop/CHANGELOG.md#${{ steps.version.outputs.releasenumber }})
97+
See [Changelog#v${{ steps.version.outputs.release }}](https://github.com/${{ github.repository }}/blob/develop/CHANGELOG.md#${{ steps.version.outputs.releasenumber }}) for more information.
9898
9999
## Installation
100100
Add the following lines to your pom:
@@ -106,9 +106,9 @@ jobs:
106106
</dependency>
107107
```
108108
109-
publish_central: # Publish the code to central
109+
publish-maven:
110110
runs-on: ubuntu-latest
111-
needs: [prepare_release]
111+
needs: [prepare-release]
112112
steps:
113113
- uses: actions/checkout@v4
114114

@@ -139,7 +139,7 @@ jobs:
139139

140140
publish-pages:
141141
runs-on: ubuntu-latest
142-
needs: [prepare_release]
142+
needs: [prepare-release]
143143
steps:
144144
- uses: actions/checkout@v4
145145

@@ -166,9 +166,9 @@ jobs:
166166
github_token: ${{ secrets.GITHUB_TOKEN }}
167167
publish_dir: ./${{ env.PRIMARY_MAVEN_MODULE }}/target/site
168168

169-
after_release:
169+
after-release:
170170
runs-on: ubuntu-latest
171-
needs: [publish_central]
171+
needs: [publish-maven]
172172
steps:
173173
- uses: actions/checkout@v4
174174

.github/workflows/sonar.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ env:
2626
jobs:
2727
token-check:
2828
runs-on: ubuntu-latest
29+
if: ${{ !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'renovate/')) }}
2930
outputs:
3031
hasToken: ${{ steps.check-token.outputs.has }}
3132
steps:
@@ -35,11 +36,10 @@ jobs:
3536
env:
3637
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
3738

38-
sonar:
39-
name: SonarCloud Scan
39+
sonar-scan:
4040
runs-on: ubuntu-latest
4141
needs: token-check
42-
if: ${{ !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'renovate/')) && needs.token-check.outputs.hasToken }}
42+
if: ${{ needs.token-check.outputs.hasToken }}
4343
steps:
4444
- uses: actions/checkout@v4
4545
with:

.github/workflows/test-deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ env:
77
PRIMARY_MAVEN_MODULE: ${{ github.event.repository.name }}
88

99
jobs:
10-
publish_central: # Publish the code to central
10+
publish-maven:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v4

.github/workflows/update-from-template.yml

Lines changed: 204 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
name: Update from Template
22

33
# This workflow keeps the repo up to date with changes from the template repo (REMOTE_URL)
4-
# It duplicates the REMOTE_BRANCH (into UPDATE_BRANCH) and tries to merge it into the
4+
# It duplicates the REMOTE_BRANCH (into UPDATE_BRANCH) and tries to merge it into
55
# this repos default branch (which is checked out here)
66
# Note that this requires a PAT (Personal Access Token) - at best from a servicing account
7+
# PAT permissions: read:discussion, read:org, repo, workflow
78
# Also note that you should have at least once merged the template repo into the current repo manually
89
# otherwise a "refusing to merge unrelated histories" error might occur.
910

1011
on:
1112
schedule:
1213
- cron: '55 2 * * 1'
1314
workflow_dispatch:
15+
inputs:
16+
no_automatic_merge:
17+
type: boolean
18+
description: 'No automatic merge'
19+
default: false
1420

1521
env:
1622
UPDATE_BRANCH: update-from-template
23+
UPDATE_BRANCH_MERGED: update-from-template-merged
1724
REMOTE_URL: https://github.com/xdev-software/standard-maven-template.git
1825
REMOTE_BRANCH: master
1926

@@ -36,31 +43,34 @@ jobs:
3643

3744
- name: Init Git
3845
run: |
39-
git config --global user.email "actions@github.com"
40-
git config --global user.name "GitHub Actions"
46+
git config --global user.email "111048771+xdev-gh-bot@users.noreply.github.com"
47+
git config --global user.name "XDEV Bot"
4148
42-
- name: Main workflow
43-
id: main
49+
- name: Manage branches
50+
id: manage-branches
4451
run: |
4552
echo "Adding remote template-repo"
4653
git remote add template ${{ env.REMOTE_URL }}
4754
4855
echo "Fetching remote template repo"
4956
git fetch template
5057
51-
echo "Deleting local branch that will contain the updates - if present"
58+
echo "Deleting local branches that will contain the updates - if present"
5259
git branch -D ${{ env.UPDATE_BRANCH }} || true
60+
git branch -D ${{ env.UPDATE_BRANCH_MERGED }} || true
5361
5462
echo "Checking if the remote template repo has new commits"
5563
git rev-list ..template/${{ env.REMOTE_BRANCH }}
5664
5765
if [ $(git rev-list --count ..template/${{ env.REMOTE_BRANCH }}) -eq 0 ]; then
5866
echo "There are no commits new commits on the template repo"
5967
60-
echo "Deleting origin branch that contains the updates - if present"
68+
echo "Deleting origin branch(es) that contain the updates - if present"
6169
git push -f origin --delete ${{ env.UPDATE_BRANCH }} || true
70+
git push -f origin --delete ${{ env.UPDATE_BRANCH_MERGED }} || true
6271
63-
echo "abort=1" >> $GITHUB_OUTPUT
72+
echo "create_update_branch_pr=0" >> $GITHUB_OUTPUT
73+
echo "create_update_branch_merged_pr=0" >> $GITHUB_OUTPUT
6474
exit 0
6575
fi
6676
@@ -73,21 +83,198 @@ jobs:
7383
echo "Pushing update branch"
7484
git push -f -u origin ${{ env.UPDATE_BRANCH }}
7585
76-
echo "Getting current branch"
77-
current_branch=$(git branch --show-current)
78-
echo "Current branch is $current_branch"
79-
echo "current_branch=$current_branch" >> $GITHUB_OUTPUT
86+
echo "Getting base branch"
87+
base_branch=$(git branch --show-current)
88+
echo "Base branch is $base_branch"
89+
echo "base_branch=$base_branch" >> $GITHUB_OUTPUT
8090
81-
echo "abort=0" >> $GITHUB_OUTPUT
91+
echo "Trying to create auto-merged branch ${{ env.UPDATE_BRANCH_MERGED }}"
92+
git branch ${{ env.UPDATE_BRANCH_MERGED }} ${{ env.UPDATE_BRANCH }}
93+
git checkout ${{ env.UPDATE_BRANCH_MERGED }}
8294
83-
- name: pull-request
84-
if: steps.main.outputs.abort == 0
95+
echo "Merging branch $base_branch into ${{ env.UPDATE_BRANCH_MERGED }}"
96+
git merge $base_branch && merge_exit_code=$? || merge_exit_code=$?
97+
if [ $merge_exit_code -ne 0 ]; then
98+
echo "Auto merge failed! Manual merge required"
99+
echo "::notice ::Auto merge failed - Manual merge required"
100+
101+
echo "Cleaning up failed merge"
102+
git merge --abort
103+
git checkout $base_branch
104+
git branch -D ${{ env.UPDATE_BRANCH_MERGED }} || true
105+
106+
echo "Deleting auto-merge branch - if present"
107+
git push -f origin --delete ${{ env.UPDATE_BRANCH_MERGED }} || true
108+
109+
echo "create_update_branch_pr=1" >> $GITHUB_OUTPUT
110+
echo "create_update_branch_merged_pr=0" >> $GITHUB_OUTPUT
111+
exit 0
112+
fi
113+
114+
echo "Post processing: Trying to automatically fill in template variables"
115+
find . -type f \
116+
-not -path "./.git/**" \
117+
-not -path "./.github/workflows/update-from-template.yml" -print0 \
118+
| xargs -0 sed -i "s/template-placeholder/${GITHUB_REPOSITORY#*/}/g"
119+
120+
git status
121+
git add --all
122+
123+
if [[ "$(git status --porcelain)" != "" ]]; then
124+
echo "Filled in template; Committing"
125+
126+
git commit -m "Fill in template"
127+
fi
128+
129+
echo "Pushing auto-merged branch"
130+
git push -f -u origin ${{ env.UPDATE_BRANCH_MERGED }}
131+
132+
echo "update_branch_merged_commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
133+
134+
echo "Restoring base branch $base_branch"
135+
git checkout $base_branch
136+
137+
echo "create_update_branch_pr=0" >> $GITHUB_OUTPUT
138+
echo "create_update_branch_merged_pr=1" >> $GITHUB_OUTPUT
139+
echo "try_close_update_branch_pr=1" >> $GITHUB_OUTPUT
140+
141+
- name: Create/Update PR update_branch
142+
if: steps.manage-branches.outputs.create_update_branch_pr == 1
85143
env:
86-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
144+
GH_TOKEN: ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }}
87145
run: |
88146
gh_pr_up() {
89147
gh pr create -H "${{ env.UPDATE_BRANCH }}" "$@" || (git checkout "${{ env.UPDATE_BRANCH }}" && gh pr edit "$@")
90148
}
91-
gh_pr_up -B "${{ steps.main.outputs.current_branch }}" \
149+
gh_pr_up -B "${{ steps.manage-branches.outputs.base_branch }}" \
92150
--title "Update from template" \
93151
--body "An automated PR to sync changes from the template into this repo"
152+
153+
# Ensure that only a single PR is open (otherwise confusion and spam)
154+
- name: Close PR update_branch
155+
if: steps.manage-branches.outputs.try_close_update_branch_pr == 1
156+
env:
157+
GH_TOKEN: ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }}
158+
run: |
159+
gh pr close "${{ env.UPDATE_BRANCH }}" || true
160+
161+
- name: Create/Update PR update_branch_merged
162+
if: steps.manage-branches.outputs.create_update_branch_merged_pr == 1
163+
env:
164+
GH_TOKEN: ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }}
165+
run: |
166+
gh_pr_up() {
167+
gh pr create -H "${{ env.UPDATE_BRANCH_MERGED }}" "$@" || (git checkout "${{ env.UPDATE_BRANCH_MERGED }}" && gh pr edit "$@")
168+
}
169+
gh_pr_up -B "${{ steps.manage-branches.outputs.base_branch }}" \
170+
--title "Update from template (auto-merged)" \
171+
--body "An automated PR to sync changes from the template into this repo"
172+
173+
- name: Checking if auto-merge for PR update_branch_merged can be done
174+
id: auto-merge-check
175+
if: steps.manage-branches.outputs.create_update_branch_merged_pr == 1
176+
env:
177+
GH_TOKEN: ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }}
178+
run: |
179+
not_failed_conclusion="skipped|neutral|success"
180+
not_relevant_app_slug="dependabot|github-pages"
181+
182+
echo "Waiting for workflows to start..."
183+
sleep 60s
184+
185+
for i in {1..15}; do
186+
echo "Checking if PR can be auto-merged. Try: $i"
187+
188+
echo "Fetching checks"
189+
cs_response=$(curl -sL \
190+
--fail-with-body \
191+
--connect-timeout 60 \
192+
--max-time 120 \
193+
-H "Accept: application/vnd.github+json" \
194+
-H "Authorization: Bearer $GH_TOKEN" \
195+
-H "X-GitHub-Api-Version: 2022-11-28" \
196+
https://api.github.com/repos/${{ github.repository }}/commits/${{ steps.manage-branches.outputs.update_branch_merged_commit }}/check-suites)
197+
198+
cs_data=$(echo $cs_response | jq '.check_suites[] | { conclusion: .conclusion, slug: .app.slug, check_runs_url: .check_runs_url }')
199+
echo $cs_data
200+
201+
if [[ -z "$cs_data" ]]; then
202+
echo "No check suite data - Assuming that there are no checks to run"
203+
204+
echo "perform=1" >> $GITHUB_OUTPUT
205+
exit 0
206+
fi
207+
208+
cs_failed=$(echo $cs_data | jq --arg x "$not_failed_conclusion" 'select ((.conclusion == null or (.conclusion | test($x))) | not)')
209+
if [[ -z "$cs_failed" ]]; then
210+
echo "No check failed so far; Checking if relevant checks are still running"
211+
212+
cs_relevant_still_running=$(echo $cs_data | jq --arg x "$not_relevant_app_slug" 'select (.conclusion == null and (.slug | test($x) | not))')
213+
if [[ -z $cs_relevant_still_running ]]; then
214+
echo "All relevant checks finished - PR can be merged"
215+
216+
echo "perform=1" >> $GITHUB_OUTPUT
217+
exit 0
218+
else
219+
echo "Relevant checks are still running"
220+
echo $cs_relevant_still_running
221+
fi
222+
else
223+
echo "Detected failed check"
224+
echo $cs_failed
225+
226+
echo "perform=0" >> $GITHUB_OUTPUT
227+
exit 0
228+
fi
229+
230+
echo "Waiting before next run..."
231+
sleep 60s
232+
done
233+
234+
echo "Timed out"
235+
echo "perform=0" >> $GITHUB_OUTPUT
236+
237+
- name: Auto-merge update_branch_merged
238+
if: steps.auto-merge-check.outputs.perform == 1
239+
run: |
240+
base_branch="${{ steps.manage-branches.outputs.base_branch }}"
241+
echo "Restoring base branch $base_branch"
242+
git checkout $base_branch
243+
244+
echo "Fetching..."
245+
git fetch
246+
247+
expected_commit="${{ steps.manage-branches.outputs.update_branch_merged_commit }}"
248+
actual_commit=$(git rev-parse origin/${{ env.UPDATE_BRANCH_MERGED }})
249+
if [[ "$expected_commit" != "$actual_commit" ]]; then
250+
echo "Branch ${{ env.UPDATE_BRANCH_MERGED }} contains unexpected commit $actual_commit"
251+
echo "Expected: $expected_commit"
252+
253+
exit 0
254+
fi
255+
256+
echo "Ensuring that current branch $base_branch is up-to-date"
257+
git pull
258+
259+
echo "Merging ${{ env.UPDATE_BRANCH_MERGED }} into $base_branch"
260+
git merge ${{ env.UPDATE_BRANCH_MERGED }} && merge_exit_code=$? || merge_exit_code=$?
261+
if [ $merge_exit_code -ne 0 ]; then
262+
echo "Unexpected merge failure $merge_exit_code - Requires manual resolution"
263+
264+
exit 0
265+
fi
266+
267+
if [[ "${{ inputs.no_automatic_merge }}" == "true" ]]; then
268+
echo "Exiting due no_automatic_merge"
269+
270+
exit 0
271+
fi
272+
273+
echo "Pushing"
274+
git push
275+
276+
echo "Cleaning up"
277+
git branch -D ${{ env.UPDATE_BRANCH }} || true
278+
git branch -D ${{ env.UPDATE_BRANCH_MERGED }} || true
279+
git push -f origin --delete ${{ env.UPDATE_BRANCH }} || true
280+
git push -f origin --delete ${{ env.UPDATE_BRANCH_MERGED }} || true

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[![Latest version](https://img.shields.io/maven-central/v/software.xdev/chartjs-java-model?logo=apache%20maven)](https://mvnrepository.com/artifact/software.xdev/chartjs-java-model)
2-
[![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/chartjs-java-model/checkBuild.yml?branch=develop)](https://github.com/xdev-software/chartjs-java-model/actions/workflows/checkBuild.yml?query=branch%3Adevelop)
2+
[![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/chartjs-java-model/check-build.yml?branch=develop)](https://github.com/xdev-software/chartjs-java-model/actions/workflows/check-build.yml?query=branch%3Adevelop)
33
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=xdev-software_chartjs-java-model&metric=alert_status)](https://sonarcloud.io/dashboard?id=xdev-software_chartjs-java-model)
44
[![ChartJS Documentation](https://img.shields.io/badge/Chart.js-documentation-ff6384?logo=Chart.js)](https://www.chartjs.org/docs/latest/)
55

0 commit comments

Comments
 (0)