-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7250999
commit 40d307c
Showing
2 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
#!groovy | ||
|
||
def runNPM(command) { | ||
def NODE_VERSION = 14; | ||
utilObj = new Utils(); | ||
envVersion = utilObj.getEnvVersion(NODE_VERSION); | ||
utilObj.runCmd(command, envVersion) | ||
} | ||
|
||
def uploadAndInvalidate(environment) { | ||
def STATIC_ASSETS = [ | ||
release: [ | ||
bucketName: credentials('DOCS_S3_BUCKET_NAME_PROD'), | ||
cdnDistributionId: credentials('DOCS_S3_BUCKET_NAME'), | ||
profile: 'prod' | ||
], | ||
staging: [ | ||
bucketName: credentials('DOCS_S3_BUCKET_NAME_STAGING'), | ||
profile: 'staging' | ||
] | ||
] | ||
|
||
uploadAssetsToS3('docs/dist', "s3://${STATIC_ASSETS[environment].bucketName}/api-sdk", 'us-east-1', true, false, 86400, STATIC_ASSETS[environment].profile) | ||
if (environment == 'release') { | ||
invalidateCDN(STATIC_ASSETS[environment].cdnDistributionId, '\"/*\"', STATIC_ASSETS[environment].profile) | ||
} | ||
} | ||
|
||
def publishToNpm(environment){ | ||
if (environment == 'release') { | ||
runNPM('npm run dopublish'); | ||
} else { | ||
runNPM('npm run dopublish-dry-run'); | ||
} | ||
} | ||
|
||
pipeline { | ||
|
||
agent any | ||
|
||
environment { | ||
NPM_TOKEN = credentials('NPM_TOKEN') | ||
} | ||
|
||
parameters { | ||
choice(choices: 'None\nstaging\nrelease\ndeploydocs', description: 'Deploys docs to S3 bucket', name: 'deployTo') | ||
} | ||
|
||
stages { | ||
|
||
stage('Checkout & Setup') { | ||
steps { | ||
checkout scm | ||
runNPM('npm ci') | ||
} | ||
} | ||
|
||
stage('Run unit tests') { | ||
steps { | ||
runNPM('npm test') | ||
} | ||
} | ||
|
||
stage ('Remove target folder') { | ||
steps { | ||
sh 'rm -rf dist' | ||
sh 'rm -rf docs/dist' | ||
} | ||
} | ||
|
||
stage ('Build SDK') { | ||
steps { | ||
runNPM('npm run build:lib') | ||
} | ||
} | ||
|
||
stage ('Build Docs') { | ||
steps { | ||
runNPM('npm run build:docs') | ||
} | ||
} | ||
|
||
stage ('NPM publish dry-run') { | ||
when { | ||
expression { | ||
params.deployTo == 'staging' || params.deployTo == 'release' | ||
} | ||
} | ||
steps { | ||
publishToNpm('staging') | ||
} | ||
} | ||
|
||
stage ('Deploy docs to Staging') { | ||
when { | ||
expression { | ||
params.deployTo == 'staging' && BRANCH_NAME == 'main' | ||
} | ||
} | ||
steps { | ||
uploadAndInvalidate('staging') | ||
} | ||
} | ||
|
||
stage ('Deploy to Release') { | ||
when { | ||
expression { | ||
params.deployTo == 'release' && BRANCH_NAME == 'main' | ||
} | ||
} | ||
steps { | ||
uploadAndInvalidate('release') | ||
publishToNpm('release') | ||
} | ||
} | ||
|
||
stage ('Deploy docs only') { | ||
when { | ||
expression { | ||
params.deployTo == 'deploydocs' && BRANCH_NAME == 'main' | ||
} | ||
} | ||
steps { | ||
uploadAndInvalidate('release') | ||
} | ||
} | ||
|
||
} | ||
|
||
post { | ||
always { | ||
echo 'Freshworks API SDK job finished' | ||
deleteDir() | ||
} | ||
success { | ||
echo 'Freshworks API SDK job successful' | ||
} | ||
failure { | ||
echo 'Freshworks API SDK job failed' | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.