fix: Modified github workflows for release and remove check-branch workflow by cs-raj · Pull Request #273 · contentstack/contentstack-utils-javascript · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/back-merge-pr.yml
20 changes: 0 additions & 20 deletions .github/workflows/check-branch.yml

This file was deleted.

76 changes: 76 additions & 0 deletions .github/workflows/check-version-bump.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Runs only when production code under src/ changes. Version must be > latest v* tag (not vs base branch).

name: Check Version Bump

on:
pull_request:

jobs:
check-version-bump:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate version and changelog updates
shell: bash
run: |
set -euo pipefail

VERSION_FILE="package.json"
CHANGELOG_FILE="CHANGELOG.md"
BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"

mapfile -t CHANGED_FILES < <(git diff --name-only "$BASE_SHA" "$HEAD_SHA")
if [ "${#CHANGED_FILES[@]}" -eq 0 ]; then
echo "No changed files detected."
exit 0
fi

is_production_source_change() {
local f="$1"
[[ "$f" == src/* ]]
}

has_source_changes=false
for file in "${CHANGED_FILES[@]}"; do
if is_production_source_change "$file"; then
has_source_changes=true
break
fi
done

if [ "$has_source_changes" = false ]; then
echo "Skipping: no src/ production code changes."
exit 0
fi

changed_file() {
local target="$1"
for file in "${CHANGED_FILES[@]}"; do
if [ "$file" = "$target" ]; then
return 0
fi
done
return 1
}

changed_file "$VERSION_FILE" || { echo "Version bump required in $VERSION_FILE."; exit 1; }
changed_file "$CHANGELOG_FILE" || { echo "Matching changelog update required in $CHANGELOG_FILE."; exit 1; }

head_version=$(node -e "console.log(require('./package.json').version)")
CHANGELOG_HEAD=$(sed -nE 's/^## v?([^[:space:]]+).*/\1/p' "$CHANGELOG_FILE" | head -1)

[ -n "$CHANGELOG_HEAD" ] || { echo "::error::Could not find a top changelog heading like '## vX.Y.Z' in $CHANGELOG_FILE."; exit 1; }
[ "$CHANGELOG_HEAD" = "$head_version" ] || { echo "::error::$CHANGELOG_FILE top version ($CHANGELOG_HEAD) does not match project version ($head_version)."; exit 1; }

latest_tag=$(git tag --list 'v*' --sort=-version:refname | sed -n '1p')
latest_version="${latest_tag#v}"
[ -n "$latest_version" ] || latest_version="0.0.0"

version_gt() {
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"
}

[ "$(version_gt "$head_version" "$latest_version")" = "true" ] || { echo "Version must be greater than latest tag version ($latest_version). Found $head_version."; exit 1; }
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Unit-Test-CI

on:
push:
branches: [ master, staging, development ]
branches: [ master, development ]
pull_request:
branches: [ master, staging, development ]
branches: [ master, development ]

jobs:
build-test:
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This workflow will publish a package to GitHub Packages when a release is created
# This workflow publishes packages when a GitHub Release is created for a version tag.
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: Publish package to NPM repository
Expand All @@ -8,9 +8,12 @@ on:

jobs:
publish-npm:
if: ${{ startsWith(github.event.release.tag_name, 'v') && !github.event.release.draft }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.release.tag_name }}
- uses: actions/setup-node@v4
with:
node-version: '22.x'
Expand All @@ -20,9 +23,12 @@ jobs:
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publish-git:
if: ${{ startsWith(github.event.release.tag_name, 'v') && !github.event.release.draft }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.release.tag_name }}
- uses: actions/setup-node@v4
with:
node-version: '22.x'
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ npm run download-regions # regions.json only (also run as part of prebuild)

`npm test` runs **`pretest` → `npm run build`**, then Jest with coverage; outputs under **`reports/`**. Use **`npm run test:debug`** for Jest watch mode (`--runInBand`).

**CI:** `.github/workflows/ci.yml` (unit tests / coverage on `development`, `staging`, `master`). Branch rules: `.github/workflows/check-branch.yml`. Publish: `.github/workflows/npm-publish.yml` (on GitHub release).
**CI:** `.github/workflows/ci.yml` (unit tests / coverage on `development`, `master`). Publish: `.github/workflows/npm-publish.yml` (GitHub **Release** created for tag `v*`; draft releases are skipped). Back-merge automation: `.github/workflows/back-merge-pr.yml`.

Install: `npm i @contentstack/utils` — see root **`README.md`** and **`package.json`** for the current version.

Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Thank you for your interest in contributing to Contentstack Utils JavaScript. Th

**All pull requests must be raised against the `development` branch.**

Do not open PRs against `master` or `staging`. Create your feature or fix branch from `development`, and open your PR to merge into `development`. Maintainers will handle promotion to other branches after review.
Feature/fix PRs should merge into `development`. Release PRs are raised by maintainers directly from `development` to `master`.

## Getting Started

Expand Down Expand Up @@ -92,7 +92,7 @@ Husky is used for Git hooks. Before each commit, the pre-commit hook runs. Ensur
git rebase upstream/development
```

2. **Open a Pull Request** against the **`development`** branch (not `master` or `staging`).
2. **Open a Pull Request** against the **`development`** branch for feature/fix work. Maintainers handle release PRs from `development` to `master`.

3. **Fill out the PR template** (if one exists) and provide:
- A clear title and description of the change
Expand Down
6 changes: 3 additions & 3 deletions skills/dev-workflow/SKILL.md
Loading