From 7ea75c32c6d3a9d0ace23bf603c4be4ddb504384 Mon Sep 17 00:00:00 2001 From: jeetiss Date: Wed, 4 Dec 2019 19:18:22 +0300 Subject: [PATCH 01/19] prepare setup for github actions --- packages/shipjs/src/flow/setup.js | 20 +++-- .../step/setup/{ => CI}/addCircleCIConfig.js | 16 +--- .../shipjs/src/step/setup/CI/askCircleCI.js | 37 ++++++++++ packages/shipjs/src/step/setup/CI/index.js | 17 +++++ .../shipjs/src/step/setup/askQuestions.js | 74 ++++--------------- .../shipjs/src/step/setup/formatMessage.js | 12 +++ 6 files changed, 98 insertions(+), 78 deletions(-) rename packages/shipjs/src/step/setup/{ => CI}/addCircleCIConfig.js (94%) create mode 100644 packages/shipjs/src/step/setup/CI/askCircleCI.js create mode 100644 packages/shipjs/src/step/setup/CI/index.js create mode 100644 packages/shipjs/src/step/setup/formatMessage.js diff --git a/packages/shipjs/src/flow/setup.js b/packages/shipjs/src/flow/setup.js index c1b0d49c..6ee1b1f8 100644 --- a/packages/shipjs/src/flow/setup.js +++ b/packages/shipjs/src/flow/setup.js @@ -4,7 +4,7 @@ import askQuestions from '../step/setup/askQuestions'; import addDevDependencies from '../step/setup/addDevDependencies'; import addScriptsToPackageJson from '../step/setup/addScriptsToPackageJson'; import addShipConfig from '../step/setup/addShipConfig'; -import addCircleCIConfig from '../step/setup/addCircleCIConfig'; +import integrations from '../step/setup/CI'; import { print } from '../util'; import { success } from '../color'; @@ -19,15 +19,14 @@ async function setup({ help = false, dir = '.', dryRun = false }) { const { baseBranch, releaseBranch, - configureCircleCI, - scheduleCircleCI, - cronExpr, useMonorepo, mainVersionFile, packagesToBump, packagesToPublish, isScoped, isPublic, + CIIndex, + CIConfig, } = await askQuestions({ dir }); const outputs = [ addDevDependencies({ dependencies: ['shipjs'], dir, dryRun }), @@ -44,11 +43,16 @@ async function setup({ help = false, dir = '.', dryRun = false }) { dir, dryRun, }), - addCircleCIConfig({ + await integrations[CIIndex].addConfig({ + ...CIConfig, + isScoped, + isPublic, baseBranch, - configureCircleCI, - scheduleCircleCI, - cronExpr, + releaseBranch, + useMonorepo, + mainVersionFile, + packagesToBump, + packagesToPublish, dir, dryRun, }), diff --git a/packages/shipjs/src/step/setup/addCircleCIConfig.js b/packages/shipjs/src/step/setup/CI/addCircleCIConfig.js similarity index 94% rename from packages/shipjs/src/step/setup/addCircleCIConfig.js rename to packages/shipjs/src/step/setup/CI/addCircleCIConfig.js index 1865866c..57637358 100644 --- a/packages/shipjs/src/step/setup/addCircleCIConfig.js +++ b/packages/shipjs/src/step/setup/CI/addCircleCIConfig.js @@ -1,24 +1,16 @@ import { getGitConfig } from 'shipjs-lib'; -import runStep from '../runStep'; +import runStep from '../../runStep'; import fs from 'fs'; import path from 'path'; import ejs from 'ejs'; import mkdirp from 'mkdirp'; -import { print } from '../../util'; -import { info, warning } from '../../color'; +import { print } from '../../../util'; +import { info, warning } from '../../../color'; -export default ({ - baseBranch, - configureCircleCI, - scheduleCircleCI, - cronExpr, - dir, - dryRun, -}) => +export default ({ baseBranch, scheduleCircleCI, cronExpr, dir, dryRun }) => runStep( { title: 'Creating CircleCI configuration', - skipIf: () => !configureCircleCI, }, () => { const filePath = path.resolve(dir, '.circleci', 'config.yml'); diff --git a/packages/shipjs/src/step/setup/CI/askCircleCI.js b/packages/shipjs/src/step/setup/CI/askCircleCI.js new file mode 100644 index 00000000..d69c6363 --- /dev/null +++ b/packages/shipjs/src/step/setup/CI/askCircleCI.js @@ -0,0 +1,37 @@ +import inquirer from 'inquirer'; +import formatMessage from '../formatMessage'; + +export default async function askCircleCI() { + const { scheduleCircleCI } = await inquirer.prompt([ + { + type: 'confirm', + name: 'scheduleCircleCI', + message: 'Schedule your release via CircleCI?', + default: true, + }, + ]); + const offset = new Date().getTimezoneOffset() / 60; + const hour = 11 + offset; + const tuesday = 2; + const defaultCronExpr = `0 ${hour} * * ${tuesday}`; + const { cronExpr } = await inquirer.prompt( + [ + scheduleCircleCI + ? { + type: 'input', + name: 'cronExpr', + message: formatMessage( + 'When to release?', + 'To learn about cron expressions, visit https://crontab.guru/\nThe default value ("Every Tuesday 11am")' + ), + default: defaultCronExpr, + } + : undefined, + ].filter(Boolean) + ); + + return { + scheduleCircleCI, + cronExpr, + }; +} diff --git a/packages/shipjs/src/step/setup/CI/index.js b/packages/shipjs/src/step/setup/CI/index.js new file mode 100644 index 00000000..1cd3946c --- /dev/null +++ b/packages/shipjs/src/step/setup/CI/index.js @@ -0,0 +1,17 @@ +import askCircleCI from './askCircleCI'; +import addCircleCIConfig from './addCircleCIConfig'; + +const noop = () => ({}); + +export default [ + { + name: 'Circle CI', + askQustions: askCircleCI, + addConfig: addCircleCIConfig, + }, + { + name: 'Nothing', + askQustions: noop, + addConfig: noop, + }, +]; diff --git a/packages/shipjs/src/step/setup/askQuestions.js b/packages/shipjs/src/step/setup/askQuestions.js index d5afad08..2a6147d4 100644 --- a/packages/shipjs/src/step/setup/askQuestions.js +++ b/packages/shipjs/src/step/setup/askQuestions.js @@ -2,24 +2,14 @@ import inquirer from 'inquirer'; import { getRemoteBranches } from 'shipjs-lib'; import fs from 'fs'; import path from 'path'; +import formatMessage from './formatMessage'; +import integrations from './CI'; import runStep from '../runStep'; -import { grey, reset } from '../../color'; - -const formatMessage = (message, description = '') => - [ - message, - ...description - .trim() - .split('\n') - .map(line => ` ${reset(grey(line.trim()))}`), - ].join('\n'); export default async ({ dir }) => await runStep({}, async () => { const { baseBranch, releaseBranch } = await askBranches(dir); - const { configureCircleCI, scheduleCircleCI, cronExpr } = await askCircleCI( - dir - ); + const { CIIndex, CIConfig } = await askCI(dir); const { useMonorepo, mainVersionFile, @@ -32,9 +22,8 @@ export default async ({ dir }) => return { baseBranch, releaseBranch, - configureCircleCI, - scheduleCircleCI, - cronExpr, + CIIndex, + CIConfig, useMonorepo, mainVersionFile, packagesToBump, @@ -82,52 +71,21 @@ async function askBranches(dir) { return { baseBranch, releaseBranch }; } -async function askCircleCI() { - const { configureCircleCI } = await inquirer.prompt([ +async function askCI() { + const choices = integrations.map(config => config.name); + const { CITypeText } = await inquirer.prompt([ { - type: 'confirm', - name: 'configureCircleCI', - message: 'Configure CircleCI?', - default: true, + type: 'list', + name: 'CITypeText', + message: 'Which CI configure?', + choices, }, ]); - const { scheduleCircleCI } = await inquirer.prompt( - [ - configureCircleCI - ? { - type: 'confirm', - name: 'scheduleCircleCI', - message: 'Schedule your release via CircleCI?', - default: true, - } - : undefined, - ].filter(Boolean) - ); - const offset = new Date().getTimezoneOffset() / 60; - const hour = 11 + offset; - const tuesday = 2; - const defaultCronExpr = `0 ${hour} * * ${tuesday}`; - const { cronExpr } = await inquirer.prompt( - [ - scheduleCircleCI - ? { - type: 'input', - name: 'cronExpr', - message: formatMessage( - 'When to release?', - 'To learn about cron expressions, visit https://crontab.guru/\nThe default value ("Every Tuesday 11am")' - ), - default: defaultCronExpr, - } - : undefined, - ].filter(Boolean) - ); - return { - configureCircleCI, - scheduleCircleCI, - cronExpr, - }; + const CIIndex = choices.indexOf(CITypeText); + const CIConfig = await integrations[CIIndex].askQustions(); + + return { CIIndex, CIConfig }; } async function askMonorepo(dir) { diff --git a/packages/shipjs/src/step/setup/formatMessage.js b/packages/shipjs/src/step/setup/formatMessage.js new file mode 100644 index 00000000..07a90e15 --- /dev/null +++ b/packages/shipjs/src/step/setup/formatMessage.js @@ -0,0 +1,12 @@ +import { grey, reset } from '../../color'; + +const formatMessage = (message, description = '') => + [ + message, + ...description + .trim() + .split('\n') + .map(line => ` ${reset(grey(line.trim()))}`), + ].join('\n'); + +export default formatMessage; From 915af26e9c98ed240da39888951958c0123ccc93 Mon Sep 17 00:00:00 2001 From: jeetiss Date: Sat, 7 Dec 2019 21:36:19 +0300 Subject: [PATCH 02/19] add base github actions integration --- .../src/step/setup/CI/addGithubActions.js | 79 +++++++++++++++++++ .../src/step/setup/CI/askGithubActions.js | 20 +++++ packages/shipjs/src/step/setup/CI/index.js | 8 ++ 3 files changed, 107 insertions(+) create mode 100644 packages/shipjs/src/step/setup/CI/addGithubActions.js create mode 100644 packages/shipjs/src/step/setup/CI/askGithubActions.js diff --git a/packages/shipjs/src/step/setup/CI/addGithubActions.js b/packages/shipjs/src/step/setup/CI/addGithubActions.js new file mode 100644 index 00000000..f7fef2eb --- /dev/null +++ b/packages/shipjs/src/step/setup/CI/addGithubActions.js @@ -0,0 +1,79 @@ +import { getGitConfig } from 'shipjs-lib'; +import runStep from '../../runStep'; +import fs from 'fs'; +import path from 'path'; +import ejs from 'ejs'; +import mkdirp from 'mkdirp'; +import { print } from '../../../util'; +import { info, warning } from '../../../color'; + +// manualPrepare +export default ({ releaseBranch, dir, dryRun }) => + runStep( + { + title: 'Creating GitHub Actions configuration', + }, + () => { + const filePath = path.resolve( + dir, + '.github/workflows', + 'shipjs-trigger.yml' + ); + + if (fs.existsSync(filePath)) { + return () => { + print( + `${warning( + '✘' + )} \`.github/workflows/shipjs-trigger.yml\` already exists.` + ); + print(' You can manually configure GitHub Actions'); + }; + } + const content = getBaseConfig({ + releaseBranch, + gitUserName: getGitConfig('user.name') || 'Your Name', + gitUserEmail: getGitConfig('user.email') || 'your@email.com', + }); + if (dryRun) { + print(`shipjs-trigger.yml`); + print(content); + } else { + mkdirp.sync(path.dirname(filePath)); + fs.writeFileSync(filePath, content); + } + return () => { + print(`${info('✔')} Created \`.github/workflows/shipjs-trigger.yml\`.`); + print(' You still need to finish setting up at GitHub Actions.'); + }; + } + ); + +function getBaseConfig({ releaseBranch, gitUserName, gitUserEmail }) { + return ejs.render( + ` +name: Ship js trigger + on: + push: + branches: + - <%= releaseBranch %> + jobs: + build: + name: Build + runs-on: Ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: actions/setup-node@master + with: + registry-url: "https://registry.npmjs.org" + - run: git switch master + - run: npm install + - run: npm run release:trigger + env: + GITHUB_TOKEN: \${{ secrets.GH_TOKEN }} + NODE_AUTH_TOKEN: \${{ secrets.NPM_TOKEN }} + +`, + { releaseBranch, gitUserName, gitUserEmail } + ); +} diff --git a/packages/shipjs/src/step/setup/CI/askGithubActions.js b/packages/shipjs/src/step/setup/CI/askGithubActions.js new file mode 100644 index 00000000..23092556 --- /dev/null +++ b/packages/shipjs/src/step/setup/CI/askGithubActions.js @@ -0,0 +1,20 @@ +import inquirer from 'inquirer'; +import formatMessage from '../formatMessage'; + +export default async function askGithubActions() { + const { manualPrepare } = await inquirer.prompt([ + { + type: 'confirm', + name: 'manualPrepare', + message: formatMessage( + 'Add manual prepare with issue comment?', + 'You can create `@shipjs prepare` comment on any issue and then github actions run `shipjs prepare`' + ), + default: true, + }, + ]); + + return { + manualPrepare, + }; +} diff --git a/packages/shipjs/src/step/setup/CI/index.js b/packages/shipjs/src/step/setup/CI/index.js index 1cd3946c..c8a8b29f 100644 --- a/packages/shipjs/src/step/setup/CI/index.js +++ b/packages/shipjs/src/step/setup/CI/index.js @@ -1,6 +1,9 @@ import askCircleCI from './askCircleCI'; import addCircleCIConfig from './addCircleCIConfig'; +import askGithubActions from './askGithubActions'; +import addGithubActions from './addGithubActions'; + const noop = () => ({}); export default [ @@ -9,6 +12,11 @@ export default [ askQustions: askCircleCI, addConfig: addCircleCIConfig, }, + { + name: 'Github Actions', + askQustions: askGithubActions, + addConfig: addGithubActions, + }, { name: 'Nothing', askQustions: noop, From 2be0e05068863e381735bcb8cd833b313fd59a53 Mon Sep 17 00:00:00 2001 From: jeetiss Date: Sat, 7 Dec 2019 22:22:36 +0300 Subject: [PATCH 03/19] add manual prepare config generation --- .../src/step/setup/CI/addGithubActions.js | 142 +++++++++++++----- 1 file changed, 107 insertions(+), 35 deletions(-) diff --git a/packages/shipjs/src/step/setup/CI/addGithubActions.js b/packages/shipjs/src/step/setup/CI/addGithubActions.js index f7fef2eb..fdb66049 100644 --- a/packages/shipjs/src/step/setup/CI/addGithubActions.js +++ b/packages/shipjs/src/step/setup/CI/addGithubActions.js @@ -7,49 +7,68 @@ import mkdirp from 'mkdirp'; import { print } from '../../../util'; import { info, warning } from '../../../color'; -// manualPrepare -export default ({ releaseBranch, dir, dryRun }) => +export default ({ releaseBranch, manualPrepare, dir, dryRun }) => runStep( { title: 'Creating GitHub Actions configuration', }, () => { - const filePath = path.resolve( - dir, - '.github/workflows', - 'shipjs-trigger.yml' - ); + const gitUserName = getGitConfig('user.name') || 'Your Name'; + const gitUserEmail = getGitConfig('user.email') || 'your@email.com'; - if (fs.existsSync(filePath)) { - return () => { - print( - `${warning( - '✘' - )} \`.github/workflows/shipjs-trigger.yml\` already exists.` - ); - print(' You can manually configure GitHub Actions'); - }; - } - const content = getBaseConfig({ - releaseBranch, - gitUserName: getGitConfig('user.name') || 'Your Name', - gitUserEmail: getGitConfig('user.email') || 'your@email.com', - }); - if (dryRun) { - print(`shipjs-trigger.yml`); - print(content); - } else { - mkdirp.sync(path.dirname(filePath)); - fs.writeFileSync(filePath, content); - } - return () => { - print(`${info('✔')} Created \`.github/workflows/shipjs-trigger.yml\`.`); - print(' You still need to finish setting up at GitHub Actions.'); - }; + const log = [ + createGithubAction({ + content: getBaseConfig({ releaseBranch }), + actionPath: '.github/workflows/shipjs-trigger.yml', + dir, + dryRun, + }), + manualPrepare && + createGithubAction({ + content: getManualPrepareConfig({ + releaseBranch, + dir, + dryRun, + gitUserName, + gitUserEmail, + }), + actionPath: '.github/workflows/shipjs-manual-prepare.yml', + dir, + dryRun, + }), + + () => { + print(' You still need to finish setting up at GitHub Actions.'); + // add link to readme here + }, + ].filter(Boolean); + + return () => log.forEach(printResult => printResult()); } ); -function getBaseConfig({ releaseBranch, gitUserName, gitUserEmail }) { +function createGithubAction({ content, actionPath, dir, dryRun }) { + const filePath = path.resolve(dir, actionPath); + + if (fs.existsSync(filePath)) { + return () => { + print(`${warning('✘')} \`${actionPath}\` already exists.`); + }; + } + + if (dryRun) { + print(actionPath); + print(content); + } else { + mkdirp.sync(path.dirname(filePath)); + fs.writeFileSync(filePath, content); + } + return () => { + print(`${info('✔')} Created \`${actionPath}\`.`); + }; +} + +function getBaseConfig({ releaseBranch }) { return ejs.render( ` name: Ship js trigger @@ -74,6 +93,59 @@ name: Ship js trigger NODE_AUTH_TOKEN: \${{ secrets.NPM_TOKEN }} `, - { releaseBranch, gitUserName, gitUserEmail } + { releaseBranch } + ); +} + +function getManualPrepareConfig({ gitUserName, gitUserEmail }) { + return ejs.render( + ` +name: Ship js Manual Prepare + on: + issue_comment: + types: [created] + jobs: + manual_prepare: + if: | + github.event_name == 'issue_comment' && + (github.event.comment.author_association == 'member' || github.event.comment.author_association == 'owner') && + startsWith(github.event.comment.body, '@shipjs prepare') + runs-on: Ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: actions/setup-node@master + - run: git switch master + - run: npm install + - run: | + git config --global user.email "<%= gitUserEmail %>" + git config --global user.name "<%= gitUserName %>" + - run: npm run release:prepare -- --yes --no-browse + env: + GITHUB_TOKEN: \${{ secrets.GH_TOKEN }} + + create_done_comment: + if: success() + needs: manual_prepare + runs-on: Ubuntu-latest + steps: + - uses: actions/github@master + env: + GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }} + with: + args: comment "@\${{ github.actor }} \`shipjs prepare\` done" + + create_fail_comment: + if: cancelled() || failure() + needs: manual_prepare + runs-on: Ubuntu-latest + steps: + - uses: actions/github@master + env: + GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }} + with: + args: comment "@\${{ github.actor }} \`shipjs prepare\` fail" + +`, + { gitUserName, gitUserEmail } ); } From fe2d8b0aab75169d736c6547c863b726399d2b69 Mon Sep 17 00:00:00 2001 From: jeetiss Date: Sat, 7 Dec 2019 22:28:36 +0300 Subject: [PATCH 04/19] fix --- packages/shipjs/src/flow/setup.js | 2 +- packages/shipjs/src/step/setup/CI/addGithubActions.js | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/shipjs/src/flow/setup.js b/packages/shipjs/src/flow/setup.js index 6ee1b1f8..6e6a2a8e 100644 --- a/packages/shipjs/src/flow/setup.js +++ b/packages/shipjs/src/flow/setup.js @@ -43,7 +43,7 @@ async function setup({ help = false, dir = '.', dryRun = false }) { dir, dryRun, }), - await integrations[CIIndex].addConfig({ + integrations[CIIndex].addConfig({ ...CIConfig, isScoped, isPublic, diff --git a/packages/shipjs/src/step/setup/CI/addGithubActions.js b/packages/shipjs/src/step/setup/CI/addGithubActions.js index fdb66049..9f87b4aa 100644 --- a/packages/shipjs/src/step/setup/CI/addGithubActions.js +++ b/packages/shipjs/src/step/setup/CI/addGithubActions.js @@ -26,9 +26,6 @@ export default ({ releaseBranch, manualPrepare, dir, dryRun }) => manualPrepare && createGithubAction({ content: getManualPrepareConfig({ - releaseBranch, - dir, - dryRun, gitUserName, gitUserEmail, }), From f4aa4e02d1ae3de334e82cd58d3434bb016aad9a Mon Sep 17 00:00:00 2001 From: jeetiss Date: Sun, 8 Dec 2019 12:59:36 +0300 Subject: [PATCH 05/19] checkout to base branch --- packages/shipjs/src/step/setup/CI/addGithubActions.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/shipjs/src/step/setup/CI/addGithubActions.js b/packages/shipjs/src/step/setup/CI/addGithubActions.js index 9f87b4aa..19401869 100644 --- a/packages/shipjs/src/step/setup/CI/addGithubActions.js +++ b/packages/shipjs/src/step/setup/CI/addGithubActions.js @@ -94,7 +94,7 @@ name: Ship js trigger ); } -function getManualPrepareConfig({ gitUserName, gitUserEmail }) { +function getManualPrepareConfig({ baseBranch, gitUserName, gitUserEmail }) { return ejs.render( ` name: Ship js Manual Prepare @@ -111,7 +111,7 @@ name: Ship js Manual Prepare steps: - uses: actions/checkout@master - uses: actions/setup-node@master - - run: git switch master + - run: git checkout <%= baseBranch %> - run: npm install - run: | git config --global user.email "<%= gitUserEmail %>" @@ -143,6 +143,6 @@ name: Ship js Manual Prepare args: comment "@\${{ github.actor }} \`shipjs prepare\` fail" `, - { gitUserName, gitUserEmail } + { baseBranch, gitUserName, gitUserEmail } ); } From a20a9a68a6d69f7186955297f2e9aa5755b68d14 Mon Sep 17 00:00:00 2001 From: jeetiss Date: Sat, 14 Dec 2019 10:53:36 +0300 Subject: [PATCH 06/19] switch to release branch before trigger --- packages/shipjs/src/step/setup/CI/addGithubActions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shipjs/src/step/setup/CI/addGithubActions.js b/packages/shipjs/src/step/setup/CI/addGithubActions.js index 19401869..c6aad32d 100644 --- a/packages/shipjs/src/step/setup/CI/addGithubActions.js +++ b/packages/shipjs/src/step/setup/CI/addGithubActions.js @@ -82,7 +82,7 @@ name: Ship js trigger - uses: actions/setup-node@master with: registry-url: "https://registry.npmjs.org" - - run: git switch master + - run: git switch <%= releaseBranch %> - run: npm install - run: npm run release:trigger env: From b77d6bcca6aa01e2f01b7f8784bb2f24264e8cf0 Mon Sep 17 00:00:00 2001 From: jeetiss Date: Sat, 14 Dec 2019 11:21:18 +0300 Subject: [PATCH 07/19] add schedule config --- .../src/step/setup/CI/addGithubActions.js | 61 +++++++++++++++++-- .../src/step/setup/CI/askGithubActions.js | 30 +++++++++ 2 files changed, 85 insertions(+), 6 deletions(-) diff --git a/packages/shipjs/src/step/setup/CI/addGithubActions.js b/packages/shipjs/src/step/setup/CI/addGithubActions.js index c6aad32d..96da2919 100644 --- a/packages/shipjs/src/step/setup/CI/addGithubActions.js +++ b/packages/shipjs/src/step/setup/CI/addGithubActions.js @@ -7,7 +7,15 @@ import mkdirp from 'mkdirp'; import { print } from '../../../util'; import { info, warning } from '../../../color'; -export default ({ releaseBranch, manualPrepare, dir, dryRun }) => +export default ({ + baseBranch, + releaseBranch, + manualPrepare, + schedulePrepare, + cronExpr, + dir, + dryRun, +}) => runStep( { title: 'Creating GitHub Actions configuration', @@ -26,6 +34,7 @@ export default ({ releaseBranch, manualPrepare, dir, dryRun }) => manualPrepare && createGithubAction({ content: getManualPrepareConfig({ + baseBranch, gitUserName, gitUserEmail, }), @@ -33,6 +42,18 @@ export default ({ releaseBranch, manualPrepare, dir, dryRun }) => dir, dryRun, }), + schedulePrepare && + createGithubAction({ + content: getScheduleConfig({ + baseBranch, + cronExpr, + gitUserName, + gitUserEmail, + }), + actionPath: '.github/workflows/shipjs-schedules-prepare.yml', + dir, + dryRun, + }), () => { print(' You still need to finish setting up at GitHub Actions.'); @@ -81,7 +102,7 @@ name: Ship js trigger - uses: actions/checkout@master - uses: actions/setup-node@master with: - registry-url: "https://registry.npmjs.org" + registry-url: 'https://registry.npmjs.org' - run: git switch <%= releaseBranch %> - run: npm install - run: npm run release:trigger @@ -114,8 +135,8 @@ name: Ship js Manual Prepare - run: git checkout <%= baseBranch %> - run: npm install - run: | - git config --global user.email "<%= gitUserEmail %>" - git config --global user.name "<%= gitUserName %>" + git config --global user.email '<%= gitUserEmail %>' + git config --global user.name '<%= gitUserName %>' - run: npm run release:prepare -- --yes --no-browse env: GITHUB_TOKEN: \${{ secrets.GH_TOKEN }} @@ -129,7 +150,7 @@ name: Ship js Manual Prepare env: GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }} with: - args: comment "@\${{ github.actor }} \`shipjs prepare\` done" + args: comment '@\${{ github.actor }} \`shipjs prepare\` done' create_fail_comment: if: cancelled() || failure() @@ -140,9 +161,37 @@ name: Ship js Manual Prepare env: GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }} with: - args: comment "@\${{ github.actor }} \`shipjs prepare\` fail" + args: comment '@\${{ github.actor }} \`shipjs prepare\` fail' `, { baseBranch, gitUserName, gitUserEmail } ); } + +function getScheduleConfig({ baseBranch, cronExpr, gitUserName, gitUserEmail }) { + return ejs.render( + ` +name: Ship js Schedule Prepare +on: + schedule: + # * is a special character in YAML so you have to quote this string + - cron: '<%= cronExpr %>' +jobs: + schedule_prepare: + runs-on: Ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: actions/setup-node@master + - run: git switch <%= baseBranch %> + - run: npm install + - run: | + git config --global user.email '<%= gitUserEmail %>' + git config --global user.name '<%= gitUserName %>' + - run: npm run release:prepare -- --yes --no-browse + env: + GITHUB_TOKEN: \${{ secrets.GH_TOKEN }} + +`, + { baseBranch, cronExpr, gitUserName, gitUserEmail } + ); +} diff --git a/packages/shipjs/src/step/setup/CI/askGithubActions.js b/packages/shipjs/src/step/setup/CI/askGithubActions.js index 23092556..86ed4511 100644 --- a/packages/shipjs/src/step/setup/CI/askGithubActions.js +++ b/packages/shipjs/src/step/setup/CI/askGithubActions.js @@ -14,7 +14,37 @@ export default async function askGithubActions() { }, ]); + const { schedulePrepare } = await inquirer.prompt([ + { + type: 'confirm', + name: 'schedulePrepare', + message: 'Schedule your release?', + default: true, + }, + ]); + const offset = new Date().getTimezoneOffset() / 60; + const hour = 11 + offset; + const tuesday = 2; + const defaultCronExpr = `0 ${hour} * * ${tuesday}`; + const { cronExpr } = await inquirer.prompt( + [ + schedulePrepare + ? { + type: 'input', + name: 'cronExpr', + message: formatMessage( + 'When to release?', + 'To learn about cron expressions, visit https://crontab.guru/\nThe default value ("Every Tuesday 11am")' + ), + default: defaultCronExpr, + } + : undefined, + ].filter(Boolean) + ); + return { manualPrepare, + schedulePrepare, + cronExpr }; } From 17acf7275989dadf8f0759ac9f51ab13ee0bb4d7 Mon Sep 17 00:00:00 2001 From: jeetiss Date: Sat, 14 Dec 2019 11:21:47 +0300 Subject: [PATCH 08/19] scheduleCircleCI -> schedulePrepare --- .../shipjs/src/step/setup/CI/addCircleCIConfig.js | 12 ++++++------ packages/shipjs/src/step/setup/CI/askCircleCI.js | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/shipjs/src/step/setup/CI/addCircleCIConfig.js b/packages/shipjs/src/step/setup/CI/addCircleCIConfig.js index 57637358..9b290aa6 100644 --- a/packages/shipjs/src/step/setup/CI/addCircleCIConfig.js +++ b/packages/shipjs/src/step/setup/CI/addCircleCIConfig.js @@ -7,7 +7,7 @@ import mkdirp from 'mkdirp'; import { print } from '../../../util'; import { info, warning } from '../../../color'; -export default ({ baseBranch, scheduleCircleCI, cronExpr, dir, dryRun }) => +export default ({ baseBranch, schedulePrepare, cronExpr, dir, dryRun }) => runStep( { title: 'Creating CircleCI configuration', @@ -30,7 +30,7 @@ export default ({ baseBranch, scheduleCircleCI, cronExpr, dir, dryRun }) => } const content = getConfig({ baseBranch, - scheduleCircleCI, + schedulePrepare, cronExpr, gitUserName: getGitConfig('user.name') || 'Your Name', gitUserEmail: getGitConfig('user.email') || 'your@email.com', @@ -54,7 +54,7 @@ export default ({ baseBranch, scheduleCircleCI, cronExpr, dir, dryRun }) => function getConfig({ baseBranch, - scheduleCircleCI, + schedulePrepare, cronExpr, gitUserName, gitUserEmail, @@ -106,7 +106,7 @@ jobs: - run: name: Run Tests command: yarn test -<% if (scheduleCircleCI) { %> +<% if (schedulePrepare) { %> prepare_release: <<: *defaults steps: @@ -141,7 +141,7 @@ workflows: - release_if_needed: requires: - test -<% if (scheduleCircleCI) { %> +<% if (schedulePrepare) { %> schedule_release: triggers: - schedule: @@ -154,6 +154,6 @@ workflows: - prepare_release <% } %> `, - { baseBranch, scheduleCircleCI, cronExpr, gitUserName, gitUserEmail } + { baseBranch, schedulePrepare, cronExpr, gitUserName, gitUserEmail } ); } diff --git a/packages/shipjs/src/step/setup/CI/askCircleCI.js b/packages/shipjs/src/step/setup/CI/askCircleCI.js index d69c6363..e3b13e37 100644 --- a/packages/shipjs/src/step/setup/CI/askCircleCI.js +++ b/packages/shipjs/src/step/setup/CI/askCircleCI.js @@ -2,10 +2,10 @@ import inquirer from 'inquirer'; import formatMessage from '../formatMessage'; export default async function askCircleCI() { - const { scheduleCircleCI } = await inquirer.prompt([ + const { schedulePrepare } = await inquirer.prompt([ { type: 'confirm', - name: 'scheduleCircleCI', + name: 'schedulePrepare', message: 'Schedule your release via CircleCI?', default: true, }, @@ -16,7 +16,7 @@ export default async function askCircleCI() { const defaultCronExpr = `0 ${hour} * * ${tuesday}`; const { cronExpr } = await inquirer.prompt( [ - scheduleCircleCI + schedulePrepare ? { type: 'input', name: 'cronExpr', @@ -31,7 +31,7 @@ export default async function askCircleCI() { ); return { - scheduleCircleCI, + schedulePrepare, cronExpr, }; } From c8584814ecdb442ba03a7a91e525ee8ebafc30dd Mon Sep 17 00:00:00 2001 From: jeetiss Date: Sat, 14 Dec 2019 12:02:38 +0300 Subject: [PATCH 09/19] rename NPM_TOKEN to NPM_AUTH_TOKEN for consistency --- packages/shipjs/src/step/setup/CI/addGithubActions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shipjs/src/step/setup/CI/addGithubActions.js b/packages/shipjs/src/step/setup/CI/addGithubActions.js index 96da2919..5214d266 100644 --- a/packages/shipjs/src/step/setup/CI/addGithubActions.js +++ b/packages/shipjs/src/step/setup/CI/addGithubActions.js @@ -108,7 +108,7 @@ name: Ship js trigger - run: npm run release:trigger env: GITHUB_TOKEN: \${{ secrets.GH_TOKEN }} - NODE_AUTH_TOKEN: \${{ secrets.NPM_TOKEN }} + NODE_AUTH_TOKEN: \${{ secrets.NPM_AUTH_TOKEN }} `, { releaseBranch } From f4bbde43bb9db6adfc94f7f816849b37015d6079 Mon Sep 17 00:00:00 2001 From: jeetiss Date: Tue, 17 Dec 2019 07:31:38 +0300 Subject: [PATCH 10/19] fix vars names and typos --- packages/shipjs/src/flow/setup.js | 8 ++++---- .../shipjs/src/step/setup/CI/addGithubActions.js | 7 ++++++- .../shipjs/src/step/setup/CI/askGithubActions.js | 2 +- packages/shipjs/src/step/setup/CI/index.js | 6 +++--- packages/shipjs/src/step/setup/askQuestions.js | 16 ++++++++-------- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/packages/shipjs/src/flow/setup.js b/packages/shipjs/src/flow/setup.js index 6e6a2a8e..69b8906a 100644 --- a/packages/shipjs/src/flow/setup.js +++ b/packages/shipjs/src/flow/setup.js @@ -25,8 +25,8 @@ async function setup({ help = false, dir = '.', dryRun = false }) { packagesToPublish, isScoped, isPublic, - CIIndex, - CIConfig, + ciIntegration, + ciConfig, } = await askQuestions({ dir }); const outputs = [ addDevDependencies({ dependencies: ['shipjs'], dir, dryRun }), @@ -43,8 +43,8 @@ async function setup({ help = false, dir = '.', dryRun = false }) { dir, dryRun, }), - integrations[CIIndex].addConfig({ - ...CIConfig, + integrations[ciIntegration].addConfig({ + ...ciConfig, isScoped, isPublic, baseBranch, diff --git a/packages/shipjs/src/step/setup/CI/addGithubActions.js b/packages/shipjs/src/step/setup/CI/addGithubActions.js index 5214d266..1d849bf1 100644 --- a/packages/shipjs/src/step/setup/CI/addGithubActions.js +++ b/packages/shipjs/src/step/setup/CI/addGithubActions.js @@ -168,7 +168,12 @@ name: Ship js Manual Prepare ); } -function getScheduleConfig({ baseBranch, cronExpr, gitUserName, gitUserEmail }) { +function getScheduleConfig({ + baseBranch, + cronExpr, + gitUserName, + gitUserEmail, +}) { return ejs.render( ` name: Ship js Schedule Prepare diff --git a/packages/shipjs/src/step/setup/CI/askGithubActions.js b/packages/shipjs/src/step/setup/CI/askGithubActions.js index 86ed4511..608d381d 100644 --- a/packages/shipjs/src/step/setup/CI/askGithubActions.js +++ b/packages/shipjs/src/step/setup/CI/askGithubActions.js @@ -45,6 +45,6 @@ export default async function askGithubActions() { return { manualPrepare, schedulePrepare, - cronExpr + cronExpr, }; } diff --git a/packages/shipjs/src/step/setup/CI/index.js b/packages/shipjs/src/step/setup/CI/index.js index c8a8b29f..1ee6173e 100644 --- a/packages/shipjs/src/step/setup/CI/index.js +++ b/packages/shipjs/src/step/setup/CI/index.js @@ -9,17 +9,17 @@ const noop = () => ({}); export default [ { name: 'Circle CI', - askQustions: askCircleCI, + askQuestions: askCircleCI, addConfig: addCircleCIConfig, }, { name: 'Github Actions', - askQustions: askGithubActions, + askQuestions: askGithubActions, addConfig: addGithubActions, }, { name: 'Nothing', - askQustions: noop, + askQuestions: noop, addConfig: noop, }, ]; diff --git a/packages/shipjs/src/step/setup/askQuestions.js b/packages/shipjs/src/step/setup/askQuestions.js index 2a6147d4..490b153a 100644 --- a/packages/shipjs/src/step/setup/askQuestions.js +++ b/packages/shipjs/src/step/setup/askQuestions.js @@ -9,7 +9,7 @@ import runStep from '../runStep'; export default async ({ dir }) => await runStep({}, async () => { const { baseBranch, releaseBranch } = await askBranches(dir); - const { CIIndex, CIConfig } = await askCI(dir); + const { ciIntegration, ciConfig } = await askCI(dir); const { useMonorepo, mainVersionFile, @@ -22,8 +22,8 @@ export default async ({ dir }) => return { baseBranch, releaseBranch, - CIIndex, - CIConfig, + ciIntegration, + ciConfig, useMonorepo, mainVersionFile, packagesToBump, @@ -73,19 +73,19 @@ async function askBranches(dir) { async function askCI() { const choices = integrations.map(config => config.name); - const { CITypeText } = await inquirer.prompt([ + const { ciTypeText } = await inquirer.prompt([ { type: 'list', - name: 'CITypeText', + name: 'ciTypeText', message: 'Which CI configure?', choices, }, ]); - const CIIndex = choices.indexOf(CITypeText); - const CIConfig = await integrations[CIIndex].askQustions(); + const ciIntegration = choices.indexOf(ciTypeText); + const ciConfig = await integrations[ciIntegration].askQuestions(); - return { CIIndex, CIConfig }; + return { ciIntegration, ciConfig }; } async function askMonorepo(dir) { From 3011f8e00dab3d7b96ba1729ecbbeb0779241893 Mon Sep 17 00:00:00 2001 From: jeetiss Date: Tue, 17 Dec 2019 07:34:53 +0300 Subject: [PATCH 11/19] Github to GitHub --- packages/shipjs/src/step/setup/CI/addGithubActions.js | 8 ++++---- packages/shipjs/src/step/setup/CI/askGithubActions.js | 2 +- packages/shipjs/src/step/setup/CI/index.js | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/shipjs/src/step/setup/CI/addGithubActions.js b/packages/shipjs/src/step/setup/CI/addGithubActions.js index 1d849bf1..e5786fab 100644 --- a/packages/shipjs/src/step/setup/CI/addGithubActions.js +++ b/packages/shipjs/src/step/setup/CI/addGithubActions.js @@ -25,14 +25,14 @@ export default ({ const gitUserEmail = getGitConfig('user.email') || 'your@email.com'; const log = [ - createGithubAction({ + createGitHubAction({ content: getBaseConfig({ releaseBranch }), actionPath: '.github/workflows/shipjs-trigger.yml', dir, dryRun, }), manualPrepare && - createGithubAction({ + createGitHubAction({ content: getManualPrepareConfig({ baseBranch, gitUserName, @@ -43,7 +43,7 @@ export default ({ dryRun, }), schedulePrepare && - createGithubAction({ + createGitHubAction({ content: getScheduleConfig({ baseBranch, cronExpr, @@ -65,7 +65,7 @@ export default ({ } ); -function createGithubAction({ content, actionPath, dir, dryRun }) { +function createGitHubAction({ content, actionPath, dir, dryRun }) { const filePath = path.resolve(dir, actionPath); if (fs.existsSync(filePath)) { diff --git a/packages/shipjs/src/step/setup/CI/askGithubActions.js b/packages/shipjs/src/step/setup/CI/askGithubActions.js index 608d381d..6a1edaee 100644 --- a/packages/shipjs/src/step/setup/CI/askGithubActions.js +++ b/packages/shipjs/src/step/setup/CI/askGithubActions.js @@ -1,7 +1,7 @@ import inquirer from 'inquirer'; import formatMessage from '../formatMessage'; -export default async function askGithubActions() { +export default async function askGitHubActions() { const { manualPrepare } = await inquirer.prompt([ { type: 'confirm', diff --git a/packages/shipjs/src/step/setup/CI/index.js b/packages/shipjs/src/step/setup/CI/index.js index 1ee6173e..21fb408b 100644 --- a/packages/shipjs/src/step/setup/CI/index.js +++ b/packages/shipjs/src/step/setup/CI/index.js @@ -1,8 +1,8 @@ import askCircleCI from './askCircleCI'; import addCircleCIConfig from './addCircleCIConfig'; -import askGithubActions from './askGithubActions'; -import addGithubActions from './addGithubActions'; +import askGitHubActions from './askGitHubActions'; +import addGitHubActions from './addGitHubActions'; const noop = () => ({}); @@ -13,9 +13,9 @@ export default [ addConfig: addCircleCIConfig, }, { - name: 'Github Actions', - askQuestions: askGithubActions, - addConfig: addGithubActions, + name: 'GitHub Actions', + askQuestions: askGitHubActions, + addConfig: addGitHubActions, }, { name: 'Nothing', From 89d2e1e7485c4e7a15718c33d65864a0b315e298 Mon Sep 17 00:00:00 2001 From: jeetiss Date: Tue, 17 Dec 2019 07:36:51 +0300 Subject: [PATCH 12/19] fix typo --- packages/shipjs/src/step/setup/CI/addGithubActions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shipjs/src/step/setup/CI/addGithubActions.js b/packages/shipjs/src/step/setup/CI/addGithubActions.js index e5786fab..5d20cf1c 100644 --- a/packages/shipjs/src/step/setup/CI/addGithubActions.js +++ b/packages/shipjs/src/step/setup/CI/addGithubActions.js @@ -50,7 +50,7 @@ export default ({ gitUserName, gitUserEmail, }), - actionPath: '.github/workflows/shipjs-schedules-prepare.yml', + actionPath: '.github/workflows/shipjs-schedule-prepare.yml', dir, dryRun, }), From e452c5331e72f7927bbe6a04aecb95aacf8d0365 Mon Sep 17 00:00:00 2001 From: jeetiss Date: Tue, 17 Dec 2019 13:57:16 +0300 Subject: [PATCH 13/19] fix prepare --- packages/shipjs/src/step/setup/CI/addGithubActions.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/shipjs/src/step/setup/CI/addGithubActions.js b/packages/shipjs/src/step/setup/CI/addGithubActions.js index 5d20cf1c..2bf48574 100644 --- a/packages/shipjs/src/step/setup/CI/addGithubActions.js +++ b/packages/shipjs/src/step/setup/CI/addGithubActions.js @@ -131,8 +131,10 @@ name: Ship js Manual Prepare runs-on: Ubuntu-latest steps: - uses: actions/checkout@master + with: + fetch-depth: 0 + ref: <%= baseBranch %> - uses: actions/setup-node@master - - run: git checkout <%= baseBranch %> - run: npm install - run: | git config --global user.email '<%= gitUserEmail %>' @@ -186,8 +188,10 @@ jobs: runs-on: Ubuntu-latest steps: - uses: actions/checkout@master + with: + fetch-depth: 0 + ref: <%= baseBranch %> - uses: actions/setup-node@master - - run: git switch <%= baseBranch %> - run: npm install - run: | git config --global user.email '<%= gitUserEmail %>' From 73c9b0999cad38933f0e183095f5571ea119266d Mon Sep 17 00:00:00 2001 From: jeetiss Date: Tue, 17 Dec 2019 16:02:33 +0300 Subject: [PATCH 14/19] return ciIntegration --- packages/shipjs/src/flow/setup.js | 3 +-- packages/shipjs/src/step/setup/askQuestions.js | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/shipjs/src/flow/setup.js b/packages/shipjs/src/flow/setup.js index 69b8906a..7e0bc967 100644 --- a/packages/shipjs/src/flow/setup.js +++ b/packages/shipjs/src/flow/setup.js @@ -4,7 +4,6 @@ import askQuestions from '../step/setup/askQuestions'; import addDevDependencies from '../step/setup/addDevDependencies'; import addScriptsToPackageJson from '../step/setup/addScriptsToPackageJson'; import addShipConfig from '../step/setup/addShipConfig'; -import integrations from '../step/setup/CI'; import { print } from '../util'; import { success } from '../color'; @@ -43,7 +42,7 @@ async function setup({ help = false, dir = '.', dryRun = false }) { dir, dryRun, }), - integrations[ciIntegration].addConfig({ + ciIntegration.addConfig({ ...ciConfig, isScoped, isPublic, diff --git a/packages/shipjs/src/step/setup/askQuestions.js b/packages/shipjs/src/step/setup/askQuestions.js index 490b153a..cf48163d 100644 --- a/packages/shipjs/src/step/setup/askQuestions.js +++ b/packages/shipjs/src/step/setup/askQuestions.js @@ -82,8 +82,8 @@ async function askCI() { }, ]); - const ciIntegration = choices.indexOf(ciTypeText); - const ciConfig = await integrations[ciIntegration].askQuestions(); + const ciIntegration = integrations[choices.indexOf(ciTypeText)]; + const ciConfig = await ciIntegration.askQuestions(); return { ciIntegration, ciConfig }; } From 4abc211dd868553f87c9988f653e0daee81e1608 Mon Sep 17 00:00:00 2001 From: shipjs Date: Tue, 17 Dec 2019 14:07:50 +0100 Subject: [PATCH 15/19] chore: rename files --- .../step/setup/CI/{addGithubActions.js => addGitHubActions.js} | 0 .../step/setup/CI/{askGithubActions.js => askGitHubActions.js} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename packages/shipjs/src/step/setup/CI/{addGithubActions.js => addGitHubActions.js} (100%) rename packages/shipjs/src/step/setup/CI/{askGithubActions.js => askGitHubActions.js} (100%) diff --git a/packages/shipjs/src/step/setup/CI/addGithubActions.js b/packages/shipjs/src/step/setup/CI/addGitHubActions.js similarity index 100% rename from packages/shipjs/src/step/setup/CI/addGithubActions.js rename to packages/shipjs/src/step/setup/CI/addGitHubActions.js diff --git a/packages/shipjs/src/step/setup/CI/askGithubActions.js b/packages/shipjs/src/step/setup/CI/askGitHubActions.js similarity index 100% rename from packages/shipjs/src/step/setup/CI/askGithubActions.js rename to packages/shipjs/src/step/setup/CI/askGitHubActions.js From 66b10321291faef41b55535ed5d7efe8de1790bd Mon Sep 17 00:00:00 2001 From: jeetiss Date: Wed, 18 Dec 2019 07:20:14 +0300 Subject: [PATCH 16/19] fix formatting --- .../src/step/setup/CI/addGitHubActions.js | 128 +++++++++--------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/packages/shipjs/src/step/setup/CI/addGitHubActions.js b/packages/shipjs/src/step/setup/CI/addGitHubActions.js index 2bf48574..28f80163 100644 --- a/packages/shipjs/src/step/setup/CI/addGitHubActions.js +++ b/packages/shipjs/src/step/setup/CI/addGitHubActions.js @@ -90,25 +90,25 @@ function getBaseConfig({ releaseBranch }) { return ejs.render( ` name: Ship js trigger - on: - push: - branches: - - <%= releaseBranch %> - jobs: - build: - name: Build - runs-on: Ubuntu-latest - steps: - - uses: actions/checkout@master - - uses: actions/setup-node@master - with: - registry-url: 'https://registry.npmjs.org' - - run: git switch <%= releaseBranch %> - - run: npm install - - run: npm run release:trigger - env: - GITHUB_TOKEN: \${{ secrets.GH_TOKEN }} - NODE_AUTH_TOKEN: \${{ secrets.NPM_AUTH_TOKEN }} +on: + push: + branches: + - <%= releaseBranch %> +jobs: + build: + name: Build + runs-on: Ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: actions/setup-node@master + with: + registry-url: 'https://registry.npmjs.org' + - run: git switch <%= releaseBranch %> + - run: npm install + - run: npm run release:trigger + env: + GITHUB_TOKEN: \${{ secrets.GH_TOKEN }} + NODE_AUTH_TOKEN: \${{ secrets.NPM_AUTH_TOKEN }} `, { releaseBranch } @@ -119,51 +119,51 @@ function getManualPrepareConfig({ baseBranch, gitUserName, gitUserEmail }) { return ejs.render( ` name: Ship js Manual Prepare - on: - issue_comment: - types: [created] - jobs: - manual_prepare: - if: | - github.event_name == 'issue_comment' && - (github.event.comment.author_association == 'member' || github.event.comment.author_association == 'owner') && - startsWith(github.event.comment.body, '@shipjs prepare') - runs-on: Ubuntu-latest - steps: - - uses: actions/checkout@master - with: - fetch-depth: 0 - ref: <%= baseBranch %> - - uses: actions/setup-node@master - - run: npm install - - run: | - git config --global user.email '<%= gitUserEmail %>' - git config --global user.name '<%= gitUserName %>' - - run: npm run release:prepare -- --yes --no-browse - env: - GITHUB_TOKEN: \${{ secrets.GH_TOKEN }} - - create_done_comment: - if: success() - needs: manual_prepare - runs-on: Ubuntu-latest - steps: - - uses: actions/github@master - env: - GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }} - with: - args: comment '@\${{ github.actor }} \`shipjs prepare\` done' - - create_fail_comment: - if: cancelled() || failure() - needs: manual_prepare - runs-on: Ubuntu-latest - steps: - - uses: actions/github@master - env: - GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }} - with: - args: comment '@\${{ github.actor }} \`shipjs prepare\` fail' +on: + issue_comment: + types: [created] +jobs: + manual_prepare: + if: | + github.event_name == 'issue_comment' && + (github.event.comment.author_association == 'member' || github.event.comment.author_association == 'owner') && + startsWith(github.event.comment.body, '@shipjs prepare') + runs-on: Ubuntu-latest + steps: + - uses: actions/checkout@master + with: + fetch-depth: 0 + ref: <%= baseBranch %> + - uses: actions/setup-node@master + - run: npm install + - run: | + git config --global user.email '<%= gitUserEmail %>' + git config --global user.name '<%= gitUserName %>' + - run: npm run release:prepare -- --yes --no-browse + env: + GITHUB_TOKEN: \${{ secrets.GH_TOKEN }} + + create_done_comment: + if: success() + needs: manual_prepare + runs-on: Ubuntu-latest + steps: + - uses: actions/github@master + env: + GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }} + with: + args: comment '@\${{ github.actor }} \`shipjs prepare\` done' + + create_fail_comment: + if: cancelled() || failure() + needs: manual_prepare + runs-on: Ubuntu-latest + steps: + - uses: actions/github@master + env: + GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }} + with: + args: comment '@\${{ github.actor }} \`shipjs prepare\` fail' `, { baseBranch, gitUserName, gitUserEmail } From 56eaeb0c14648d32a05a75a87da42b93ef033c00 Mon Sep 17 00:00:00 2001 From: jeetiss Date: Thu, 19 Dec 2019 12:06:54 +0300 Subject: [PATCH 17/19] use duble quotes in gh actions --- .../src/step/setup/CI/addGitHubActions.js | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/shipjs/src/step/setup/CI/addGitHubActions.js b/packages/shipjs/src/step/setup/CI/addGitHubActions.js index 28f80163..7595c40e 100644 --- a/packages/shipjs/src/step/setup/CI/addGitHubActions.js +++ b/packages/shipjs/src/step/setup/CI/addGitHubActions.js @@ -102,7 +102,7 @@ jobs: - uses: actions/checkout@master - uses: actions/setup-node@master with: - registry-url: 'https://registry.npmjs.org' + registry-url: "https://registry.npmjs.org" - run: git switch <%= releaseBranch %> - run: npm install - run: npm run release:trigger @@ -125,9 +125,9 @@ on: jobs: manual_prepare: if: | - github.event_name == 'issue_comment' && - (github.event.comment.author_association == 'member' || github.event.comment.author_association == 'owner') && - startsWith(github.event.comment.body, '@shipjs prepare') + github.event_name == "issue_comment" && + (github.event.comment.author_association == "member" || github.event.comment.author_association == "owner") && + startsWith(github.event.comment.body, "@shipjs prepare") runs-on: Ubuntu-latest steps: - uses: actions/checkout@master @@ -137,8 +137,8 @@ jobs: - uses: actions/setup-node@master - run: npm install - run: | - git config --global user.email '<%= gitUserEmail %>' - git config --global user.name '<%= gitUserName %>' + git config --global user.email "<%= gitUserEmail %>" + git config --global user.name "<%= gitUserName %>" - run: npm run release:prepare -- --yes --no-browse env: GITHUB_TOKEN: \${{ secrets.GH_TOKEN }} @@ -152,7 +152,7 @@ jobs: env: GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }} with: - args: comment '@\${{ github.actor }} \`shipjs prepare\` done' + args: comment "@\${{ github.actor }} \`shipjs prepare\` done" create_fail_comment: if: cancelled() || failure() @@ -163,7 +163,7 @@ jobs: env: GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }} with: - args: comment '@\${{ github.actor }} \`shipjs prepare\` fail' + args: comment "@\${{ github.actor }} \`shipjs prepare\` fail" `, { baseBranch, gitUserName, gitUserEmail } @@ -182,7 +182,7 @@ name: Ship js Schedule Prepare on: schedule: # * is a special character in YAML so you have to quote this string - - cron: '<%= cronExpr %>' + - cron: "<%= cronExpr %>" jobs: schedule_prepare: runs-on: Ubuntu-latest @@ -194,8 +194,8 @@ jobs: - uses: actions/setup-node@master - run: npm install - run: | - git config --global user.email '<%= gitUserEmail %>' - git config --global user.name '<%= gitUserName %>' + git config --global user.email "<%= gitUserEmail %>" + git config --global user.name "<%= gitUserName %>" - run: npm run release:prepare -- --yes --no-browse env: GITHUB_TOKEN: \${{ secrets.GH_TOKEN }} From 76a25487a4c3fba5483c0240f3cd6baa2cab62ce Mon Sep 17 00:00:00 2001 From: jeetiss Date: Thu, 19 Dec 2019 13:10:28 +0300 Subject: [PATCH 18/19] use single quote in condition --- packages/shipjs/src/step/setup/CI/addGitHubActions.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/shipjs/src/step/setup/CI/addGitHubActions.js b/packages/shipjs/src/step/setup/CI/addGitHubActions.js index 7595c40e..c3eb08e6 100644 --- a/packages/shipjs/src/step/setup/CI/addGitHubActions.js +++ b/packages/shipjs/src/step/setup/CI/addGitHubActions.js @@ -125,9 +125,9 @@ on: jobs: manual_prepare: if: | - github.event_name == "issue_comment" && - (github.event.comment.author_association == "member" || github.event.comment.author_association == "owner") && - startsWith(github.event.comment.body, "@shipjs prepare") + github.event_name == 'issue_comment' && + (github.event.comment.author_association == 'member' || github.event.comment.author_association == 'owner') && + startsWith(github.event.comment.body, '@shipjs prepare') runs-on: Ubuntu-latest steps: - uses: actions/checkout@master From 11fc704253453c287acbf1b23c4dc44625b6b620 Mon Sep 17 00:00:00 2001 From: jeetiss Date: Fri, 20 Dec 2019 14:08:32 +0300 Subject: [PATCH 19/19] use bash if statement to choose package manager --- .../src/step/setup/CI/addGitHubActions.js | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/shipjs/src/step/setup/CI/addGitHubActions.js b/packages/shipjs/src/step/setup/CI/addGitHubActions.js index c3eb08e6..091ca863 100644 --- a/packages/shipjs/src/step/setup/CI/addGitHubActions.js +++ b/packages/shipjs/src/step/setup/CI/addGitHubActions.js @@ -104,7 +104,12 @@ jobs: with: registry-url: "https://registry.npmjs.org" - run: git switch <%= releaseBranch %> - - run: npm install + - run: | + if [ -f "yarn.lock" ]; then + yarn install + else + npm install + fi - run: npm run release:trigger env: GITHUB_TOKEN: \${{ secrets.GH_TOKEN }} @@ -135,7 +140,12 @@ jobs: fetch-depth: 0 ref: <%= baseBranch %> - uses: actions/setup-node@master - - run: npm install + - run: | + if [ -f "yarn.lock" ]; then + yarn install + else + npm install + fi - run: | git config --global user.email "<%= gitUserEmail %>" git config --global user.name "<%= gitUserName %>" @@ -192,7 +202,12 @@ jobs: fetch-depth: 0 ref: <%= baseBranch %> - uses: actions/setup-node@master - - run: npm install + - run: | + if [ -f "yarn.lock" ]; then + yarn install + else + npm install + fi - run: | git config --global user.email "<%= gitUserEmail %>" git config --global user.name "<%= gitUserName %>"