Skip to content

Commit f54594d

Browse files
Merge pull request #52 from contentstack/enh/dx-6968-new-release-process
chore: align release workflows with new development-to-main process
2 parents 5275504 + a75772e commit f54594d

2 files changed

Lines changed: 167 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Back-merge main to development
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
pull-requests: write
12+
13+
jobs:
14+
open-back-merge-pr:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Open back-merge PR if needed
23+
env:
24+
GH_TOKEN: ${{ github.token }}
25+
run: |
26+
set -euo pipefail
27+
BASE_BRANCH="development"
28+
SOURCE_BRANCH="main"
29+
30+
git fetch origin "$BASE_BRANCH" "$SOURCE_BRANCH"
31+
32+
SOURCE_SHA=$(git rev-parse "origin/$SOURCE_BRANCH")
33+
BASE_SHA=$(git rev-parse "origin/$BASE_BRANCH")
34+
35+
if [ "$SOURCE_SHA" = "$BASE_SHA" ]; then
36+
echo "$SOURCE_BRANCH and $BASE_BRANCH are at the same commit; nothing to back-merge."
37+
exit 0
38+
fi
39+
40+
EXISTING=$(gh pr list --repo "${{ github.repository }}" \
41+
--base "$BASE_BRANCH" \
42+
--head "$SOURCE_BRANCH" \
43+
--state open \
44+
--json number \
45+
--jq 'length')
46+
47+
if [ "$EXISTING" -gt 0 ]; then
48+
echo "An open PR from $SOURCE_BRANCH to $BASE_BRANCH already exists; skipping."
49+
exit 0
50+
fi
51+
52+
gh pr create --repo "${{ github.repository }}" \
53+
--base "$BASE_BRANCH" \
54+
--head "$SOURCE_BRANCH" \
55+
--title "chore: back-merge main into development" \
56+
--body "Automated back-merge after changes landed on \`main\`. Review and merge to keep \`development\` in sync."
57+
58+
echo "Created back-merge PR $SOURCE_BRANCH -> $BASE_BRANCH."
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: Check Version Bump
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
version-bump:
8+
name: Version & Changelog bump
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
15+
16+
- name: Detect changed files and version bump
17+
id: detect
18+
run: |
19+
set -euo pipefail
20+
BASE_SHA="${{ github.event.pull_request.base.sha }}"
21+
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
22+
FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA")
23+
24+
VERSION_FILES_CHANGED=false
25+
echo "$FILES" | grep -qx 'pom.xml' && VERSION_FILES_CHANGED=true
26+
echo "$FILES" | grep -qE '^changelog\.md$|^CHANGELOG\.md$|^CHANGELOG\.MD$' && VERSION_FILES_CHANGED=true
27+
echo "version_files_changed=$VERSION_FILES_CHANGED" >> "$GITHUB_OUTPUT"
28+
29+
CODE_CHANGED=false
30+
echo "$FILES" | grep -qE '^src/|^pom.xml' && CODE_CHANGED=true
31+
echo "code_changed=$CODE_CHANGED" >> "$GITHUB_OUTPUT"
32+
33+
- name: Skip when only test/docs/.github changed
34+
if: steps.detect.outputs.code_changed != 'true'
35+
run: |
36+
echo "No release-affecting files changed (e.g. only test/docs/.github). Skipping version-bump check."
37+
exit 0
38+
39+
- name: Fail when version bump was missed
40+
if: steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed != 'true'
41+
run: |
42+
echo "::error::This PR has code changes but no version bump. Please bump the version in pom.xml and add an entry in changelog.md."
43+
exit 1
44+
45+
- name: Set up Java
46+
if: steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed == 'true'
47+
uses: actions/setup-java@v4
48+
with:
49+
distribution: temurin
50+
java-version: '11'
51+
52+
- name: Check version bump
53+
if: steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed == 'true'
54+
run: |
55+
set -euo pipefail
56+
57+
POM_VERSION=$(python3 - <<'PYV'
58+
import xml.etree.ElementTree as ET
59+
root = ET.parse("pom.xml").getroot()
60+
ns = {"m":"http://maven.apache.org/POM/4.0.0"}
61+
ver = root.find("m:version", ns)
62+
if ver is None:
63+
parent = root.find("m:parent", ns)
64+
ver = parent.find("m:version", ns) if parent is not None else None
65+
print((ver.text if ver is not None else "").strip())
66+
PYV
67+
)
68+
69+
POM_VERSION="${POM_VERSION#v}"
70+
POM_VERSION="${POM_VERSION%%-*}"
71+
if [ -z "$POM_VERSION" ]; then
72+
echo "::error::Could not read version from pom.xml"
73+
exit 1
74+
fi
75+
76+
git fetch --tags --force 2>/dev/null || true
77+
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || true)
78+
if [ -z "$LATEST_TAG" ]; then
79+
echo "No existing tags found. Skipping version-bump check (first release)."
80+
exit 0
81+
fi
82+
83+
LATEST_VERSION="${LATEST_TAG#v}"
84+
LATEST_VERSION="${LATEST_VERSION%%-*}"
85+
if [ "$(printf '%s\n' "$LATEST_VERSION" "$POM_VERSION" | sort -V | tail -1)" != "$POM_VERSION" ]; then
86+
echo "::error::Version bump required: pom.xml version ($POM_VERSION) is not greater than latest tag ($LATEST_TAG). Please bump the version in pom.xml."
87+
exit 1
88+
fi
89+
if [ "$POM_VERSION" = "$LATEST_VERSION" ]; then
90+
echo "::error::Version bump required: pom.xml version ($POM_VERSION) equals latest tag ($LATEST_TAG). Please bump the version in pom.xml."
91+
exit 1
92+
fi
93+
94+
CHANGELOG_FILE="changelog.md"
95+
if [ ! -f "$CHANGELOG_FILE" ] && [ -f "CHANGELOG.md" ]; then
96+
CHANGELOG_FILE="CHANGELOG.md"
97+
fi
98+
99+
CHANGELOG_VERSION=$(sed -nE 's/^####[[:space:]]+v?([0-9]+\.[0-9]+\.[0-9]+).*/\1/p' "$CHANGELOG_FILE" | head -1)
100+
if [ -z "$CHANGELOG_VERSION" ]; then
101+
echo "::error::Could not find a version entry in $CHANGELOG_FILE (expected line like '#### v1.0.0')."
102+
exit 1
103+
fi
104+
if [ "$CHANGELOG_VERSION" != "$POM_VERSION" ]; then
105+
echo "::error::CHANGELOG version mismatch: $CHANGELOG_FILE top version ($CHANGELOG_VERSION) does not match pom.xml version ($POM_VERSION). Please add or update the changelog entry for $POM_VERSION."
106+
exit 1
107+
fi
108+
109+
echo "Version bump check passed: pom.xml and $CHANGELOG_FILE are at $POM_VERSION (latest tag: $LATEST_TAG)."

0 commit comments

Comments
 (0)