Skip to content

Commit 13322fa

Browse files
ci: add mini release script
- Bash script for patch/minor/major releases (core + eslint-plugin) - Bumps versions and aligns @softarc/sheriff-core peerDependency - Builds, prompts before publish, publishes both packages, then commits and pushes "chore: release <version>"
1 parent 63614e3 commit 13322fa

1 file changed

Lines changed: 100 additions & 0 deletions

File tree

tools/scripts/mini-release.sh

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Mini release script driven by Bash with partial Node for JSON edits
5+
#
6+
# Usage:
7+
# bash tools/scripts/mini-release.sh <patch|minor|major> [remote]
8+
#
9+
# Arguments:
10+
# release type: one of patch | minor | major
11+
# remote (opt.): git remote name to push to (default: origin)
12+
13+
release_type="${1:-}"
14+
remote="${2:-origin}"
15+
if [[ "$release_type" != "patch" && "$release_type" != "minor" && "$release_type" != "major" ]]; then
16+
echo "Usage: bash tools/scripts/mini-release.sh <patch|minor|major> [remote]" >&2
17+
exit 1
18+
fi
19+
20+
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
21+
repo_root="$(cd "$script_dir/../.." && pwd)"
22+
23+
core_json="$repo_root/packages/core/package.json"
24+
eslint_json="$repo_root/packages/eslint-plugin/package.json"
25+
26+
if [[ ! -f "$core_json" || ! -f "$eslint_json" ]]; then
27+
echo "Could not locate package.json files. Expected paths: $core_json, $eslint_json" >&2
28+
exit 1
29+
fi
30+
31+
echo "[1/4] Bumping versions ($release_type) in core and eslint-plugin..."
32+
33+
next_version=$(node - "$release_type" "$core_json" "$eslint_json" <<'NODE'
34+
const fs = require('fs');
35+
36+
const releaseType = process.argv[2];
37+
const corePath = process.argv[3];
38+
const eslintPath = process.argv[4];
39+
40+
function bumpVersion(version, type) {
41+
const m = /^(\d+)\.(\d+)\.(\d+)(.*)?$/.exec(version);
42+
if (!m) throw new Error(`Invalid version: ${version}`);
43+
const major = Number(m[1]);
44+
const minor = Number(m[2]);
45+
const patch = Number(m[3]);
46+
switch (type) {
47+
case 'major': return `${major + 1}.0.0`;
48+
case 'minor': return `${major}.${minor + 1}.0`;
49+
case 'patch': return `${major}.${minor}.${patch + 1}`;
50+
default: throw new Error(`Unknown release type: ${type}`);
51+
}
52+
}
53+
54+
const corePkg = JSON.parse(fs.readFileSync(corePath, 'utf8'));
55+
const eslintPkg = JSON.parse(fs.readFileSync(eslintPath, 'utf8'));
56+
57+
const current = corePkg.version;
58+
if (!current) throw new Error('packages/core/package.json missing version');
59+
const next = bumpVersion(current, releaseType);
60+
61+
corePkg.version = next;
62+
eslintPkg.version = next;
63+
eslintPkg.peerDependencies = eslintPkg.peerDependencies || {};
64+
eslintPkg.peerDependencies['@softarc/sheriff-core'] = next;
65+
66+
fs.writeFileSync(corePath, JSON.stringify(corePkg, null, 2));
67+
fs.writeFileSync(eslintPath, JSON.stringify(eslintPkg, null, 2));
68+
69+
process.stdout.write(next);
70+
NODE
71+
)
72+
73+
echo " -> Next version: $next_version"
74+
75+
echo "[2/4] Building all packages..."
76+
(cd "$repo_root" && yarn build:all)
77+
78+
echo "[3/4] Confirm before publish"
79+
read -r -p "Proceed to npm publish and commit? [y/N] " reply
80+
reply_lc="${reply,,}"
81+
if [[ "$reply_lc" != "y" && "$reply_lc" != "yes" ]]; then
82+
echo "Aborted before publish. Versions were bumped and build completed."
83+
exit 0
84+
fi
85+
86+
echo "[4/4] Publishing to npm..."
87+
(cd "$repo_root/dist/packages/core" && npm publish)
88+
(cd "$repo_root/dist/packages/eslint-plugin" && npm publish)
89+
90+
echo "Creating git commit..."
91+
(cd "$repo_root" && git add "$core_json" "$eslint_json" && \
92+
git commit -m "chore: release" -m "chore: release $next_version")
93+
94+
echo "Pushing to git remote '$remote'..."
95+
(cd "$repo_root" && git push "$remote")
96+
97+
echo "Done."
98+
99+
100+

0 commit comments

Comments
 (0)