Skip to content

Commit 96722e5

Browse files
committed
chore: migrate java repo to GitHub Release–based publish flow with strict version gating
1 parent ee5986b commit 96722e5

8 files changed

Lines changed: 161 additions & 31 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Opens a PR from master → development after changes land on master (back-merge).
2+
#
3+
# Org/repo Settings → Actions → General → Workflow permissions: read and write
4+
# (so GITHUB_TOKEN can create pull requests). Or use a PAT in secret GH_TOKEN.
5+
6+
name: Back-merge master to development
7+
8+
on:
9+
push:
10+
branches: [master]
11+
workflow_dispatch:
12+
13+
permissions:
14+
contents: read
15+
pull-requests: write
16+
17+
jobs:
18+
open-back-merge-pr:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Open back-merge PR if needed
27+
env:
28+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
run: |
30+
set -euo pipefail
31+
git fetch origin development master
32+
33+
MASTER_SHA=$(git rev-parse origin/master)
34+
DEV_SHA=$(git rev-parse origin/development)
35+
36+
if [ "$MASTER_SHA" = "$DEV_SHA" ]; then
37+
echo "master and development are at the same commit; nothing to back-merge."
38+
exit 0
39+
fi
40+
41+
EXISTING=$(gh pr list --repo "${{ github.repository }}" \
42+
--base development \
43+
--head master \
44+
--state open \
45+
--json number \
46+
--jq 'length')
47+
48+
if [ "$EXISTING" -gt 0 ]; then
49+
echo "An open PR from master to development already exists; skipping."
50+
exit 0
51+
fi
52+
53+
gh pr create --repo "${{ github.repository }}" \
54+
--base development \
55+
--head master \
56+
--title "chore: back-merge master into development" \
57+
--body "Automated back-merge after changes landed on \`master\`. Review and merge to keep \`development\` in sync."
58+
59+
echo "Created back-merge PR master → development."

.github/workflows/check-branch.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Check Version Bump
2+
3+
on:
4+
pull_request:
5+
branches: [main, master]
6+
7+
jobs:
8+
check-version-bump:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
with:
13+
fetch-depth: 0
14+
- name: Validate version and changelog updates
15+
shell: bash
16+
run: |
17+
set -euo pipefail
18+
19+
VERSION_FILE="pom.xml"
20+
CHANGELOG_FILE="CHANGELOG.md"
21+
BASE_SHA="${{ github.event.pull_request.base.sha }}"
22+
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
23+
24+
mapfile -t CHANGED_FILES < <(git diff --name-only "$BASE_SHA" "$HEAD_SHA")
25+
if [ "${#CHANGED_FILES[@]}" -eq 0 ]; then
26+
echo "No changed files detected."
27+
exit 0
28+
fi
29+
30+
is_ignored_change() {
31+
local f="$1"
32+
[[ "$f" =~ ^docs/ ]] && return 0
33+
[[ "$f" =~ ^\.github/ ]] && return 0
34+
[[ "$f" =~ (^|/)tests?/ ]] && return 0
35+
[[ "$f" =~ (^|/)src/test/ ]] && return 0
36+
[[ "$f" =~ \.md$ ]] && [[ ! "$f" =~ (^|/)CHANGELOG\.md$ ]] && return 0
37+
return 1
38+
}
39+
40+
has_release_impact=false
41+
for file in "${CHANGED_FILES[@]}"; do
42+
if ! is_ignored_change "$file"; then
43+
has_release_impact=true
44+
break
45+
fi
46+
done
47+
48+
if [ "$has_release_impact" = false ]; then
49+
echo "Skipping docs/test-only PR."
50+
exit 0
51+
fi
52+
53+
changed_file() {
54+
local target="$1"
55+
for file in "${CHANGED_FILES[@]}"; do
56+
if [ "$file" = "$target" ]; then
57+
return 0
58+
fi
59+
done
60+
return 1
61+
}
62+
63+
changed_file "$VERSION_FILE" || { echo "Version bump required in $VERSION_FILE."; exit 1; }
64+
changed_file "$CHANGELOG_FILE" || { echo "Matching changelog update required in $CHANGELOG_FILE."; exit 1; }
65+
66+
extract_version() {
67+
python3 -c 'import sys,xml.etree.ElementTree as ET;r=ET.fromstring(sys.stdin.read());ns={"m":r.tag.split("}")[0].strip("{")} if r.tag.startswith("{") else None;n=(r.find("m:version",ns) if ns else r.find("version"));print((n.text or "").strip() if n is not None else "")'
68+
}
69+
70+
head_version=$(extract_version < "$VERSION_FILE")
71+
CHANGELOG_HEAD=$(sed -nE 's/^## v?([^[:space:]]+).*/\1/p' "$CHANGELOG_FILE" | head -1)
72+
73+
[ -n "$CHANGELOG_HEAD" ] || { echo "::error::Could not find a top changelog heading like '## vX.Y.Z' in $CHANGELOG_FILE."; exit 1; }
74+
[ "$CHANGELOG_HEAD" = "$head_version" ] || { echo "::error::$CHANGELOG_FILE top version ($CHANGELOG_HEAD) does not match project version ($head_version)."; exit 1; }
75+
76+
base_version=$(git show "$BASE_SHA:$VERSION_FILE" | extract_version)
77+
latest_tag=$(git tag --list 'v*' --sort=-version:refname | sed -n '1p')
78+
latest_version="${latest_tag#v}"
79+
[ -n "$latest_version" ] || latest_version="0.0.0"
80+
81+
version_gt() {
82+
python3 -c 'import sys;v=lambda s:[int(x) if x.isdigit() else 0 for x in (s.strip().lstrip("v").split("-",1)[0].split("+",1)[0].split(".")+["0","0","0"])[:3]];print("true" if v(sys.argv[1])>v(sys.argv[2]) else "false")' "$1" "$2"
83+
}
84+
85+
[ "$(version_gt "$head_version" "$base_version")" = "true" ] || { echo "Version must be greater than base version ($base_version). Found $head_version."; exit 1; }
86+
[ "$(version_gt "$head_version" "$latest_version")" = "true" ] || { echo "Version must be greater than latest tag version ($latest_version). Found $head_version."; exit 1; }

.github/workflows/maven-publish.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ on:
44
types: [created]
55
jobs:
66
publish-maven:
7+
if: ${{ startsWith(github.event.release.tag_name, 'v') && !github.event.release.draft }}
78
runs-on: ubuntu-latest
89
permissions:
910
contents: read
1011
packages: write
1112
steps:
1213
- uses: actions/checkout@v3
14+
with:
15+
ref: ${{ github.event.release.tag_name }}
1316
- name: Set up Maven Central Repository
1417
uses: actions/setup-java@v3
1518
with:
@@ -27,17 +30,20 @@ jobs:
2730
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
2831
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
2932
publish-github:
33+
if: ${{ startsWith(github.event.release.tag_name, 'v') && !github.event.release.draft }}
3034
runs-on: ubuntu-latest
3135
steps:
3236
- uses: actions/checkout@v3
37+
with:
38+
ref: ${{ github.event.release.tag_name }}
3339
- name: Set up Java for publishing to GitHub Packages
3440
uses: actions/setup-java@v3
3541
with:
3642
java-version: '17'
3743
distribution: 'adopt'
3844
server-id: github
3945
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
40-
gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }}
46+
gpg-passphrase: GPG_PASSPHRASE
4147
- name: Set up Maven settings for Central and GitHub
4248
run: |
4349
mkdir -p $HOME/.m2
@@ -58,4 +64,4 @@ jobs:
5864
- name: Publish to GitHub Packages
5965
run: mvn --batch-mode -Dgpg.passphrase=${{ secrets.GPG_PASSPHRASE }} deploy
6066
env:
61-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
| Single test class | `mvn test -Dtest=UtilTests` |
3434
| Javadoc | `mvn javadoc:javadoc` |
3535
| Sample (after `mvn install` with skips if needed) | `mvn -f sample/pom.xml compile` |
36-
| **CI** | Java **17** publish: `.github/workflows/maven-publish.yml` · SCA: `.github/workflows/sca-scan.yml` · branch rules: `.github/workflows/check-branch.yml` |
36+
| **CI** | Java **17** publish: `.github/workflows/maven-publish.yml` (GitHub **Release** for tag `v*`, draft releases skipped) · SCA: `.github/workflows/sca-scan.yml` · back-merge automation: `.github/workflows/back-merge-pr.yml` |
3737

3838
## Where the documentation lives: skills
3939

Changelog.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Changelog
1+
# CHANGELOG
22

33
A brief description of what changes project contains
44

55
## Apr 20, 2026
66

77
#### v1.5.0
88

9-
- Enhancement: Live Preview Editable tags
9+
- Enhancement: Live Preview Editable tags
1010

1111
## Mar 23, 2026
1212

@@ -36,7 +36,7 @@ A brief description of what changes project contains
3636

3737
#### v1.2.11
3838

39-
- Fix: ignore td/th in case of attrs has void:true
39+
- Fix: ignore td/th in case of attrs has void:true
4040

4141
## May 14, 2024
4242

@@ -48,7 +48,7 @@ A brief description of what changes project contains
4848

4949
#### v1.2.9
5050

51-
- Fixed vulnerability issue related to strAttrs and children.
51+
- Fixed vulnerability issue related to strAttrs and children.
5252

5353
## April 23, 2024
5454

@@ -136,4 +136,3 @@ A brief description of what changes project contains
136136
## Support
137137

138138
- For support, email fake@fake.com or join our Slack channel.
139-

skills/code-review/SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ description: PR checklist and optional Blocker/Major/Minor — use when reviewin
1616
### API design and stability
1717

1818
- [ ] **Public API:** New or changed methods on `Utils`, `GQL`, `DefaultOption`, or `interfaces` are necessary, Javadoc’d, and safe for `com.contentstack.sdk:utils` consumers.
19-
- [ ] **Backward compatibility:** Breaking changes only with major version / **`Changelog.md`** plan.
19+
- [ ] **Backward compatibility:** Breaking changes only with major version / **`CHANGELOG.md`** plan.
2020
- [ ] **Naming:** Consistent with existing Utils and RTE/embedded terminology.
2121

2222
### Error handling and robustness

skills/dev-workflow/SKILL.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ description: Branches, CI, build and test commands, PR expectations, optional TD
1515

1616
### Branches
1717

18-
- Default integration for PRs is often **`staging`**; merging into **`master`** may be restricted (see `.github/workflows/check-branch.yml`).
18+
- Feature/fix PRs should target **`development`**. Release PRs are raised directly from **`development`** to **`master`**.
1919
- Feature/fix branches often use ticket-style names (e.g. `fix/DX-5734`).
2020

2121
### Running tests and builds
@@ -28,7 +28,7 @@ description: Branches, CI, build and test commands, PR expectations, optional TD
2828
### Pull requests
2929

3030
- Describe the change; link issues/tickets when applicable.
31-
- Keep public API backward-compatible unless releasing a breaking version; update **`Changelog.md`** for user-visible behavior.
31+
- Keep public API backward-compatible unless releasing a breaking version; update **`CHANGELOG.md`** for user-visible behavior.
3232
- Use **`skills/code-review/SKILL.md`** as the review checklist.
3333

3434
### Optional: TDD

0 commit comments

Comments
 (0)