-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (134 loc) · 5.05 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
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
name: NodeJS-SDK
on:
push:
branches:
- main
workflow_dispatch:
inputs:
environment:
description: Configuration environment
required: true
default: 'dev'
type: choice
options:
- dev
- rc
- prod
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.sha }}
cancel-in-progress: true
env:
NODE_VERSION: '20'
SDK_PATH: './packages/sdk'
RC_SUFFIX: 'rc'
GLOBAL_ENV: ${{ github.event_name == 'push' && format('{0}', 'dev') || inputs.environment }}
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@v4
with:
node-version: ${{ env.NODE_VERSION }}
# Install dependencies
- name: Install dependencies
run: yarn --frozen-lockfile --pure-lockfile
working-directory: ${{ env.SDK_PATH }}
# Run lint
- name: Run Lint
run: yarn lint
continue-on-error: false
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@v4
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=${{ env.GLOBAL_ENV == 'prod' && 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: ${{ env.GLOBAL_ENV == 'prod' && 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 }}
# Set Github Packages Token
- name: Set Github Packages Token
run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > .npmrc
# Publish Github Repo
- name: Publish Github Repo
if: ${{ env.GLOBAL_ENV == 'prod' || env.GLOBAL_ENV == 'rc' }}
run: npm publish ${{ github.repository_owner }}-${{ env.SDK_NAME }}-${{ env.SDK_NEW_VERSION }}.tgz --registry=https://npm.pkg.github.com --tag ${{ env.RELEASE_TAG }} --access public --userconfig ./.npmrc --force
env:
RELEASE_TAG: ${{ env.GLOBAL_ENV == 'prod' && format('{0}', 'latest' ) || env.RC_SUFFIX }}
working-directory: ${{ env.SDK_PATH }}
# Publish NpmJS
- name: Publish
if: ${{ env.GLOBAL_ENV == 'prod' || env.GLOBAL_ENV == '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: ${{ env.GLOBAL_ENV == 'prod' && format('{0}', 'latest' ) || env.RC_SUFFIX }}
working-directory: ${{ env.SDK_PATH }}
# Upload Artifacts
- name: Upload Artifact
if: success()
uses: actions/upload-artifact@v4
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