From 105e7cb86abb8fe816d588068a48b90c29f92a4c Mon Sep 17 00:00:00 2001 From: Pham Hai Duong Date: Wed, 12 Feb 2020 23:01:47 +0700 Subject: [PATCH] fix: pipe line release prod (#250) * fix: change to runCommand function to view stdout * fix: update script to build storybook for production * fix: tsconfig for elements to build storybook --- .../cognito-auth/src/scripts/check-version.js | 7 +++---- packages/elements/package.json | 2 +- packages/elements/tsconfig.json | 5 ++++- .../scripts/bump-version.js | 21 ++++++++----------- .../scripts/check-version.js | 7 +++---- .../scripts/handle-cronjob.js | 5 ++--- .../scripts/release-master.js | 4 ++-- scripts/release/release-dev.js | 14 +++++++++---- scripts/release/release-npm.js | 5 ++--- scripts/release/release-prod.js | 16 ++++++++------ scripts/release/release-serverless.js | 5 ++--- scripts/release/utils.js | 13 +++++++++--- 12 files changed, 58 insertions(+), 46 deletions(-) diff --git a/packages/cognito-auth/src/scripts/check-version.js b/packages/cognito-auth/src/scripts/check-version.js index 3f3ff0cbea..85f05caf99 100644 --- a/packages/cognito-auth/src/scripts/check-version.js +++ b/packages/cognito-auth/src/scripts/check-version.js @@ -1,8 +1,7 @@ const { npm_package_version: currentPackageVersion, npm_package_name: npmPackageName } = process.env -const { execSync } = require('child_process') -const remotePackageVersion = execSync(`yarn info ${npmPackageName} version`) - .toString() - .trim() +const { runCommand } = require('../../../scripts/release/utils') + +const remotePackageVersion = runCommand('yarn', ['info', npmPackageName, 'version']) const compareVersions = require('compare-versions') if (remotePackageVersion === '') { diff --git a/packages/elements/package.json b/packages/elements/package.json index 04ea7864bb..cde03a5f63 100644 --- a/packages/elements/package.json +++ b/packages/elements/package.json @@ -20,7 +20,7 @@ "module": "dist/elements.esm.js", "typings": "dist/index.d.ts", "scripts": { - "build:prod": "rimraf dist && cross-env NODE_ENV=production tsdx build --format=cjs,esm,umd && rollup -c", + "build:prod": "rimraf dist && rimraf out && cross-env NODE_ENV=production tsdx build --format=cjs,esm,umd && rollup -c && build-storybook -o out", "release:prod": "node ../../scripts/release/release-npm.js @reapit/elements && gh-pages -d out", "start:dev": "start-storybook -p 6006", "start:prod": "cross-env NODE_ENV=development tsdx watch", diff --git a/packages/elements/tsconfig.json b/packages/elements/tsconfig.json index 4a37db9cd7..619343faf1 100644 --- a/packages/elements/tsconfig.json +++ b/packages/elements/tsconfig.json @@ -6,9 +6,12 @@ "moduleResolution": "node", "types": ["jest", "node", "react"], "baseUrl": "./", + "paths": { + "@/*": ["src/*"], + "@reapit/cognito-auth": ["../cognito-auth/src"] + }, "lib": ["es2015", "es2017", "dom", "es5", "es6", "esnext"], "outDir": "public", - "rootDir": "src", "sourceRoot": "/" }, "include": ["src"] diff --git a/packages/foundations-ts-definitions/scripts/bump-version.js b/packages/foundations-ts-definitions/scripts/bump-version.js index 2220ed8111..1aaf6d6cbc 100644 --- a/packages/foundations-ts-definitions/scripts/bump-version.js +++ b/packages/foundations-ts-definitions/scripts/bump-version.js @@ -1,16 +1,13 @@ -const { execSync } = require('child_process') const semver = require('semver') const fs = require('fs') const path = require('path') +const { runCommand } = require('../../../scripts/release/utils') const { npm_package_name } = process.env const packageJsonPath = path.resolve(__dirname, '../package.json') module.exports = () => { - const remotePackageVersionStdOut = execSync(`yarn info ${npm_package_name} version`) - .toString() - .trim() - .split('\n') + const remotePackageVersionStdOut = runCommand('yarn', ['info', npm_package_name, 'version']).split('\n') let remotePackageVersion = '' // Ex of remotePackageVersionStdOut: ['0.0.0'] @@ -38,12 +35,12 @@ module.exports = () => { parsedPackageJsonContent.version = bumpedVersion fs.writeFileSync(packageJsonPath, JSON.stringify(parsedPackageJsonContent, null, 2)) - execSync(`git remote add sshOrigin git@github.com:${process.env.GITHUB_REPOSITORY}.git`) - execSync('git config --global user.email "GithubActions@email.com"') - execSync('git config --global user.name "Github Actions"') + runCommand('git', ['remote', 'add', 'sshOrigin', `git@github.com:${process.env.GITHUB_REPOSITORY}.git`]) + runCommand('git', ['config', '--global', 'user.email', '"GithubActions@email.com"']) + runCommand('git', ['config', '--global', 'user.name', '"Github Actions"']) - execSync('git add .') - execSync(`git commit -m 'Update TypeScript definition - version: ${bumpedVersion}'`) - execSync('yarn publish') - execSync('git push -u sshOrigin HEAD:master') + runCommand('git', ['add', '.']) + runCommand('git', ['commit', '-m', `"Update TypeScript definition - version: ${bumpedVersion}"`]) + runCommand('yarn', ['publish']) + runCommand('git', ['push', '-u', 'sshOrigin', 'HEAD:master']) } diff --git a/packages/foundations-ts-definitions/scripts/check-version.js b/packages/foundations-ts-definitions/scripts/check-version.js index f0072670cd..21445574d4 100644 --- a/packages/foundations-ts-definitions/scripts/check-version.js +++ b/packages/foundations-ts-definitions/scripts/check-version.js @@ -1,8 +1,7 @@ +const { runCommand } = require('../../../scripts/release/utils') const { npm_package_version: currentPackageVersion, npm_package_name: npmPackageName } = process.env -const { execSync } = require('child_process') -const remotePackageVersion = execSync(`yarn info ${npmPackageName} version`) - .toString() - .trim() + +const remotePackageVersion = runCommand('yarn', ['info', npmPackageName, 'version']) const compareVersions = require('compare-versions') if (!remotePackageVersion) { diff --git a/packages/foundations-ts-definitions/scripts/handle-cronjob.js b/packages/foundations-ts-definitions/scripts/handle-cronjob.js index 01e97fd845..ba568723ce 100644 --- a/packages/foundations-ts-definitions/scripts/handle-cronjob.js +++ b/packages/foundations-ts-definitions/scripts/handle-cronjob.js @@ -1,8 +1,7 @@ -const { execSync } = require('child_process') - +const { runCommand } = require('../../../scripts/release/utils') const bumpVersion = require('./bump-version') const releaseMaster = require('./release-master') -const gitStatus = execSync('git status -s').toString() +const gitStatus = runCommand('git', ['status', '-s']) // const { npm_package_version, GITHUB_TOKEN, GITHUB_ACTOR, GITHUB_REPOSITORY } = process.env diff --git a/packages/foundations-ts-definitions/scripts/release-master.js b/packages/foundations-ts-definitions/scripts/release-master.js index b1623978ed..79e8466587 100644 --- a/packages/foundations-ts-definitions/scripts/release-master.js +++ b/packages/foundations-ts-definitions/scripts/release-master.js @@ -1,5 +1,5 @@ const Octokit = require('@octokit/rest') -const { execSync } = require('child_process') +const { runCommand } = require('../../../scripts/release/utils') const fs = require('fs') const path = require('path') const { GITHUB_TOKEN } = process.env @@ -15,7 +15,7 @@ module.exports = async () => { try { // https://stackoverflow.com/questions/9110478/how-to-find-the-hash-of-branch-in-git - const currentHeadSHA = execSync('git rev-parse HEAD') + const currentHeadSHA = runCommand('git', ['rev-parse', 'HEAD']) const splittedGithubRepositoryParts = process.env.GITHUB_REPOSITORY.split('/') const ownerName = splittedGithubRepositoryParts[0] const repositoryName = splittedGithubRepositoryParts[1] diff --git a/scripts/release/release-dev.js b/scripts/release/release-dev.js index 90260761f0..d07c0159f6 100644 --- a/scripts/release/release-dev.js +++ b/scripts/release/release-dev.js @@ -1,6 +1,6 @@ #!/usr/bin/env node const path = require('path') -const { execSync } = require('child_process') +const { runCommand } = require('./utils') const releaseDev = () => { const [, , ...args] = process.argv @@ -19,9 +19,15 @@ const releaseDev = () => { const distPath = path.resolve(__dirname, '../../', 'packages', packageName, 'public', 'dist') - execSync( - `aws s3 cp ${distPath} s3://${bucketName} --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --recursive`, - ) + runCommand('aws', [ + 's3', + 'cp', + distPath, + `s3://${bucketName}`, + '--grants', + 'read=uri=http://acs.amazonaws.com/groups/global/AllUsers', + '--recursive', + ]) } releaseDev() diff --git a/scripts/release/release-npm.js b/scripts/release/release-npm.js index b0127d7168..8d0bdd0dc6 100644 --- a/scripts/release/release-npm.js +++ b/scripts/release/release-npm.js @@ -1,6 +1,5 @@ #!/usr/bin/env node -const { execSync } = require('child_process') -const { getPreviousTag, editReleaseNote, getVersionTag } = require('./utils') +const { getPreviousTag, editReleaseNote, getVersionTag, runCommand } = require('./utils') const releaseServerless = async () => { const [, , ...args] = process.argv @@ -12,7 +11,7 @@ const releaseServerless = async () => { } if (packageName === packageNameOnTag) { - execSync('npm publish') + runCommand('npm', ['publish']) const previousTag = getPreviousTag({ packageName: packageNameOnTag }) await editReleaseNote({ packageName: packageNameOnTag, version, previousTag }) diff --git a/scripts/release/release-prod.js b/scripts/release/release-prod.js index 3774e117a9..f5f2ab6135 100644 --- a/scripts/release/release-prod.js +++ b/scripts/release/release-prod.js @@ -1,7 +1,6 @@ #!/usr/bin/env node const path = require('path') -const { execSync } = require('child_process') -const { getPreviousTag, editReleaseNote, getVersionTag } = require('./utils') +const { getPreviousTag, editReleaseNote, getVersionTag, runCommand } = require('./utils') const releaseProd = async () => { const [, , ...args] = process.argv @@ -20,10 +19,15 @@ const releaseProd = async () => { if (packageName === packageNameOnTag) { const distPath = path.resolve(__dirname, '../../', 'packages', packageName, 'public', 'dist') - - execSync( - `aws s3 cp ${distPath} s3://${bucketName} --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --recursive`, - ) + runCommand('aws', [ + 's3', + 'cp', + distPath, + `s3://${bucketName}`, + '--grants', + 'read=uri=http://acs.amazonaws.com/groups/global/AllUsers', + '--recursive', + ]) const previousTag = getPreviousTag({ packageName: packageNameOnTag }) await editReleaseNote({ packageName: packageNameOnTag, version, previousTag }) diff --git a/scripts/release/release-serverless.js b/scripts/release/release-serverless.js index 6c808a6b89..d141ef0613 100644 --- a/scripts/release/release-serverless.js +++ b/scripts/release/release-serverless.js @@ -1,6 +1,5 @@ #!/usr/bin/env node -const { execSync } = require('child_process') -const { getPreviousTag, editReleaseNote, getVersionTag } = require('./utils') +const { getPreviousTag, editReleaseNote, getVersionTag, runCommand } = require('./utils') const releaseServerless = async () => { const [, , ...args] = process.argv @@ -12,7 +11,7 @@ const releaseServerless = async () => { } if (packageName === packageNameOnTag) { - execSync('cross-env CI=true serverless deploy --stage prod') + runCommand('cross-env', ['CI=true', 'serverless', 'deploy', '--stage', 'prod']) const previousTag = getPreviousTag({ packageName: packageNameOnTag }) await editReleaseNote({ packageName: packageNameOnTag, version, previousTag }) diff --git a/scripts/release/utils.js b/scripts/release/utils.js index aca4acc1b2..68de7ed837 100644 --- a/scripts/release/utils.js +++ b/scripts/release/utils.js @@ -1,5 +1,4 @@ #!/usr/bin/env node -const { execSync } = require('child_process') const spawn = require('child_process').spawnSync const Octokit = require('@octokit/rest') @@ -41,7 +40,15 @@ const getVersionTag = () => { } const getPreviousTag = ({ packageName }) => { - const tagName = execSync(`git describe --always --tags $(git rev-list --tags) | grep ${packageName}`).toString() + const tagName = runCommand('git', [ + 'describe', + '--always', + '--tags', + '$(git rev-list --tags)', + '|', + 'grep', + packageName, + ]) const tagNameArr = tagName.split('\n') const PREVIOUS_TAG_INDEX = 1 if (tagNameArr[PREVIOUS_TAG_INDEX]) { @@ -101,7 +108,7 @@ monitor: https://sentry.io/organizations/reapit-ltd/projects/` const editReleaseNote = async ({ packageName, version, previousTag }) => { try { - const commitLog = execSync(`git log ${packageName}_${version}...${previousTag}`).toString() + const commitLog = runCommand('git', ['log', `${packageName}_${version}...${previousTag}`]) const token = process.env.GITHUB_TOKEN const octokit = new Octokit({ auth: token }) const latestRelease = await octokit.repos.getReleaseByTag({