-
Notifications
You must be signed in to change notification settings - Fork 19
143 lines (116 loc) · 3.61 KB
/
Copy pathrelease.yml
File metadata and controls
143 lines (116 loc) · 3.61 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
name: Release
# Trigger on manual workflow dispatch or version tags
on:
workflow_dispatch:
inputs:
tag:
description: 'npm dist-tag to publish under (e.g., latest, beta, next)'
required: false
default: 'beta'
dry_run:
description: 'Dry run (npm publish --dry-run)'
required: false
type: boolean
default: false
push:
tags:
- 'v*.*.*'
permissions:
id-token: write # Required for OIDC
contents: read
jobs:
validate:
name: Validate Build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Enable Corepack
run: corepack enable
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Compile
run: pnpm run compile
- name: Lint
run: pnpm run lint
- name: Build
run: pnpm run build
- name: Verify type definitions
run: |
if [ ! -f "dist/index.d.ts" ]; then
echo "Error: Type definitions not generated"
exit 1
fi
echo "Type definitions verified: $(wc -l < dist/index.d.ts) lines"
- name: Verify CLI executable
run: |
if [ ! -f "dist/cli.js" ]; then
echo "Error: CLI executable not found"
exit 1
fi
if ! head -n 1 dist/cli.js | grep -q "#!/usr/bin/env node"; then
echo "Error: CLI missing shebang"
exit 1
fi
echo "CLI executable verified"
- name: Test
run: pnpm run test
- name: Upload dist artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
retention-days: 7
publish:
name: Publish to npm
runs-on: ubuntu-latest
permissions:
id-token: write # Required for OIDC
contents: read
needs: validate
if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Configure npm for user-specific global installs
run: |
npm config set prefix ~/.npm-global
echo "~/.npm-global/bin" >> $GITHUB_PATH
shell: bash
- name: Update npm to the latest version (now in a user-owned directory)
run: npm install -g npm@latest
- name: Verify the new npm version (optional)
run: npm -v
- name: Enable Corepack
run: corepack enable
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build
run: pnpm run build
- name: Publish to npm (workflow_dispatch)
if: github.event_name == 'workflow_dispatch'
run: |
if [ "${{ github.event.inputs.dry_run }}" == "true" ]; then
echo "Dry run mode - would publish with tag: ${{ github.event.inputs.tag }}"
npm publish --dry-run --tag ${{ github.event.inputs.tag }}
else
npm publish --tag ${{ github.event.inputs.tag }}
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish to npm (tag push)
if: startsWith(github.ref, 'refs/tags/v')
run: npm publish --tag latest
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}