Skip to content

Commit f8a3d44

Browse files
authored
Merge pull request #273 from contentstack/fix/DX-6182
fix: Modified github workflows for release and remove check-branch workflow
2 parents 19d259e + 8d73365 commit f8a3d44

8 files changed

Lines changed: 150 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: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Runs only when production code under src/ changes. Version must be > latest v* tag (not vs base branch).
2+
3+
name: Check Version Bump
4+
5+
on:
6+
pull_request:
7+
8+
jobs:
9+
check-version-bump:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
15+
- name: Validate version and changelog updates
16+
shell: bash
17+
run: |
18+
set -euo pipefail
19+
20+
VERSION_FILE="package.json"
21+
CHANGELOG_FILE="CHANGELOG.md"
22+
BASE_SHA="${{ github.event.pull_request.base.sha }}"
23+
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
24+
25+
mapfile -t CHANGED_FILES < <(git diff --name-only "$BASE_SHA" "$HEAD_SHA")
26+
if [ "${#CHANGED_FILES[@]}" -eq 0 ]; then
27+
echo "No changed files detected."
28+
exit 0
29+
fi
30+
31+
is_production_source_change() {
32+
local f="$1"
33+
[[ "$f" == src/* ]]
34+
}
35+
36+
has_source_changes=false
37+
for file in "${CHANGED_FILES[@]}"; do
38+
if is_production_source_change "$file"; then
39+
has_source_changes=true
40+
break
41+
fi
42+
done
43+
44+
if [ "$has_source_changes" = false ]; then
45+
echo "Skipping: no src/ production code changes."
46+
exit 0
47+
fi
48+
49+
changed_file() {
50+
local target="$1"
51+
for file in "${CHANGED_FILES[@]}"; do
52+
if [ "$file" = "$target" ]; then
53+
return 0
54+
fi
55+
done
56+
return 1
57+
}
58+
59+
changed_file "$VERSION_FILE" || { echo "Version bump required in $VERSION_FILE."; exit 1; }
60+
changed_file "$CHANGELOG_FILE" || { echo "Matching changelog update required in $CHANGELOG_FILE."; exit 1; }
61+
62+
head_version=$(node -e "console.log(require('./package.json').version)")
63+
CHANGELOG_HEAD=$(sed -nE 's/^## v?([^[:space:]]+).*/\1/p' "$CHANGELOG_FILE" | head -1)
64+
65+
[ -n "$CHANGELOG_HEAD" ] || { echo "::error::Could not find a top changelog heading like '## vX.Y.Z' in $CHANGELOG_FILE."; exit 1; }
66+
[ "$CHANGELOG_HEAD" = "$head_version" ] || { echo "::error::$CHANGELOG_FILE top version ($CHANGELOG_HEAD) does not match project version ($head_version)."; exit 1; }
67+
68+
latest_tag=$(git tag --list 'v*' --sort=-version:refname | sed -n '1p')
69+
latest_version="${latest_tag#v}"
70+
[ -n "$latest_version" ] || latest_version="0.0.0"
71+
72+
version_gt() {
73+
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"
74+
}
75+
76+
[ "$(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/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Unit-Test-CI
22

33
on:
44
push:
5-
branches: [ master, staging, development ]
5+
branches: [ master, development ]
66
pull_request:
7-
branches: [ master, staging, development ]
7+
branches: [ master, development ]
88

99
jobs:
1010
build-test:

.github/workflows/npm-publish.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This workflow will publish a package to GitHub Packages when a release is created
1+
# This workflow publishes packages when a GitHub Release is created for a version tag.
22
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
33

44
name: Publish package to NPM repository
@@ -8,9 +8,12 @@ on:
88

99
jobs:
1010
publish-npm:
11+
if: ${{ startsWith(github.event.release.tag_name, 'v') && !github.event.release.draft }}
1112
runs-on: ubuntu-latest
1213
steps:
1314
- uses: actions/checkout@v4
15+
with:
16+
ref: ${{ github.event.release.tag_name }}
1417
- uses: actions/setup-node@v4
1518
with:
1619
node-version: '22.x'
@@ -20,9 +23,12 @@ jobs:
2023
env:
2124
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
2225
publish-git:
26+
if: ${{ startsWith(github.event.release.tag_name, 'v') && !github.event.release.draft }}
2327
runs-on: ubuntu-latest
2428
steps:
2529
- uses: actions/checkout@v4
30+
with:
31+
ref: ${{ github.event.release.tag_name }}
2632
- uses: actions/setup-node@v4
2733
with:
2834
node-version: '22.x'

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ npm run download-regions # regions.json only (also run as part of prebuild)
2929

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

32-
**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).
32+
**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`.
3333

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

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Thank you for your interest in contributing to Contentstack Utils JavaScript. Th
66

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

9-
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.
9+
Feature/fix PRs should merge into `development`. Release PRs are raised by maintainers directly from `development` to `master`.
1010

1111
## Getting Started
1212

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

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

9797
3. **Fill out the PR template** (if one exists) and provide:
9898
- A clear title and description of the change

skills/dev-workflow/SKILL.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ description: Branches, CI, build/test/lint commands, git hooks, PR expectations,
1515

1616
### Branches and PRs
1717

18-
- **CI** (`Unit-Test-CI`) runs on **push/PR** to `development`, `staging`, and `master` (`.github/workflows/ci.yml`).
19-
- **Branch check:** PRs **into `staging`** from a head branch other than **`development`** fail (`.github/workflows/check-branch.yml`). Prefer **`development`** as the integration branch when aligning with upstream.
18+
- **CI** (`Unit-Test-CI`) runs on **push/PR** to `development` and `master` (`.github/workflows/ci.yml`).
19+
- Feature/fix PRs should target **`development`**. Release PRs are raised directly from **`development`** to **`master`**.
2020
- Confirm target branch with maintainers if unsure.
2121

2222
### Commands
@@ -43,4 +43,4 @@ description: Branches, CI, build/test/lint commands, git hooks, PR expectations,
4343

4444
- Version in **`package.json`** and **`CHANGELOG.md`**.
4545
- **`prepublishOnly`** runs **`npm test`**.
46-
- **npm / GitHub Packages:** `.github/workflows/npm-publish.yml` on **release `created`**; secrets `NPM_TOKEN`, `GIT_TOKEN` (maintainers).
46+
- **npm / GitHub Packages:** `.github/workflows/npm-publish.yml` on **`release: types: [created]`** for tag **`v*`** (draft releases skipped); secrets `NPM_TOKEN`, `GIT_TOKEN` (maintainers).

0 commit comments

Comments
 (0)