Skip to content

Commit 2bdb701

Browse files
committed
fix: Modified github workflows for release and remove check-branch workflow
1 parent 19d259e commit 2bdb701

8 files changed

Lines changed: 153 additions & 31 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: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Check Version Bump
2+
3+
on:
4+
pull_request:
5+
branches: [main, master]
6+
7+
jobs:
8+
check-version-bump:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
with:
13+
fetch-depth: 0
14+
- name: Validate version and changelog updates
15+
shell: bash
16+
run: |
17+
set -euo pipefail
18+
19+
VERSION_FILE="package.json"
20+
CHANGELOG_FILE="CHANGELOG.md"
21+
BASE_SHA="${{ github.event.pull_request.base.sha }}"
22+
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
23+
24+
mapfile -t CHANGED_FILES < <(git diff --name-only "$BASE_SHA" "$HEAD_SHA")
25+
if [ "${#CHANGED_FILES[@]}" -eq 0 ]; then
26+
echo "No changed files detected."
27+
exit 0
28+
fi
29+
30+
is_ignored_change() {
31+
local f="$1"
32+
[[ "$f" =~ ^docs/ ]] && return 0
33+
[[ "$f" =~ ^\.github/ ]] && return 0
34+
[[ "$f" =~ (^|/)tests?/ ]] && return 0
35+
[[ "$f" =~ (^|/)__tests__/ ]] && return 0
36+
[[ "$f" =~ \.md$ ]] && [[ ! "$f" =~ (^|/)CHANGELOG\.md$ ]] && return 0
37+
return 1
38+
}
39+
40+
has_release_impact=false
41+
for file in "${CHANGED_FILES[@]}"; do
42+
if ! is_ignored_change "$file"; then
43+
has_release_impact=true
44+
break
45+
fi
46+
done
47+
48+
if [ "$has_release_impact" = false ]; then
49+
echo "Skipping docs/test-only PR."
50+
exit 0
51+
fi
52+
53+
changed_file() {
54+
local target="$1"
55+
for file in "${CHANGED_FILES[@]}"; do
56+
if [ "$file" = "$target" ]; then
57+
return 0
58+
fi
59+
done
60+
return 1
61+
}
62+
63+
changed_file "$VERSION_FILE" || { echo "Version bump required in $VERSION_FILE."; exit 1; }
64+
changed_file "$CHANGELOG_FILE" || { echo "Matching changelog update required in $CHANGELOG_FILE."; exit 1; }
65+
66+
head_version=$(node -e "console.log(require('./package.json').version)")
67+
CHANGELOG_HEAD=$(sed -nE 's/^## v?([^[:space:]]+).*/\1/p' "$CHANGELOG_FILE" | head -1)
68+
69+
[ -n "$CHANGELOG_HEAD" ] || { echo "::error::Could not find a top changelog heading like '## vX.Y.Z' in $CHANGELOG_FILE."; exit 1; }
70+
[ "$CHANGELOG_HEAD" = "$head_version" ] || { echo "::error::$CHANGELOG_FILE top version ($CHANGELOG_HEAD) does not match project version ($head_version)."; exit 1; }
71+
72+
base_version=$(git show "$BASE_SHA:$VERSION_FILE" | node -e "let d=''; process.stdin.on('data', c => d += c); process.stdin.on('end', () => console.log(JSON.parse(d).version));")
73+
latest_tag=$(git tag --list 'v*' --sort=-version:refname | sed -n '1p')
74+
latest_version="${latest_tag#v}"
75+
[ -n "$latest_version" ] || latest_version="0.0.0"
76+
77+
version_gt() {
78+
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"
79+
}
80+
81+
[ "$(version_gt "$head_version" "$base_version")" = "true" ] || { echo "Version must be greater than base version ($base_version). Found $head_version."; exit 1; }
82+
[ "$(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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
# This workflow will publish a package to GitHub Packages when a release is created
1+
# This workflow publishes packages when a release tag is pushed
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
55
on:
6-
release:
7-
types: [created]
6+
push:
7+
tags:
8+
- 'v*'
89

910
jobs:
1011
publish-npm:

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` (on tag push `v*`). 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 **tag push (`v*`)**; secrets `NPM_TOKEN`, `GIT_TOKEN` (maintainers).

0 commit comments

Comments
 (0)