From b3ae43606e028ad612600d22c468efb4336ca464 Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Thu, 28 Nov 2019 00:23:13 +0100 Subject: [PATCH] fix: guide users to have GITHUB_TOKEN (#460) --- GUIDE.md | 19 +++++++++++++++++- packages/shipjs/src/flow/prepare.js | 2 ++ packages/shipjs/src/flow/release.js | 2 ++ packages/shipjs/src/step/checkGitHubToken.js | 21 ++++++++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 packages/shipjs/src/step/checkGitHubToken.js diff --git a/GUIDE.md b/GUIDE.md index e60046ab..a064c4f5 100644 --- a/GUIDE.md +++ b/GUIDE.md @@ -3,12 +3,13 @@ - [Installation](#installation) + - [GitHub Token](#github-token) - [Before running Shipjs](#before-running-shipjs) - [Dry Mode](#dry-mode) - [On your local machine](#on-your-local-machine) - [Automate Part 3 (`shipjs trigger`) on your CI](#automate-part-3-shipjs-trigger-on-your-ci) - [NPM Token](#npm-token) - - [GitHub Token](#github-token) + - [GitHub Token](#github-token-1) - [Useful Configurations](#useful-configurations) - [`mergeStrategy`](#mergestrategy) - [`toSameBranch` strategy](#tosamebranch-strategy) @@ -54,6 +55,22 @@ Add the following to the `scripts` section in your `package.json`. } ``` +### GitHub Token + +GitHub token is used in both `shipjs prepare` and `shipjs trigger`. + +1. Go to https://github.com/settings/tokens/new +2. Check "repo(Full control of private repositories)" +3. Generate/copy the token + +You can put it in the following two ways: + +1. Prepend it in your command like: `GITHUB_TOKEN=xxx shipjs prepare` +2. Create a file named ".env" and put the following content: `GITHUB_TOKEN=xxx` + (".env" should not be committed. Add it to ".gitignore".) + +If you automate flows in your CI, you can add the token to Environment Variable section in your CI service. + ### Before running Shipjs Shipjs compares previous version. diff --git a/packages/shipjs/src/flow/prepare.js b/packages/shipjs/src/flow/prepare.js index 9be06892..a865da99 100644 --- a/packages/shipjs/src/flow/prepare.js +++ b/packages/shipjs/src/flow/prepare.js @@ -18,6 +18,7 @@ import commitChanges from '../step/prepare/commitChanges'; import createPullRequest from '../step/prepare/createPullRequest'; import notifyPrepared from '../step/prepare/notifyPrepared'; import pushToStagingBranch from '../step/prepare/pushToStagingBranch'; +import checkGitHubToken from '../step/checkGitHubToken'; import finished from '../step/finished'; import { print } from '../util'; @@ -40,6 +41,7 @@ async function prepare({ printDryRunBanner(); } printDeprecated({ firstRelease, releaseCount }); + checkGitHubToken({ dryRun }); const config = loadConfig(dir); const { currentVersion, baseBranch } = validate({ config, dir }); validateMergeStrategy({ config }); diff --git a/packages/shipjs/src/flow/release.js b/packages/shipjs/src/flow/release.js index 94272d56..6c684193 100644 --- a/packages/shipjs/src/flow/release.js +++ b/packages/shipjs/src/flow/release.js @@ -14,6 +14,7 @@ import createGitTag from '../step/release/createGitTag'; import gitPush from '../step/release/gitPush'; import createGitHubRelease from '../step/release/createGitHubRelease'; import notifyReleaseSuccess from '../step/release/notifyReleaseSuccess'; +import checkGitHubToken from '../step/checkGitHubToken'; import finished from '../step/finished'; import { detectYarn } from '../util'; @@ -25,6 +26,7 @@ async function release({ help = false, dir = '.', dryRun = false }) { if (dryRun) { printDryRunBanner(); } + checkGitHubToken({ dryRun }); const config = loadConfig(dir); const { remote } = config; const { currentVersion: version } = validate({ config, dir }); diff --git a/packages/shipjs/src/step/checkGitHubToken.js b/packages/shipjs/src/step/checkGitHubToken.js new file mode 100644 index 00000000..7548f35a --- /dev/null +++ b/packages/shipjs/src/step/checkGitHubToken.js @@ -0,0 +1,21 @@ +import runStep from './runStep'; +import { print, exitProcess } from '../util'; +import { error } from '../color'; + +export default ({ dryRun }) => + runStep({ title: 'Checking GITHUB_TOKEN' }, () => { + if (process.env.GITHUB_TOKEN) { + return; + } + print( + error('You need to specify GITHUB_TOKEN as an environment variable.') + ); + print(' 1. GITHUB_TOKEN=xxx shipjs ...'); + print(' or'); + print(' 2. Create a file named ".env" and put the following content:'); + print(' GITHUB_TOKEN=xxx'); + print(' (".env" should not be committed. Add it to ".gitignore".)'); + if (!dryRun) { + exitProcess(1); + } + });