Skip to content

Commit 226b2ef

Browse files
Merge pull request #239 from contentstack/enh/dx-6154-adopt-new-release-process
enh(DX-6154): adopt development→main release flow, back-merge, and version checks
2 parents ee09d2d + 63f2a7a commit 226b2ef

6 files changed

Lines changed: 176 additions & 29 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: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Release-affecting changes under src/main/ or pom.xml require pom.xml + changelog.md bumps
2+
# aligned with the latest tag. Skips when only tests, .github, skills, or docs change.
3+
4+
name: Check Version Bump
5+
6+
on:
7+
pull_request:
8+
9+
jobs:
10+
version-bump:
11+
name: Version & changelog bump
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Detect changed files
20+
id: detect
21+
run: |
22+
FILES=$(git diff --name-only "${{ github.event.pull_request.base.sha }}" "${{ github.event.pull_request.head.sha }}")
23+
echo "Changed files:"
24+
echo "$FILES"
25+
26+
CODE_CHANGED=false
27+
while IFS= read -r f; do
28+
[ -z "$f" ] && continue
29+
if [[ "$f" == src/main/* ]] || [[ "$f" == "pom.xml" ]]; then
30+
CODE_CHANGED=true
31+
break
32+
fi
33+
done <<< "$FILES"
34+
35+
POM_CHANGED=false
36+
CHANGELOG_CHANGED=false
37+
echo "$FILES" | grep -qx 'pom.xml' && POM_CHANGED=true
38+
echo "$FILES" | grep -qx 'changelog.md' && CHANGELOG_CHANGED=true
39+
40+
VERSION_FILES_OK=false
41+
if [ "$POM_CHANGED" = true ] && [ "$CHANGELOG_CHANGED" = true ]; then
42+
VERSION_FILES_OK=true
43+
fi
44+
45+
echo "code_changed=$CODE_CHANGED" >> "$GITHUB_OUTPUT"
46+
echo "version_files_ok=$VERSION_FILES_OK" >> "$GITHUB_OUTPUT"
47+
48+
- name: Skip when no release-affecting code changed
49+
if: steps.detect.outputs.code_changed != 'true'
50+
run: |
51+
echo "No src/main or pom-only release path triggered (e.g. tests/docs/.github only). Skipping version-bump check."
52+
exit 0
53+
54+
- name: Fail when version bump files were not both updated
55+
if: steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_ok != 'true'
56+
run: |
57+
echo "::error::This PR changes release-affecting code but pom.xml and/or changelog.md were not both updated. Bump <version> in pom.xml and add a ## vX.Y.Z section in changelog.md."
58+
exit 1
59+
60+
- name: Validate version vs latest tag and changelog header
61+
if: steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_ok == 'true'
62+
run: |
63+
set -euo pipefail
64+
POM_VERSION=$(python3 <<'PY'
65+
import xml.etree.ElementTree as ET
66+
root = ET.parse("pom.xml").getroot()
67+
ns = {"m": "http://maven.apache.org/POM/4.0.0"}
68+
el = root.find("m:version", ns)
69+
if el is None or not (el.text or "").strip():
70+
raise SystemExit("Could not read project version from pom.xml")
71+
print(el.text.strip())
72+
PY
73+
)
74+
75+
git fetch --tags --force 2>/dev/null || true
76+
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || true)
77+
if [ -z "$LATEST_TAG" ]; then
78+
echo "No existing tags found. Skipping semver vs tag check (first release)."
79+
CHANGELOG_HEAD=$(sed -nE 's/^## v?([0-9]+\.[0-9]+\.[0-9]+).*/\1/p' changelog.md | head -1)
80+
if [ -z "$CHANGELOG_HEAD" ]; then
81+
echo "::error::Could not find a ## vX.Y.Z entry at the top of changelog.md."
82+
exit 1
83+
fi
84+
if [ "$CHANGELOG_HEAD" != "$POM_VERSION" ]; then
85+
echo "::error::changelog.md top version ($CHANGELOG_HEAD) does not match pom.xml version ($POM_VERSION)."
86+
exit 1
87+
fi
88+
exit 0
89+
fi
90+
91+
LATEST_VERSION="${LATEST_TAG#v}"
92+
LATEST_VERSION="${LATEST_VERSION%%-*}"
93+
if [ "$(printf '%s\n' "$LATEST_VERSION" "$POM_VERSION" | sort -V | tail -1)" != "$POM_VERSION" ]; then
94+
echo "::error::pom.xml version ($POM_VERSION) must be greater than latest tag ($LATEST_TAG)."
95+
exit 1
96+
fi
97+
if [ "$POM_VERSION" = "$LATEST_VERSION" ]; then
98+
echo "::error::pom.xml version ($POM_VERSION) must be strictly greater than latest tag version ($LATEST_VERSION)."
99+
exit 1
100+
fi
101+
102+
CHANGELOG_HEAD=$(sed -nE 's/^## v?([0-9]+\.[0-9]+\.[0-9]+).*/\1/p' changelog.md | head -1)
103+
if [ -z "$CHANGELOG_HEAD" ]; then
104+
echo "::error::Could not find a ## vX.Y.Z entry at the top of changelog.md."
105+
exit 1
106+
fi
107+
if [ "$CHANGELOG_HEAD" != "$POM_VERSION" ]; then
108+
echo "::error::changelog.md top version ($CHANGELOG_HEAD) does not match pom.xml version ($POM_VERSION)."
109+
exit 1
110+
fi
111+
echo "Version bump check passed: pom.xml and changelog.md at $POM_VERSION (latest tag: $LATEST_TAG)."

.github/workflows/maven-publish.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
name: Publish package to the Maven Central Repository
22

3+
# Publishes when a GitHub Release is created (same pattern as before tag-based experiments).
34
on:
45
release:
56
types:
67
- created
8+
79
jobs:
810
publish-maven:
911
runs-on: ubuntu-latest

skills/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Source of truth for detailed guidance. Read [AGENTS.md](../AGENTS.md) first, the
66

77
| Skill folder | Use when |
88
| --- | --- |
9-
| [dev-workflow](dev-workflow/SKILL.md) | Branching against `master`/`staging`, running Maven/CI commands, release or publish touchpoints. |
9+
| [dev-workflow](dev-workflow/SKILL.md) | Branching (`development``master`, back-merge, GitHub Release publish), Maven/CI, publish touchpoints. |
1010
| [contentstack-java-cma-sdk](contentstack-java-cma-sdk/SKILL.md) | Changing public API, `Contentstack` / `Stack` flows, auth tokens, or SDK surface exposed to integrators. |
1111
| [java](java/SKILL.md) | Package structure under `com.contentstack.cms`, Java 8 compatibility, Lombok, imports, and code style in this repo. |
1212
| [testing](testing/SKILL.md) | Adding or fixing tests, Surefire `skipTests` behavior, MockWebServer or live API tests, env/credentials. |

skills/dev-workflow/SKILL.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ description: Use when branching, building with Maven, CI, or release/publish wor
88
## When to use
99

1010
- You need the canonical build/test commands or CI expectations.
11-
- You are opening a PR and need branch rules (`master` vs `staging`).
11+
- You are opening a PR and need branch rules (`development``master`, GitHub Release publishing).
1212
- You are changing `pom.xml`, plugins, or publishing configuration.
1313

1414
## Instructions
1515

1616
### Repository and branches
1717

18-
- Default collaboration flow is documented in [.github/workflows/check-branch.yml](../../.github/workflows/check-branch.yml): PRs targeting `master` from branches other than `staging` may be blocked; prefer the documented Contentstack branching policy for your team.
18+
- **Flow:** work merges to **`development`**; **release PRs** go **`development``master`** (no `staging`). After `master` moves, [.github/workflows/back-merge-pr.yml](../../.github/workflows/back-merge-pr.yml) can open a PR **`master``development`** to stay aligned.
19+
- **Releases:** create a **GitHub Release** (triggers [.github/workflows/maven-publish.yml](../../.github/workflows/maven-publish.yml) on **`release: created`**). PRs that change `src/main` or `pom.xml` are checked by [.github/workflows/check-version-bump.yml](../../.github/workflows/check-version-bump.yml) (version + `changelog.md`).
1920

2021
### Maven
2122

@@ -33,9 +34,3 @@ description: Use when branching, building with Maven, CI, or release/publish wor
3334

3435
- Run tests locally with `-DskipTests=false` before pushing.
3536
- Update [changelog.md](../../changelog.md) or version metadata when your team’s release process requires it.
36-
37-
## References
38-
39-
- [AGENTS.md](../../AGENTS.md)
40-
- [testing/SKILL.md](../testing/SKILL.md)
41-
- [code-review/SKILL.md](../code-review/SKILL.md)

0 commit comments

Comments
 (0)