-
Notifications
You must be signed in to change notification settings - Fork 0
112 lines (109 loc) · 3.98 KB
/
nodejs-sdk.workflow.yml
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: NodeJS-SDK
on:
push:
branches:
- main
- rc
- dev
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.sha }}
cancel-in-progress: true
env:
NODE_VERSION: '20'
SDK_PATH: './packages/sdk'
RC_SUFFIX: 'rc'
jobs:
test-nodejs-sdk:
runs-on: ubuntu-latest
steps:
# Checkout
- name: Git clone repository
uses: actions/checkout@v4
# Setup Node.js
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
# Install dependencies
- name: Install dependencies
run: yarn --frozen-lockfile --pure-lockfile
working-directory: ${{ env.SDK_PATH }}
# Run test
- name: Run Test
run: yarn test
continue-on-error: false
working-directory: ${{ env.SDK_PATH }}
build-nodejs-sdk:
runs-on: ubuntu-latest
needs:
- test-nodejs-sdk
steps:
# Checkout
- name: Git clone repository
uses: actions/checkout@v4
# Set Slug
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
with:
short-length: 7
# Setup Node.js
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
# Install dependencies
- name: Install dependencies
run: yarn --frozen-lockfile --pure-lockfile
working-directory: ${{ env.SDK_PATH }}
# Get current version
- name: Get current version
run: |
echo SDK_VERSION=$(jq -r '"v" + .version' package.json) >> $GITHUB_ENV
echo SDK_NAME=$(jq -r '.name' package.json | cut -d'/' -f2) >> $GITHUB_ENV
working-directory: ${{ env.SDK_PATH }}
# Set New Version
- name: Set New Version
run: echo SDK_NEW_VERSION=${{ github.ref == 'refs/heads/main' && format('{0}', env.SDK_VERSION) || format('{0}-{1}.{2}', env.SDK_VERSION, env.RC_SUFFIX, env.GITHUB_SHA_SHORT) }} >> $GITHUB_ENV
# Set Version
- name: Set Version
run: npm version ${{ env.OPTION }}
env:
OPTION: ${{ github.ref == 'refs/heads/main' && format('{0} --allow-same-version', env.SDK_NEW_VERSION) || format('{0}', env.SDK_NEW_VERSION) }}
working-directory: ${{ env.SDK_PATH }}
# Build SDK
- name: Build SDK
run: yarn build
working-directory: ${{ env.SDK_PATH }}
# Pack SDK
- name: Pack SDK
run: yarn pack
working-directory: ${{ env.SDK_PATH }}
# Publish to npm
- name: Set NPM Packages Config
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
working-directory: ${{ env.SDK_PATH }}
# Git Set Identity
- name: Git Identity
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
# Commit Version Locally for Github npm
- name: Commit Version Locally for Github npm
run: git add .npmrc && git commit -am "Prepare to release"
working-directory: ${{ env.SDK_PATH }}
# Publish
- name: Publish
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/rc' }}
run: npm publish ${{ github.repository_owner }}-${{ env.SDK_NAME }}-${{ env.SDK_NEW_VERSION }}.tgz --tag ${{ env.RELEASE_TAG }} --access public --userconfig ./.npmrc --force
env:
RELEASE_TAG: ${{ github.ref == 'refs/heads/main' && format('{0}', 'latest' ) || env.RC_SUFFIX }}
working-directory: ${{ env.SDK_PATH }}
# Upload Artifacts
- name: Upload Artifact
if: success()
uses: actions/upload-artifact@v3
with:
name: ${{ github.repository_owner }}-${{ env.SDK_NAME }}-${{ env.SDK_NEW_VERSION }}
path: ${{ env.SDK_PATH }}/${{ github.repository_owner }}-${{ env.SDK_NAME }}-${{ env.SDK_NEW_VERSION }}.tgz
if-no-files-found: error
retention-days: 1