-
Notifications
You must be signed in to change notification settings - Fork 21
92 lines (80 loc) · 3.22 KB
/
Copy pathpublishToNPM.yml
File metadata and controls
92 lines (80 loc) · 3.22 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
name: Publish TypeScript SDK to npm (OIDC)
on:
workflow_dispatch:
inputs:
tag:
description: 'NPM tag for the release (e.g., latest, beta, alpha, next)'
required: false
default: 'latest'
type: string
permissions:
id-token: write
contents: read
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: '20.19.4'
registry-url: 'https://registry.npmjs.org'
- name: Update npm for OIDC support
run: npm install -g npm@latest
- name: Extract version from package.json
id: version
working-directory: sdks/typescript
run: |
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION"
- name: Check if version exists on npm
id: npm-check
run: |
VERSION="${{ steps.version.outputs.version }}"
EXISTING=$(npm view @thoughtspot/rest-api-sdk@${VERSION} version 2>/dev/null || echo 'not_found')
if [ "$EXISTING" = "$VERSION" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "Version $VERSION already exists on npm - skipping publish"
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Install dependencies
if: steps.npm-check.outputs.exists == 'false'
working-directory: sdks/typescript
run: npm install
- name: Build TypeScript SDK
if: steps.npm-check.outputs.exists == 'false'
working-directory: sdks/typescript
run: npm run build
- name: Get Branch Name
id: branch_name
run: echo "::set-output name=BRANCH_NAME::$(git branch --show-current)"
- name: Publish to npm with OIDC
if: steps.npm-check.outputs.exists == 'false'
working-directory: sdks/typescript
run: |
BRANCH_NAME="${{ steps.branch_name.outputs.BRANCH_NAME }}"
NPM_TAG=$(echo "${{ github.event.inputs.tag }}" | tr '[:upper:]' '[:lower:]')
if [ "$BRANCH_NAME" = "release" ]; then
echo "publish prod with tag: $NPM_TAG"
npm publish --tag $NPM_TAG
elif [ "$NPM_TAG" = "latest" ]; then
echo "Error: 'latest' tag can only be used when publishing from the release branch"
echo "Current branch: $BRANCH_NAME"
exit 1
else
CURRENT_VERSION=$(node -p "require('./package.json').version")
if [[ "$CURRENT_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Stable versions (X.Y.Z) can only be published from the release branch"
echo "Current version: $CURRENT_VERSION"
echo "Current branch: $BRANCH_NAME"
echo "Please use a pre-release version (e.g., X.Y.Z-beta.1, X.Y.Z-alpha.0) for non-release branches"
exit 1
fi
echo "Publishing from $BRANCH_NAME branch with tag: $NPM_TAG"
npm publish --tag $NPM_TAG
echo "Published @thoughtspot/rest-api-sdk@${{ steps.version.outputs.version }} to tag $NPM_TAG"
fi