-
Notifications
You must be signed in to change notification settings - Fork 75
112 lines (98 loc) · 3.48 KB
/
Copy pathtypescript-release.yml
File metadata and controls
112 lines (98 loc) · 3.48 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
name: TypeScript SDK Release
on:
workflow_call:
inputs:
working-directory:
description: Path where build commands should run
required: true
type: string
tag:
description: Git tag for this release (e.g., v0.1.0)
required: true
type: string
version:
description: Package version without the leading v (e.g., 0.1.0)
required: true
type: string
node-version:
description: Node.js version used to build the package
required: false
type: string
default: "20"
secrets:
NPM_TOKEN:
required: false
jobs:
publish:
name: Publish TypeScript SDK
runs-on: ubuntu-latest
environment: release
if: inputs.version != ''
permissions:
contents: read
id-token: write
defaults:
run:
shell: bash
working-directory: ${{ inputs.working-directory }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Show release context
run: |
echo "Tag: ${{ inputs.tag }}"
echo "Version: ${{ inputs.version }}"
echo "Working directory: ${{ inputs.working-directory }}"
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
cache: npm
cache-dependency-path: ${{ inputs.working-directory }}/package-lock.json
registry-url: https://registry.npmjs.org
- name: Ensure npm supports trusted publishing
run: npm install -g npm@^11.5.1
- name: Install dependencies
run: npm ci
- name: Type-check
run: npm run type-check
- name: Build package
run: npm run build
- name: Verify package version matches tag
id: verify-ts-version
run: |
TAG_VERSION="${{ inputs.version }}"
PACKAGE_VERSION=$(node -p "require('./package.json').version")
echo "Detected package version: $PACKAGE_VERSION"
if [ "$PACKAGE_VERSION" != "$TAG_VERSION" ]; then
echo "❌ Version mismatch! Tag: $TAG_VERSION, Package: $PACKAGE_VERSION"
exit 1
fi
echo "✅ TypeScript version matches tag"
- name: Check if package version already exists on npm
id: check-npm
run: |
VERSION="${{ inputs.version }}"
PACKAGE_NAME=$(node -p "require('./package.json').name")
echo "Package name: $PACKAGE_NAME"
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "https://registry.npmjs.org/$PACKAGE_NAME/$VERSION")
if [ "$HTTP_CODE" = "200" ]; then
echo "⚠️ $PACKAGE_NAME v$VERSION already exists on npm"
echo "should_publish=false" >> "$GITHUB_OUTPUT"
else
echo "✅ $PACKAGE_NAME v$VERSION not found on npm"
echo "should_publish=true" >> "$GITHUB_OUTPUT"
fi
echo "package_name=$PACKAGE_NAME" >> "$GITHUB_OUTPUT"
- name: Remove injected npm auth token (use OIDC)
run: npm config delete //registry.npmjs.org/:_authToken || true
- name: Publish package to npm
if: steps.check-npm.outputs.should_publish == 'true'
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ""
- name: Skip publish (already exists)
if: steps.check-npm.outputs.should_publish != 'true'
run: echo "Skipping npm publish because version already exists."