Skip to content

Commit

Permalink
fix: pipe line release prod (#250)
Browse files Browse the repository at this point in the history
* fix: change to runCommand function to view stdout

* fix: update script to build storybook for production

* fix: tsconfig for elements to build storybook
  • Loading branch information
duong-se authored Feb 12, 2020
1 parent 79007e1 commit 105e7cb
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 46 deletions.
7 changes: 3 additions & 4 deletions packages/cognito-auth/src/scripts/check-version.js
Original file line number Diff line number Diff line change
@@ -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 === '') {
Expand Down
2 changes: 1 addition & 1 deletion packages/elements/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion packages/elements/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
21 changes: 9 additions & 12 deletions packages/foundations-ts-definitions/scripts/bump-version.js
Original file line number Diff line number Diff line change
@@ -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']
Expand Down Expand Up @@ -38,12 +35,12 @@ module.exports = () => {
parsedPackageJsonContent.version = bumpedVersion
fs.writeFileSync(packageJsonPath, JSON.stringify(parsedPackageJsonContent, null, 2))

execSync(`git remote add sshOrigin [email protected]:${process.env.GITHUB_REPOSITORY}.git`)
execSync('git config --global user.email "[email protected]"')
execSync('git config --global user.name "Github Actions"')
runCommand('git', ['remote', 'add', 'sshOrigin', `[email protected]:${process.env.GITHUB_REPOSITORY}.git`])
runCommand('git', ['config', '--global', 'user.email', '"[email protected]"'])
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'])
}
7 changes: 3 additions & 4 deletions packages/foundations-ts-definitions/scripts/check-version.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
5 changes: 2 additions & 3 deletions packages/foundations-ts-definitions/scripts/handle-cronjob.js
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions packages/foundations-ts-definitions/scripts/release-master.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]
Expand Down
14 changes: 10 additions & 4 deletions scripts/release/release-dev.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
5 changes: 2 additions & 3 deletions scripts/release/release-npm.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 })
Expand Down
16 changes: 10 additions & 6 deletions scripts/release/release-prod.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 })
Expand Down
5 changes: 2 additions & 3 deletions scripts/release/release-serverless.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 })
Expand Down
13 changes: 10 additions & 3 deletions scripts/release/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env node
const { execSync } = require('child_process')
const spawn = require('child_process').spawnSync
const Octokit = require('@octokit/rest')

Expand Down Expand Up @@ -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]) {
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 105e7cb

Please sign in to comment.