Skip to content

Commit 4e518ae

Browse files
author
perlinson
committed
Add automated NPM publishing with GitHub Actions
🚀 GitHub Actions Workflows: - Add CI workflow for testing and validation - Add NPM publish workflow for automated releases - Support multiple Node.js versions (16, 18, 20) 📦 Release Automation: - Create release-version.js script for version management - Add npm scripts for patch/minor/major releases - Automatic Git tagging and GitHub Release creation 🔧 Configuration: - Update CI workflow with modern actions - Add package size monitoring - Include coverage reporting with Codecov 📚 Documentation: - Add comprehensive automated publishing guide - Include troubleshooting and best practices - Document setup steps and workflows 🎯 Features: - Semantic versioning support - Automatic dependency publishing order - Rollback and error handling - Release verification and validation
1 parent 55f884a commit 4e518ae

6 files changed

Lines changed: 861 additions & 16 deletions

File tree

.github/workflows/ci.yml

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,63 @@
1-
name: Node CI
1+
name: CI
22

3-
on: [push]
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
48

59
jobs:
6-
build:
7-
runs-on: ${{ matrix.os }}
10+
test:
11+
runs-on: ubuntu-latest
12+
813
strategy:
914
matrix:
10-
node_version: [10.x, 12.x]
11-
os: [ubuntu-latest]
15+
node-version: [16.x, 18.x, 20.x]
16+
1217
steps:
13-
- uses: actions/checkout@v1
14-
- name: Use Node.js ${{ matrix.node_version }}
15-
uses: actions/setup-node@v1
18+
- uses: actions/checkout@v4
19+
20+
- name: Use Node.js ${{ matrix.node-version }}
21+
uses: actions/setup-node@v4
1622
with:
17-
node-version: ${{ matrix.node_version }}
18-
- run: npm install
19-
- run: npm run bootstrap
20-
- run: npm run build
21-
- run: npm run test -- --forceExit
23+
node-version: ${{ matrix.node-version }}
24+
cache: 'npm'
25+
26+
- name: Install dependencies
27+
run: npm ci
28+
29+
- name: Bootstrap packages
30+
run: npx lerna bootstrap --no-ci
31+
32+
- name: Build packages
33+
run: |
34+
npm run build:simple
35+
# 或者逐个构建
36+
cd packages/modernx-core && npx father-build
37+
cd ../modernx-immer && npx father-build
38+
cd ../modernx-loading && npx father-build
39+
cd ../modernx && npx father-build
40+
41+
- name: Run tests
42+
run: npm test
2243
env:
2344
CI: true
24-
HEADLESS: false
25-
PROGRESS: none
2645
NODE_ENV: test
2746
NODE_OPTIONS: --max_old_space_size=4096
47+
48+
- name: Validate monorepo
49+
run: npm run validate
50+
51+
- name: Check package sizes
52+
run: |
53+
echo "Package sizes:"
54+
du -sh packages/*/dist || echo "No dist directories found"
55+
56+
- name: Upload coverage reports
57+
if: matrix.node-version == '18.x'
58+
uses: codecov/codecov-action@v3
59+
with:
60+
file: ./coverage/lcov.info
61+
flags: unittests
62+
name: codecov-umbrella
2863

.github/workflows/npm-publish.yml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: NPM Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*' # 触发条件:推送以 v 开头的标签 (如 v1.0.2)
7+
workflow_dispatch: # 允许手动触发
8+
9+
jobs:
10+
publish:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0 # 获取完整历史记录
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: '18'
22+
registry-url: 'https://registry.npmjs.org'
23+
scope: '@perlinson'
24+
25+
- name: Install dependencies
26+
run: npm ci
27+
28+
- name: Bootstrap packages
29+
run: npx lerna bootstrap --no-ci
30+
31+
- name: Build packages
32+
run: |
33+
npm run build:simple
34+
# 或者逐个构建
35+
cd packages/modernx-core && npx father-build
36+
cd ../modernx-immer && npx father-build
37+
cd ../modernx-loading && npx father-build
38+
cd ../modernx && npx father-build
39+
40+
- name: Check package versions
41+
run: |
42+
echo "Checking package versions..."
43+
node -e "
44+
const fs = require('fs');
45+
const packages = ['modernx-core', 'modernx-immer', 'modernx-loading', 'modernx'];
46+
packages.forEach(pkg => {
47+
const pkgPath = \`packages/\${pkg}/package.json\`;
48+
const pkgJson = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
49+
console.log(\`\${pkg}: \${pkgJson.version}\`);
50+
});
51+
"
52+
53+
- name: Publish to NPM
54+
run: |
55+
echo "Publishing packages to NPM..."
56+
57+
# 按依赖顺序发布
58+
echo "Publishing modernx-core..."
59+
cd packages/modernx-core
60+
npm publish --access public
61+
cd ../..
62+
63+
echo "Publishing modernx-immer..."
64+
cd packages/modernx-immer
65+
npm publish --access public
66+
cd ../..
67+
68+
echo "Publishing modernx-loading..."
69+
cd packages/modernx-loading
70+
npm publish --access public
71+
cd ../..
72+
73+
echo "Publishing modernx..."
74+
cd packages/modernx
75+
npm publish --access public
76+
cd ../..
77+
env:
78+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
79+
80+
- name: Verify publish
81+
run: |
82+
echo "Verifying published packages..."
83+
npm view modernx@$(node -p "require('./packages/modernx/package.json').version")
84+
npm view modernx-core@$(node -p "require('./packages/modernx-core/package.json').version")
85+
npm view modernx-immer@$(node -p "require('./packages/modernx-immer/package.json').version")
86+
npm view modernx-loading@$(node -p "require('./packages/modernx-loading/package.json').version")
87+
88+
- name: Create GitHub Release
89+
uses: actions/create-release@v1
90+
env:
91+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
92+
with:
93+
tag_name: ${{ github.ref }}
94+
release_name: Release ${{ github.ref }}
95+
body: |
96+
## 🚀 ModernX Release ${{ github.ref }}
97+
98+
### 📦 Published Packages
99+
- modernx@$(node -p "require('./packages/modernx/package.json').version")
100+
- modernx-core@$(node -p "require('./packages/modernx-core/package.json').version")
101+
- modernx-immer@$(node -p "require('./packages/modernx-immer/package.json').version")
102+
- modernx-loading@$(node -p "require('./packages/modernx-loading/package.json').version")
103+
104+
### 📋 Changes
105+
See [CHANGELOG.md](https://github.com/perlinson/modernx/blob/main/CHANGELOG.md) for detailed changes.
106+
107+
### 🚀 Installation
108+
\`\`\`bash
109+
npm install modernx@latest
110+
\`\`\`
111+
112+
### 🔗 Links
113+
- [Documentation](https://perlinson.github.io/modernx)
114+
- [NPM Package](https://www.npmjs.com/package/modernx)
115+
- [GitHub Repository](https://github.com/perlinson/modernx)
116+
draft: false
117+
prerelease: false

0 commit comments

Comments
 (0)