Skip to content

Commit

Permalink
fix: guide users to have GITHUB_TOKEN (#460)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunjae Lee authored Nov 27, 2019
1 parent cfd4b2f commit b3ae436
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
19 changes: 18 additions & 1 deletion GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
<!-- toc -->

- [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)
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions packages/shipjs/src/flow/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 });
Expand Down
2 changes: 2 additions & 0 deletions packages/shipjs/src/flow/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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 });
Expand Down
21 changes: 21 additions & 0 deletions packages/shipjs/src/step/checkGitHubToken.js
Original file line number Diff line number Diff line change
@@ -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);
}
});

0 comments on commit b3ae436

Please sign in to comment.