enh(DX-6155): adopt development→main release flow, back-merge, and version checks #1
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Release-affecting changes under contentstack_management/ or setup.py require | |
| # __version__ + CHANGELOG.md updates aligned with the latest tag. | |
| name: Check Version Bump | |
| on: | |
| pull_request: | |
| jobs: | |
| version-bump: | |
| name: Version & changelog bump | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Detect changed files | |
| id: detect | |
| run: | | |
| FILES=$(git diff --name-only "${{ github.event.pull_request.base.sha }}" "${{ github.event.pull_request.head.sha }}") | |
| echo "Changed files:" | |
| echo "$FILES" | |
| CODE_CHANGED=false | |
| while IFS= read -r f; do | |
| [ -z "$f" ] && continue | |
| if [[ "$f" == contentstack_management/* ]] || [[ "$f" == "setup.py" ]]; then | |
| CODE_CHANGED=true | |
| break | |
| fi | |
| done <<< "$FILES" | |
| INIT_CHANGED=false | |
| CHANGELOG_CHANGED=false | |
| echo "$FILES" | grep -qx 'contentstack_management/__init__.py' && INIT_CHANGED=true | |
| echo "$FILES" | grep -qx 'CHANGELOG.md' && CHANGELOG_CHANGED=true | |
| VERSION_FILES_OK=false | |
| if [ "$INIT_CHANGED" = true ] && [ "$CHANGELOG_CHANGED" = true ]; then | |
| VERSION_FILES_OK=true | |
| fi | |
| echo "code_changed=$CODE_CHANGED" >> "$GITHUB_OUTPUT" | |
| echo "version_files_ok=$VERSION_FILES_OK" >> "$GITHUB_OUTPUT" | |
| - name: Skip when no release-affecting code changed | |
| if: steps.detect.outputs.code_changed != 'true' | |
| run: | | |
| echo "No contentstack_management or setup.py changes. Skipping version-bump check." | |
| exit 0 | |
| - name: Fail when version files were not both updated | |
| if: steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_ok != 'true' | |
| run: | | |
| echo "::error::Bump __version__ in contentstack_management/__init__.py and add a ## vX.Y.Z section in CHANGELOG.md." | |
| exit 1 | |
| - name: Validate version vs latest tag and changelog header | |
| if: steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_ok == 'true' | |
| run: | | |
| set -euo pipefail | |
| PKG_VERSION=$(python3 <<'PY' | |
| import re | |
| text = open("contentstack_management/__init__.py").read() | |
| m = re.search(r"^__version__\s*=\s*['\"]([^'\"]+)['\"]", text, re.MULTILINE) | |
| if not m: | |
| raise SystemExit("Could not read __version__ from contentstack_management/__init__.py") | |
| print(m.group(1).strip()) | |
| PY | |
| ) | |
| git fetch --tags --force 2>/dev/null || true | |
| LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || true) | |
| if [ -z "$LATEST_TAG" ]; then | |
| echo "No existing tags found. Skipping semver vs tag check." | |
| CHANGELOG_HEAD=$(sed -nE 's/^## v?([0-9]+\.[0-9]+\.[0-9]+).*/\1/p' CHANGELOG.md | head -1) | |
| if [ -z "$CHANGELOG_HEAD" ]; then | |
| echo "::error::Could not find a ## vX.Y.Z entry at the top of CHANGELOG.md." | |
| exit 1 | |
| fi | |
| if [ "$CHANGELOG_HEAD" != "$PKG_VERSION" ]; then | |
| echo "::error::CHANGELOG top version ($CHANGELOG_HEAD) does not match __version__ ($PKG_VERSION)." | |
| exit 1 | |
| fi | |
| exit 0 | |
| fi | |
| LATEST_VERSION="${LATEST_TAG#v}" | |
| LATEST_VERSION="${LATEST_VERSION%%-*}" | |
| if [ "$(printf '%s\n' "$LATEST_VERSION" "$PKG_VERSION" | sort -V | tail -1)" != "$PKG_VERSION" ]; then | |
| echo "::error::__version__ ($PKG_VERSION) must be greater than latest tag ($LATEST_TAG)." | |
| exit 1 | |
| fi | |
| if [ "$PKG_VERSION" = "$LATEST_VERSION" ]; then | |
| echo "::error::__version__ ($PKG_VERSION) must be strictly greater than latest tag version ($LATEST_VERSION)." | |
| exit 1 | |
| fi | |
| CHANGELOG_HEAD=$(sed -nE 's/^## v?([0-9]+\.[0-9]+\.[0-9]+).*/\1/p' CHANGELOG.md | head -1) | |
| if [ -z "$CHANGELOG_HEAD" ]; then | |
| echo "::error::Could not find a ## vX.Y.Z entry at the top of CHANGELOG.md." | |
| exit 1 | |
| fi | |
| if [ "$CHANGELOG_HEAD" != "$PKG_VERSION" ]; then | |
| echo "::error::CHANGELOG top version ($CHANGELOG_HEAD) does not match __version__ ($PKG_VERSION)." | |
| exit 1 | |
| fi | |
| echo "Version bump check passed: __version__ and CHANGELOG at $PKG_VERSION (latest tag: $LATEST_TAG)." |