-
Notifications
You must be signed in to change notification settings - Fork 6
169 lines (148 loc) · 4.7 KB
/
release-npm.yml
File metadata and controls
169 lines (148 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: Release npm Package
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
tag:
description: 'Release tag (e.g., v1.1.0)'
required: true
type: string
dry_run:
description: 'Dry run (skip actual publish)'
required: false
type: boolean
default: false
permissions:
contents: write
packages: write
jobs:
release-npm:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: |
cd javascript
npm ci
- name: Run tests
run: |
cd javascript
npm test
- name: Run linting
run: |
cd javascript
npm run lint
- name: Validate package.json
run: |
cd javascript
node -e "
const pkg = require('./package.json');
if (!pkg.name || !pkg.version || !pkg.description) {
console.error('Missing required package.json fields');
process.exit(1);
}
console.log('Package validation passed');
"
- name: Check version consistency
run: |
cd javascript
JS_VERSION=$(node -p "require('./package.json').version")
cd ../python
PY_VERSION=$(grep '^version = ' pyproject.toml | cut -d'"' -f2)
if [ "$JS_VERSION" != "$PY_VERSION" ]; then
echo "Version mismatch: JS=$JS_VERSION, Python=$PY_VERSION"
exit 1
fi
echo "Version consistency check passed: $JS_VERSION"
- name: Build package
run: |
cd javascript
npm pack
- name: Test package installation
run: |
cd javascript
PACKAGE_FILE=$(ls *.tgz)
mkdir -p ../test-install
cd ../test-install
cat > package.json << 'EOF'
{
"name": "test-install",
"version": "1.0.0",
"type": "module"
}
EOF
npm install "../javascript/$PACKAGE_FILE"
cat > test.js << 'EOF'
import { KeyManager, SchemaPinCore } from 'schemapin';
try {
const { privateKey, publicKey } = KeyManager.generateKeypair();
const core = new SchemaPinCore();
console.log('✅ Package installation test passed');
} catch (error) {
console.error('❌ Package test failed:', error);
process.exit(1);
}
EOF
node test.js
- name: Check if version exists on npm
run: |
cd javascript
PACKAGE_NAME=$(node -p "require('./package.json').name")
VERSION=$(node -p "require('./package.json').version")
if npm view "$PACKAGE_NAME@$VERSION" version 2>/dev/null; then
echo "Version $VERSION already exists on npm"
exit 1
fi
echo "Version $VERSION is available for publishing"
- name: Publish to npm (dry run)
if: ${{ github.event.inputs.dry_run == 'true' }}
run: |
cd javascript
npm publish --dry-run --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish to npm
if: ${{ github.event.inputs.dry_run != 'true' }}
run: |
cd javascript
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create GitHub Release
if: ${{ github.event.inputs.dry_run != 'true' && startsWith(github.ref, 'refs/tags/') }}
run: |
PRERELEASE=""
if [[ "${{ github.ref_name }}" == *"alpha"* ]] || [[ "${{ github.ref_name }}" == *"beta"* ]] || [[ "${{ github.ref_name }}" == *"rc"* ]]; then
PRERELEASE="--prerelease"
fi
if gh release view ${{ github.ref_name }} &>/dev/null; then
echo "GitHub Release ${{ github.ref_name }} already exists, skipping creation"
else
gh release create ${{ github.ref_name }} \
--title "Release ${{ github.ref_name }}" \
--notes "## npm Package Release
Published \`schemapin@${{ github.ref_name }}\` to npm registry.
### Installation
\`\`\`bash
npm install schemapin
\`\`\`
### Changes
See [CHANGELOG.md](./CHANGELOG.md) for details." \
$PRERELEASE
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Required secrets to configure in GitHub repository settings:
# - NPM_TOKEN: npm authentication token with publish permissions
# Generate at: https://www.npmjs.com/settings/tokens
# Should be an "Automation" token with "Publish" permission