Skip to content

Commit

Permalink
fix: pipeline deploy web-components (#2565)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pham Hai Duong authored Sep 4, 2020
1 parent df023b0 commit b171bbe
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 38 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/developer-portal/src/tests/badges/badge-lines.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions packages/foundations-ts-definitions/scripts/release-github.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ const { GITHUB_TOKEN } = process.env

module.exports = async () => {
try {
await runCommand('git', ['remote', 'add', 'sshOrigin', `[email protected]:${process.env.GITHUB_REPOSITORY}.git`])
await runCommand('git', ['config', '--global', 'user.email', '"[email protected]"'])
await runCommand('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"'])

await runCommand('git', ['add', '.'])
runCommand('git', ['add', '.'])
/**
* have to use execSync instead
* husky is throwing output to stderr
Expand Down
2 changes: 1 addition & 1 deletion packages/foundations-ts-definitions/scripts/update-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { FOUNDATION_ROOT_FOLDER, PACKAGE_NAME } = require('./constants')
const packageJsonPath = path.resolve(FOUNDATION_ROOT_FOLDER, './package.json')

module.exports = async () => {
const remotePackageVersionStdOut = await runCommand('yarn', [
const remotePackageVersionStdOut = runCommand('yarn', [
'info',
'@reapit/foundations-ts-definitions',
'version',
Expand Down
2 changes: 1 addition & 1 deletion packages/web-components/scripts/release-serverless.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const listServerless = [
const deployServerlessList = async () => {
// This will run when run particular widget by yarn release:development --name <widget_name> in web-components folder
if (name) {
await runCommand('serverless', ['deploy', '--config', `src/${name}/server/serverless.yml`, '--stage', stage])
runCommand('serverless', ['deploy', '--config', `src/${name}/server/serverless.yml`, '--stage', stage])
return
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/release/fetch-artifact.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const fetchCachedTarFile = async () => {
await sendMessageToSlack(
`Pulling the artifact \`${currentTag}\` from S3 bucket \`cloud-deployments-releases-cache-prod\``,
)
await runCommand('aws', [
runCommand('aws', [
's3',
'cp',
`s3://cloud-deployments-releases-cache-prod/${fileName}`,
Expand Down
12 changes: 6 additions & 6 deletions scripts/release/upload-artifact.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ const uploadArtifact = async () => {
workspaceName = '@reapit/web-components'
}
try {
await runCommand('yarn', ['workspace', workspaceName, 'fetch-config', '--name', 'production'])
await runCommand('yarn', ['workspace', workspaceName, 'lint'])
await runCommand('yarn', ['workspace', workspaceName, 'test:ci'])
await runCommand('yarn', ['workspace', workspaceName, 'build:prod'])
await runCommand('tar', [
runCommand('yarn', ['workspace', workspaceName, 'fetch-config', '--name', 'production'])
runCommand('yarn', ['workspace', workspaceName, 'lint'])
runCommand('yarn', ['workspace', workspaceName, 'test:ci'])
runCommand('yarn', ['workspace', workspaceName, 'build:prod'])
runCommand('tar', [
'-C',
`./packages/${packageName}/public`,
'-czvf',
fileName,
'--exclude="config.json"',
'dist',
])
await runCommand('aws', [
runCommand('aws', [
's3',
'cp',
fileName,
Expand Down
45 changes: 24 additions & 21 deletions scripts/release/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ const runCommand = (cmd, args) => {
return stdout.toString().trim()
}

const getRef = async () => {
const ref = await runCommand('git', ['rev-parse', '--short', 'HEAD'])
return ref
const getRef = () => {
return runCommand('git', ['rev-parse', '--short', 'HEAD'])
}

const getVersionTag = () => {
Expand Down Expand Up @@ -67,7 +66,7 @@ const sendMessageToSlack = async message => {
const extractTarFile = async ({ tagName, packageName }) => {
try {
const fileName = `${tagName}.tar.gz`
await runCommand('tar', [
runCommand('tar', [
'-C',
`./packages/${packageName}/public`,
'-xzvf',
Expand All @@ -87,13 +86,13 @@ const copyConfig = ({ packageName }) => {

const runReleaseCommand = async ({ packageName, tagName, env }) => {
await sendMessageToSlack(`Deploying for web app \`${packageName}\` with version \`${tagName}\``)
await runCommand('yarn', ['workspace', packageName, `release:${env}`])
runCommand('yarn', ['workspace', packageName, `release:${env}`])
await sendMessageToSlack(`Finish the deployment for web app \`${packageName}\` with version \`${tagName}\``)
}

const runTestCyPress = async ({ packageName, tagName, env }) => {
const runTestCypress = async ({ packageName, tagName, env }) => {
await sendMessageToSlack(`Testing cypress for web app \`${packageName}\` with version \`${tagName}\``)
await runCommand('yarn', [
runCommand('yarn', [
'workspace',
'cloud-alert',
'cypress:ci',
Expand All @@ -107,11 +106,15 @@ const releaseWebApp = async ({ tagName, packageName, env }) => {
try {
await extractTarFile({ tagName, packageName })
// Ignore copy config for web-components
if (packageName !== 'web-components') {
await copyConfig({ packageName })
if (packageName === 'web-components') {
packageName = '@reapit/web-components'
await runReleaseCommand({ packageName, tagName, env })
await runTestCypress({ packageName, tagName, env })
return
}
await copyConfig({ packageName })
await runReleaseCommand({ packageName, tagName, env })
await runTestCyPress({ packageName, tagName, env })
await runTestCypress({ packageName, tagName, env })
} catch (err) {
console.error('releaseWebApp', err)
throw new Error(err)
Expand All @@ -120,7 +123,7 @@ const releaseWebApp = async ({ tagName, packageName, env }) => {

const runReleaseCommandForWebComponents = async ({ packageName, tagName, env }) => {
await sendMessageToSlack(`Deploying for web app \`${packageName}\` with version \`${tagName}\``)
await runCommand('yarn', ['workspace', '@reapit/web-components', `release:serverless:${env}`, '--name', packageName])
runCommand('yarn', ['workspace', '@reapit/web-components', `release:serverless:${env}`, '--name', packageName])
await sendMessageToSlack(`Finish the deployment for web app \`${packageName}\` with version \`${tagName}\``)
}

Expand All @@ -131,15 +134,15 @@ const releaseServerless = async ({ tagName, packageName, env }) => {
}
try {
await sendMessageToSlack(`Checking out for \`${packageName}\` with version \`${tagName}\``)
await runCommand('git', ['checkout', tagName])
runCommand('git', ['checkout', tagName])
const isReleaseWebComponentPackage = WEB_COMPONENTS_SERVERLESS_APPS.includes(packageName)
if (isReleaseWebComponentPackage) {
await runReleaseCommandForWebComponents({ packageName: packageName, tagName, env })
await runTestCyPress({ packageName, tagName, env })
await runTestCypress({ packageName, tagName, env })
return
}
await runReleaseCommand({ packageName, tagName, env })
await runTestCyPress({ packageName, tagName, env })
await runTestCypress({ packageName, tagName, env })
return
} catch (err) {
console.error('releaseServerless', err)
Expand All @@ -150,13 +153,13 @@ const releaseServerless = async ({ tagName, packageName, env }) => {
const releaseNpm = async ({ tagName, packageName }) => {
try {
await sendMessageToSlack(`Checking out for \`${packageName}\` with version \`${tagName}\``)
await runCommand('git', ['checkout', tagName])
runCommand('git', ['checkout', tagName])
await sendMessageToSlack(`Releasing for npm \`${packageName}\` with version \`${tagName}\``)
await runCommand('git', ['config', '--global', 'url.ssh://[email protected]/.insteadOf https://github.com/'])
await runCommand('git', ['config', '--global', 'user.email', `"${process.env.GITHUB_ACTOR}@email.com"`]).toString()
await runCommand('git', ['config', ' --global', 'user.name', `"${process.env.GITHUB_ACTOR}"`])
await runCommand('yarn', ['workspace', packageName, 'build:prod'])
await runCommand('yarn', ['workspace', packageName, 'publish'])
runCommand('git', ['config', '--global', 'url.ssh://[email protected]/.insteadOf https://github.com/'])
runCommand('git', ['config', '--global', 'user.email', `"${process.env.GITHUB_ACTOR}@email.com"`]).toString()
runCommand('git', ['config', ' --global', 'user.name', `"${process.env.GITHUB_ACTOR}"`])
runCommand('yarn', ['workspace', packageName, 'build:prod'])
runCommand('yarn', ['workspace', packageName, 'publish'])
await sendMessageToSlack(`Finish the release for npm \`${packageName}\` with version \`${tagName}\``)
} catch (err) {
console.error('releaseNpm', err)
Expand Down Expand Up @@ -217,7 +220,7 @@ monitor: https://sentry.io/organizations/reapit-ltd/projects/
}

const getCommitLog = async ({ currentTag, previousTag, packageName }) => {
const commitLog = await runCommand('git', ['log', `${currentTag}...${previousTag}`, `./packages/${packageName}/.`])
const commitLog = runCommand('git', ['log', `${currentTag}...${previousTag}`, `./packages/${packageName}/.`])
return commitLog
}

Expand Down

0 comments on commit b171bbe

Please sign in to comment.