-
Notifications
You must be signed in to change notification settings - Fork 0
93 lines (78 loc) · 2.98 KB
/
publish.yml
File metadata and controls
93 lines (78 loc) · 2.98 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
name: Publish to NPM
on:
push:
branches:
- master
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate version tag and package.json
run: |
# Since develop→master may be a squash merge, look for the latest version tag anywhere in the repo
# This handles both regular merges and squash merges
TAG=$(git tag --list --sort=-version:refname 'v*.*.*' | head -1 || echo "")
if [[ -z "$TAG" ]]; then
echo "❌ ERROR: No version tag found!"
echo ""
echo "This typically happens when:"
echo " 1. You forgot to run 'npm version patch|minor|major' on develop"
echo " 2. You didn't push tags: git push origin develop --tags"
echo " 3. Tags weren't pushed to GitHub before merge"
echo ""
echo "📋 Correct workflow:"
echo " 1. On develop: npm version patch (or minor/major)"
echo " 2. On develop: git push origin develop --tags"
echo " 3. Create PR develop→master and merge (can be squash merge)"
echo " 4. Workflow automatically triggers on master with the tag"
echo ""
exit 1
fi
# Validate tag format
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "❌ ERROR: Invalid tag format: '$TAG'"
echo "Expected format: v*.*.* (e.g., v1.0.0, v0.2.3)"
exit 1
fi
# Extract version from tag
TAG_VERSION="${TAG#v}" # Remove 'v' prefix
PKG_VERSION=$(grep '"version"' package.json | head -1 | sed 's/.*"version": "\([^"]*\)".*/\1/')
# Verify package.json version matches tag
if [[ "$TAG_VERSION" != "$PKG_VERSION" ]]; then
echo "❌ ERROR: Version mismatch!"
echo " Tag version: $TAG_VERSION"
echo " package.json: $PKG_VERSION"
echo ""
echo "Fix: Make sure you ran 'npm version' before pushing"
exit 1
fi
echo "✅ Valid tag found: $TAG"
echo "✅ Version matches package.json: $PKG_VERSION"
echo "TAG_VERSION=$TAG" >> $GITHUB_ENV
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
registry-url: "https://registry.npmjs.org"
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build --if-present
- name: Lint
run: npm run lint --if-present 2>/dev/null || true
- name: Test
run: npm test --if-present 2>/dev/null || true
- name: Publish to NPM
run: npm publish --access public --provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}