Skip to content

Commit 9747fbc

Browse files
committed
feat: add scripts for bumping and publishing dev versions, update CI/CD workflow for automated publishing
1 parent 91941f9 commit 9747fbc

File tree

4 files changed

+280
-11
lines changed

4 files changed

+280
-11
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
# Bump all packages to dev prerelease versions
3+
set -euo pipefail
4+
5+
echo "🔄 Bumping packages to dev prerelease versions..."
6+
7+
# Define all publishable packages (as regular arrays for better compatibility)
8+
PACKAGES=(
9+
"mcp:packages/mcp"
10+
"core:packages/core"
11+
"ai:packages/ai"
12+
"cli:packages/cli"
13+
)
14+
15+
# Generate timestamp for unique dev versions
16+
TIMESTAMP=$(date +%Y%m%d%H%M%S)
17+
SHORT_SHA=${GITHUB_SHA:0:7}
18+
DEV_SUFFIX="dev.${TIMESTAMP}.${SHORT_SHA}"
19+
20+
for package_entry in "${PACKAGES[@]}"; do
21+
pkg_key="${package_entry%%:*}"
22+
pkg_dir="${package_entry##*:}"
23+
24+
if [ -f "$pkg_dir/package.json" ]; then
25+
PKG_NAME=$(jq -r '.name' "$pkg_dir/package.json")
26+
CURRENT_VERSION=$(jq -r '.version' "$pkg_dir/package.json")
27+
28+
echo "Processing $PKG_NAME@$CURRENT_VERSION..."
29+
30+
# Parse current version to determine next prerelease version
31+
# If current version is already a prerelease, increment it
32+
# If it's a stable version, create a new prerelease based on it
33+
if [[ "$CURRENT_VERSION" == *"-"* ]]; then
34+
# Already a prerelease - extract base version
35+
BASE_VERSION=$(echo "$CURRENT_VERSION" | cut -d'-' -f1)
36+
else
37+
# Stable version - use as base
38+
BASE_VERSION="$CURRENT_VERSION"
39+
fi
40+
41+
NEW_VERSION="${BASE_VERSION}-${DEV_SUFFIX}"
42+
43+
echo " Bumping to: $NEW_VERSION"
44+
45+
# Update package.json with new version
46+
jq ".version = \"$NEW_VERSION\"" "$pkg_dir/package.json" > "$pkg_dir/package.json.tmp"
47+
mv "$pkg_dir/package.json.tmp" "$pkg_dir/package.json"
48+
49+
echo " ✅ Updated $PKG_NAME to v$NEW_VERSION"
50+
else
51+
echo " ⚠️ Package.json not found for $pkg_key"
52+
fi
53+
done
54+
55+
echo "🎉 All packages updated to dev versions with suffix: $DEV_SUFFIX"
56+
57+
# Output for GitHub Actions
58+
echo "dev_suffix=$DEV_SUFFIX" >> ${GITHUB_OUTPUT:-/dev/stdout}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
# Publish packages to NPM with dev tag
3+
set -euo pipefail
4+
5+
echo "📦 Publishing packages to NPM with dev tag..."
6+
7+
# Define all publishable packages (as regular arrays for better compatibility)
8+
PACKAGES=(
9+
"mcp:packages/mcp"
10+
"core:packages/core"
11+
"ai:packages/ai"
12+
"cli:packages/cli"
13+
)
14+
15+
PUBLISHED_PACKAGES=""
16+
FAILED_PACKAGES=""
17+
18+
for package_entry in "${PACKAGES[@]}"; do
19+
pkg_key="${package_entry%%:*}"
20+
pkg_dir="${package_entry##*:}"
21+
22+
if [ -f "$pkg_dir/package.json" ]; then
23+
PKG_NAME=$(jq -r '.name' "$pkg_dir/package.json")
24+
PKG_VERSION=$(jq -r '.version' "$pkg_dir/package.json")
25+
26+
echo "📤 Publishing $PKG_NAME@$PKG_VERSION with dev tag..."
27+
28+
cd "$pkg_dir"
29+
30+
# Publish with dev tag
31+
if pnpm publish --access public --no-git-checks --tag dev; then
32+
echo " ✅ Successfully published $PKG_NAME@$PKG_VERSION"
33+
PUBLISHED_PACKAGES="$PUBLISHED_PACKAGES$PKG_NAME@$PKG_VERSION "
34+
else
35+
echo " ❌ Failed to publish $PKG_NAME@$PKG_VERSION"
36+
FAILED_PACKAGES="$FAILED_PACKAGES$PKG_NAME@$PKG_VERSION "
37+
fi
38+
39+
cd - > /dev/null
40+
else
41+
echo " ⚠️ Package.json not found for $pkg_key"
42+
FAILED_PACKAGES="$FAILED_PACKAGES$pkg_key "
43+
fi
44+
done
45+
46+
# Output for GitHub Actions
47+
echo "published_packages=$PUBLISHED_PACKAGES" >> ${GITHUB_OUTPUT:-/dev/stdout}
48+
49+
if [ -n "$FAILED_PACKAGES" ]; then
50+
echo "failed_packages=$FAILED_PACKAGES" >> ${GITHUB_OUTPUT:-/dev/stdout}
51+
echo "❌ Some packages failed to publish: $FAILED_PACKAGES"
52+
exit 1
53+
else
54+
echo "✅ All packages published successfully: $PUBLISHED_PACKAGES"
55+
fi

.github/workflows/main.yml

Lines changed: 101 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,16 @@ jobs:
173173
with:
174174
sarif_file: 'trivy-results.sarif'
175175

176-
# Phase 4: NPM Publish (depends on build-and-test)
177-
npm-publish:
178-
name: Publish to NPM
176+
# Phase 4a: NPM Publish Stable (main branch)
177+
npm-publish-stable:
178+
name: Publish to NPM (Stable)
179179
runs-on: ubuntu-latest
180180
needs: build-and-test
181181
if: |
182-
github.event_name == 'workflow_dispatch' ||
183-
(github.event_name == 'push' &&
184-
(github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop') &&
185-
contains(github.event.head_commit.message, '[publish]'))
182+
github.ref == 'refs/heads/main' && (
183+
github.event_name == 'workflow_dispatch' ||
184+
(github.event_name == 'push' && contains(github.event.head_commit.message, '[publish]'))
185+
)
186186
permissions:
187187
contents: read
188188
id-token: write
@@ -242,10 +242,10 @@ jobs:
242242
- name: Create summary
243243
if: always()
244244
run: |
245-
echo "## 📦 NPM Publish Results" >> $GITHUB_STEP_SUMMARY
245+
echo "## 📦 NPM Publish Results (Stable)" >> $GITHUB_STEP_SUMMARY
246246
247247
if [ "${{ steps.check_versions.outputs.has_packages_to_publish }}" == "true" ]; then
248-
echo "### ✅ Successfully Published" >> $GITHUB_STEP_SUMMARY
248+
echo "### ✅ Successfully Published to latest tag" >> $GITHUB_STEP_SUMMARY
249249
echo "${{ steps.publish.outputs.published_packages }}" >> $GITHUB_STEP_SUMMARY
250250
else
251251
echo "### ℹ️ No Packages to Publish" >> $GITHUB_STEP_SUMMARY
@@ -257,11 +257,100 @@ jobs:
257257
echo "**Branch:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
258258
echo "**Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
259259
260+
# Phase 4b: NPM Publish Dev (develop branch)
261+
npm-publish-dev:
262+
name: Publish to NPM (Dev)
263+
runs-on: ubuntu-latest
264+
needs: build-and-test
265+
if: |
266+
github.ref == 'refs/heads/develop' && (
267+
github.event_name == 'workflow_dispatch' ||
268+
github.event_name == 'push'
269+
)
270+
permissions:
271+
contents: read
272+
id-token: write
273+
274+
steps:
275+
- name: Checkout code
276+
uses: actions/checkout@v4
277+
with:
278+
fetch-depth: 0
279+
280+
- name: Setup Node.js
281+
uses: actions/setup-node@v4
282+
with:
283+
node-version: '20'
284+
registry-url: 'https://registry.npmjs.org'
285+
286+
- name: Setup pnpm
287+
uses: pnpm/action-setup@v4
288+
with:
289+
version: 10.13.1
290+
run_install: false
291+
292+
- name: Restore pnpm cache
293+
uses: actions/cache@v4
294+
with:
295+
path: ~/.pnpm-store
296+
key: ${{ needs.build-and-test.outputs.cache-key }}
297+
restore-keys: |
298+
${{ runner.os }}-pnpm-
299+
300+
- name: Install dependencies
301+
run: ./.github/scripts/setup-node.sh
302+
303+
- name: Restore build artifacts
304+
uses: actions/cache@v4
305+
with:
306+
path: |
307+
packages/*/build
308+
packages/web/.next-build
309+
key: build-${{ github.sha }}-20
310+
311+
- name: Bump to dev prerelease versions
312+
id: bump_versions
313+
run: |
314+
./.github/scripts/bump-dev-versions.sh
315+
316+
- name: Publish dev packages
317+
id: publish_dev
318+
env:
319+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
320+
run: |
321+
./.github/scripts/publish-dev-packages.sh
322+
323+
- name: Create summary
324+
if: always()
325+
run: |
326+
echo "## 📦 NPM Publish Results (Dev)" >> $GITHUB_STEP_SUMMARY
327+
328+
if [ "${{ steps.publish_dev.outcome }}" == "success" ]; then
329+
echo "### ✅ Successfully Published to dev tag" >> $GITHUB_STEP_SUMMARY
330+
echo "${{ steps.publish_dev.outputs.published_packages }}" >> $GITHUB_STEP_SUMMARY
331+
echo "" >> $GITHUB_STEP_SUMMARY
332+
echo "Install dev versions with:" >> $GITHUB_STEP_SUMMARY
333+
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
334+
echo "npm install @codervisor/devlog-core@dev" >> $GITHUB_STEP_SUMMARY
335+
echo "npm install @codervisor/devlog-mcp@dev" >> $GITHUB_STEP_SUMMARY
336+
echo "npm install @codervisor/devlog-ai@dev" >> $GITHUB_STEP_SUMMARY
337+
echo "npm install @codervisor/devlog-cli@dev" >> $GITHUB_STEP_SUMMARY
338+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
339+
else
340+
echo "### ❌ Dev Publishing Failed" >> $GITHUB_STEP_SUMMARY
341+
echo "Check the logs for details" >> $GITHUB_STEP_SUMMARY
342+
fi
343+
344+
echo "" >> $GITHUB_STEP_SUMMARY
345+
echo "**Trigger:** ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY
346+
echo "**Branch:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
347+
echo "**Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
348+
260349
# Final Summary Job
261350
deployment-summary:
262351
name: Deployment Summary
263352
runs-on: ubuntu-latest
264-
needs: [build-and-test, docker-build, npm-publish]
353+
needs: [build-and-test, docker-build, npm-publish-stable, npm-publish-dev]
265354
if: always() && github.event_name != 'pull_request'
266355

267356
steps:
@@ -278,4 +367,5 @@ jobs:
278367
echo "### Job Status:" >> $GITHUB_STEP_SUMMARY
279368
echo "- 🧪 **Build & Test:** ${{ needs.build-and-test.result }}" >> $GITHUB_STEP_SUMMARY
280369
echo "- 🐳 **Docker Build:** ${{ needs.docker-build.result }}" >> $GITHUB_STEP_SUMMARY
281-
echo "- 📦 **NPM Publish:** ${{ needs.npm-publish.result }}" >> $GITHUB_STEP_SUMMARY
370+
echo "- 📦 **NPM Publish (Stable):** ${{ needs.npm-publish-stable.result }}" >> $GITHUB_STEP_SUMMARY
371+
echo "- 🚧 **NPM Publish (Dev):** ${{ needs.npm-publish-dev.result }}" >> $GITHUB_STEP_SUMMARY

docs/guides/NPM_DEV_VERSIONS.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# NPM Dev Versions
2+
3+
This document explains how to install and use development versions of the Devlog packages.
4+
5+
## Installing Dev Versions
6+
7+
Development versions are automatically published from the `develop` branch and are available under the `dev` tag:
8+
9+
```bash
10+
# Install specific dev package
11+
npm install @codervisor/devlog-core@dev
12+
npm install @codervisor/devlog-mcp@dev
13+
npm install @codervisor/devlog-ai@dev
14+
npm install @codervisor/devlog-cli@dev
15+
16+
# Or with pnpm
17+
pnpm add @codervisor/devlog-core@dev
18+
pnpm add @codervisor/devlog-mcp@dev
19+
pnpm add @codervisor/devlog-ai@dev
20+
pnpm add @codervisor/devlog-cli@dev
21+
```
22+
23+
## Dev Version Format
24+
25+
Dev versions follow the format: `{base-version}-dev.{timestamp}.{commit-sha}`
26+
27+
For example: `0.0.1-dev.20250130155816.abc1234`
28+
29+
- `0.0.1`: Base version from package.json
30+
- `dev`: Development tag
31+
- `20250130155816`: Timestamp (YYYYMMDDHHMMSS)
32+
- `abc1234`: Short commit SHA (first 7 characters)
33+
34+
## Automatic Publishing
35+
36+
Dev versions are automatically published when:
37+
38+
1. **Push to develop branch**: Every push to `develop` triggers a dev release
39+
2. **Manual workflow dispatch**: You can manually trigger dev publishing from GitHub Actions
40+
41+
## Checking Available Versions
42+
43+
```bash
44+
# View all available versions and tags
45+
npm view @codervisor/devlog-core versions --json
46+
47+
# View current dev version
48+
npm view @codervisor/devlog-core@dev version
49+
50+
# View all dist-tags
51+
npm view @codervisor/devlog-core dist-tags
52+
```
53+
54+
## Production vs Development
55+
56+
- **Production**: `npm install @codervisor/devlog-core` (installs `latest` tag)
57+
- **Development**: `npm install @codervisor/devlog-core@dev` (installs `dev` tag)
58+
59+
## CI/CD Workflow
60+
61+
The workflow includes two separate publishing jobs:
62+
63+
1. **npm-publish-stable**: Publishes to `latest` tag from `main` branch
64+
2. **npm-publish-dev**: Publishes to `dev` tag from `develop` branch
65+
66+
Both jobs run independently and publish to different NPM tags, allowing users to choose between stable and development versions.

0 commit comments

Comments
 (0)