ci-scripts
Advanced tools
Comparing version 0.8.2 to 0.9.0
@@ -23,4 +23,5 @@ { | ||
"no-inline-comments": "off", | ||
"line-comment-position": "off" | ||
"line-comment-position": "off", | ||
"complexity": "off" | ||
} | ||
} |
@@ -20,13 +20,1 @@ const docifyFolder = require('./docifyFolder'); | ||
}); | ||
exports.variableList = () => docifyFolder({ | ||
folder: 'lib/var', | ||
concatBlock: () => '', | ||
concatListItem: (name) => '- [`' + name + '`](#' + name.toLowerCase() + '-variable)\n', | ||
}); | ||
exports.variables = () => docifyFolder({ | ||
folder: 'lib/var', | ||
concatBlock: (name, src) => `#### \`${name}\` Variable\n\n` + src + '\n\n\n', | ||
concatListItem: () => '', | ||
}); |
# ci-scripts | ||
Useful scripts to execute from your CI runner. For example, post to Slack and GitHub: | ||
Useful scripts to execute from your CI runner. For example, | ||
post to Slack and GitHub when your build completes: | ||
@@ -10,33 +11,16 @@ ``` | ||
Upload build artifacts to S3: | ||
Uses [`cross-ci`](https://github.com/streamich/cross-ci) to normalize environment variables. | ||
``` | ||
ci s3-upload | ||
``` | ||
Bump NPM version automatically using semantic semver and push changed `package.json` to origin: | ||
##### Install | ||
``` | ||
ci npm-bump | ||
npm install ci-scripts | ||
``` | ||
See sample [Travis](./.travis.yml) and [CircleCI](./.circleci/config.yml) configurations. | ||
##### CLI usage | ||
## Usage | ||
You can use `ci-scripts` as a CLI tool as well as programmatically. | ||
### From Command Line | ||
Install globally or in your project repo to get started. | ||
``` | ||
npm install -g ci-scripts | ||
``` | ||
Test that it works. | ||
``` | ||
ci echo --message="It works" | ||
@@ -46,3 +30,3 @@ ``` | ||
### From Node.js | ||
##### Node usage | ||
@@ -56,3 +40,7 @@ ```js | ||
## Environment Variables | ||
`ci-scripts` uses [`cross-ci`](https://github.com/streamich/cross-ci). | ||
## Docs | ||
@@ -68,12 +56,5 @@ | ||
##### Variables | ||
```mmd | ||
return scripts.variableList(); | ||
``` | ||
##### CLI Params | ||
- `--plan` — don't execute the actual command, but show what it would do. | ||
- `--plan`, `--dry-run` — only show what would be done, without executing it. | ||
- `--verbose` — log extra info. | ||
@@ -90,12 +71,1 @@ - `-e`, `--eval` — evaluate command line params as template strings. | ||
``` | ||
## Variables | ||
`ci-scripts` pre-generates and normalizes across CI runners commonly used environment variables. | ||
The convetion is to use all upper case letters for "global" variables. | ||
```mmd | ||
return scripts.variables(); | ||
``` |
@@ -15,2 +15,21 @@ module.exports = { | ||
}, | ||
cmd: { | ||
release: { | ||
staging: { | ||
params: { | ||
command: './switch.sh', | ||
args: ['prod', 'web'], | ||
env: ({PROJECT_NAME, BUILD_VERSION}) => ({ | ||
NEW_KEY: `builds/${PROJECT_NAME}/${BUILD_VERSION}` | ||
}), | ||
} | ||
} | ||
}, | ||
year: { | ||
params: { | ||
command: 'printenv', | ||
args: 'YEAR' | ||
} | ||
} | ||
}, | ||
}; |
const minimist = require('minimist'); | ||
const exec = require('./exec'); | ||
/* eslint-disable no-console, no-process-exit */ | ||
const main = async () => { | ||
@@ -11,9 +12,8 @@ const {_: commands, ...params} = minimist(process.argv.slice(2)); | ||
if (result) { | ||
// eslint-disable-next-line no-console | ||
console.log(result); | ||
} | ||
process.exit(0); | ||
} catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.error(error); | ||
// eslint-disable-next-line no-process-exit | ||
process.exit(1); | ||
@@ -20,0 +20,0 @@ } |
const log = require('../effects/log'); | ||
const evalParam = require('../evalParam'); | ||
@@ -10,7 +9,3 @@ /// `echo` script simply prints a message to standard output. Set | ||
/// ``` | ||
const echo = (ci, params) => { | ||
if (typeof params.message === 'undefined') { | ||
throw new TypeError('echo command requires a "message" parameter.'); | ||
} | ||
const echo = (ci) => { | ||
/// Using `--eval` parameters get wrapped in template string literals and evaluated. | ||
@@ -23,8 +18,12 @@ /// You can use that to pring useful data. | ||
/// ``` | ||
const message = evalParam(ci, params.message); | ||
const {message} = ci.params; | ||
if (typeof ci.params.message === 'undefined') { | ||
throw new TypeError('echo command requires a "message" parameter.'); | ||
} | ||
// eslint-disable-next-line no-console | ||
log(ci, params, message); | ||
log(ci, message); | ||
}; | ||
module.exports = echo; |
/* eslint-disable filenames/match-exported */ | ||
const request = require('../effects/request'); | ||
const log = require('../effects/log'); | ||
const evalParam = require('../evalParam'); | ||
@@ -27,8 +26,8 @@ const headers = { | ||
/// Posts a message to your GitHub PR thread. | ||
const githubPost = async (ci, params) => { | ||
const {PROJECT_OWNER, PROJECT_NAME, BUILD_PR_NUM, GITHUB_TOKEN, IS_PR, GIT_COMMIT} = ci; | ||
const githubPost = async (ci) => { | ||
const {params, PROJECT_OWNER, PROJECT_NAME, BUILD_PR_NUM, GITHUB_TOKEN, IS_PR, BUILD_COMMIT} = ci; | ||
if (!IS_PR) { | ||
if (params.onlyPR) { | ||
log(ci, params, 'Will not post to GitHub, as build not triggered by a PR.'); | ||
log(ci, 'Will not post to GitHub, as build not triggered by a PR.'); | ||
@@ -71,11 +70,13 @@ return undefined; | ||
/// Use `--text` param to specify a custom message. Default message: | ||
/// | ||
/// > Build version: __`x.y.z-pr-1.1`__ | ||
let {text} = params; | ||
if (!text) { | ||
text = defaultMessage(ci); | ||
} | ||
const body = { | ||
body: evalParam(ci, | ||
/// Use `--text` param to specify a custom message. Default message: | ||
/// | ||
/// > Build version: __`x.y.z-pr-1.1`__ | ||
params.text | ||
|| defaultMessage | ||
) | ||
body: text, | ||
}; | ||
@@ -85,3 +86,3 @@ | ||
? `https://api.github.com/repos/${PROJECT_OWNER}/${PROJECT_NAME}/issues/${BUILD_PR_NUM}/comments?access_token=${token}` | ||
: `https://api.github.com/repos/${PROJECT_OWNER}/${PROJECT_NAME}/commits/${GIT_COMMIT}/comments?access_token=${token}`; | ||
: `https://api.github.com/repos/${PROJECT_OWNER}/${PROJECT_NAME}/commits/${BUILD_COMMIT}/comments?access_token=${token}`; | ||
@@ -96,5 +97,5 @@ const config = { | ||
const result = await request(ci, params, config); | ||
const result = await request(ci, config); | ||
log(ci, params, `Posted to GitHub: ${ci.BUILD_VERSION}`); | ||
log(ci, `Posted to GitHub: ${ci.BUILD_VERSION}`); | ||
@@ -101,0 +102,0 @@ return result; |
/* eslint-disable filenames/match-exported */ | ||
const evalParam = require('../evalParam'); | ||
const gitCommitAndForcePush = require('../effects/gitCommitAndForcePush'); | ||
@@ -9,7 +8,7 @@ | ||
/// the folder using `--folder` param. | ||
const githubUpload = async (ci, params) => { | ||
const folder = evalParam(ci, params.folder || 'docs'); | ||
const message = evalParam(ci, params.message || 'update docs'); | ||
const githubUpload = async (ci) => { | ||
const {params} = ci; | ||
const {folder = 'docs', message = 'update docs'} = params; | ||
return gitCommitAndForcePush(ci, params, { | ||
return gitCommitAndForcePush(ci, { | ||
branch: 'gh-pages', | ||
@@ -16,0 +15,0 @@ folder, |
@@ -1,18 +0,19 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const marked = require('marked'); | ||
const TerminalRenderer = require('marked-terminal'); | ||
const pkg = require('../../package.json'); | ||
marked.setOptions({ | ||
renderer: new TerminalRenderer() | ||
}); | ||
/// Prints README in terminal. | ||
const help = () => { | ||
const msg = fs.readFileSync(path.join(__dirname, '..', '..', 'README.md'), 'utf8'); | ||
const help = () => | ||
`${pkg.name} v${pkg.version} | ||
// eslint-disable-next-line no-console | ||
console.log(marked(msg)); | ||
}; | ||
Usage: ci <command> [sub-command] [subsub-command] [options] | ||
Use e.g. "ci slack --webhook=http://..." will post message to Slack". | ||
See https://github.com/streamich/ci-scripts for more commands. | ||
--config Path to configuration file [default: "ci.config.js"] | ||
--plan, --dry-run Do not touch or write anything, but show the commands | ||
--debug Print debug information | ||
-h, --help Print this help | ||
-v, --version Print version number | ||
-V, --verbose Verbose output`; | ||
module.exports = help; |
@@ -5,3 +5,2 @@ /* eslint-disable filenames/match-exported */ | ||
const gitForcePush = require('../effects/gitForcePush'); | ||
const evalParam = require('../evalParam'); | ||
@@ -26,3 +25,4 @@ const getRecommendedBump = () => new Promise((resolve, reject) => { | ||
const npmBump = async (ci, params) => { | ||
const npmBump = async (ci) => { | ||
const {params} = ci; | ||
let type = 'patch'; | ||
@@ -40,4 +40,4 @@ | ||
let message = evalParam(ci, params.message || defaultMessage); | ||
const skipCI = Boolean(typeof params.skipCI === 'undefined' ? true : evalParam(ci, params.skipCI)); | ||
let message = params.message || defaultMessage(ci); | ||
const skipCI = Boolean(typeof params.skipCI === 'undefined' ? true : params.skipCI); | ||
@@ -51,7 +51,7 @@ if (skipCI) { | ||
message, | ||
force: Boolean(evalParam(ci, params.force)), | ||
noTag: Boolean(evalParam(ci, params['no-tag'])), | ||
force: Boolean(params.force), | ||
noTag: Boolean(params['no-tag']), | ||
}); | ||
await gitForcePush(ci, params, { | ||
await gitForcePush(ci, { | ||
remote: ci.GIT_REMOTE, | ||
@@ -58,0 +58,0 @@ branch: ci.BUILD_BRANCH, |
/* eslint-disable filenames/match-exported */ | ||
const s3UploadDir = require('../effects/s3UploadDir'); | ||
const evalParam = require('../evalParam'); | ||
/// Uploads a folder and all its files recursively to a destination | ||
/// in a S3 bucket. | ||
const s3Upload = (ci, params) => { | ||
const bucket = evalParam(ci, params.bucket); | ||
const src = evalParam(ci, params.localDir) || 'dist/'; | ||
const s3Upload = (ci) => { | ||
const {params} = ci; | ||
const bucket = params.bucket; | ||
const src = params.localDir || 'dist/'; | ||
@@ -27,15 +27,15 @@ if (!bucket || (typeof bucket !== 'string')) { | ||
const config = { | ||
accessKeyId: evalParam(ci, params.accessKeyId), | ||
secretAccessKey: evalParam(ci, params.secretAccessKey), | ||
region: evalParam(ci, params.region), | ||
accessKeyId: params.accessKeyId, | ||
secretAccessKey: params.secretAccessKey, | ||
region: params.region, | ||
src, | ||
bucket, | ||
dest: evalParam(ci, params.dest) || '', | ||
acl: evalParam(ci, params.acl) || undefined, | ||
delete: Boolean(evalParam(ci, params.delete)), | ||
dest: params.dest || '', | ||
acl: params.acl || undefined, | ||
delete: Boolean(params.delete), | ||
}; | ||
return s3UploadDir(ci, params, config); | ||
return s3UploadDir(ci, config); | ||
}; | ||
module.exports = s3Upload; |
@@ -5,3 +5,2 @@ /* eslint-disable complexity */ | ||
const log = require('../effects/log'); | ||
const evalParam = require('../evalParam'); | ||
@@ -35,4 +34,4 @@ const headers = { | ||
const slack = async (ci, params) => { | ||
const param = (name) => evalParam(ci, params[name]); | ||
const slack = async (ci) => { | ||
const {params} = ci; | ||
const uri = params.webhook || ci.SLACK_WEBHOOK || process.env.SLACK_WEBHOOK; | ||
@@ -67,9 +66,6 @@ | ||
/// ``` | ||
text: evalParam(ci, | ||
params.text | ||
|| defaultMessage | ||
), | ||
text: params.text || defaultMessage(ci), | ||
/// Use `--username` param to overwrite sender's display name, defaults to `ci-scripts`. | ||
username: param('username') || 'ci-scripts', | ||
username: params.username || 'ci-scripts', | ||
@@ -83,3 +79,3 @@ /// Set emoji icon of the sender using `--icon_emoji` param, defaults to `javascript`. | ||
? `:${defaultEmoji}:` | ||
: ':' + (evalParam(ci, params.icon_emoji) || defaultEmoji) + ':', | ||
: ':' + (params.icon_emoji || defaultEmoji) + ':', | ||
}; | ||
@@ -89,3 +85,3 @@ | ||
/// Specify sender icon URL using `--icon_url` param. | ||
body.icon_url = evalParam(params.icon_url); | ||
body.icon_url = params.icon_url; | ||
} | ||
@@ -95,6 +91,6 @@ | ||
/// You can overwrite default channel using `--channel` param. | ||
body.channel = evalParam(params.channel); | ||
body.channel = params.channel; | ||
} | ||
const result = await request(ci, params, { | ||
const result = await request(ci, { | ||
method: 'POST', | ||
@@ -134,3 +130,3 @@ | ||
log(ci, params, `Posted to Slack: ${ci.BUILD_VERSION}`); | ||
log(ci, `Posted to Slack: ${ci.BUILD_VERSION}`); | ||
@@ -137,0 +133,0 @@ return result; |
@@ -1,5 +0,5 @@ | ||
const createVars = require('./createVars'); | ||
const createVars = require('cross-ci').createVars; | ||
const loadConfig = require('./loadConfig'); | ||
const createCi = async (commands, params = {}) => { | ||
const createCi = (commands, params = {}) => { | ||
if (!Array.isArray(commands)) { | ||
@@ -18,4 +18,6 @@ throw new TypeError('commands must be an array.'); | ||
const config = loadConfig(params.config); | ||
const vars = createVars(); | ||
let ci = { | ||
const ci = { | ||
vars, | ||
config, | ||
@@ -26,3 +28,4 @@ commands, | ||
ci = await createVars(ci); | ||
Object.assign(ci, vars); | ||
Object.assign(process.env, vars); | ||
@@ -29,0 +32,0 @@ return ci; |
@@ -9,5 +9,7 @@ const {execSync} = require('child_process'); | ||
const evalParam = require('../evalParam'); | ||
const isDryRun = require('../isDryRun'); | ||
const gitForcePush = require('./gitForcePush'); | ||
const gitCommitAndForcePush = async (ci, params, opts) => { | ||
const gitCommitAndForcePush = async (ci, opts) => { | ||
const {params} = ci; | ||
const { | ||
@@ -28,3 +30,3 @@ branch, | ||
if (params.plan) { | ||
if (isDryRun(params)) { | ||
// eslint-disable-next-line no-console | ||
@@ -31,0 +33,0 @@ console.log(chalk.cyan.bold('\n Will force push branch:\n')); |
@@ -5,4 +5,5 @@ /* eslint-disable no-console */ | ||
const {exec} = require('./util'); | ||
const isDryRun = require('.../isDryRun'); | ||
const gitForcePush = (ci, params, config) => { | ||
const gitForcePush = (ci, config) => { | ||
// eslint-disable-next-line prefer-const | ||
@@ -32,3 +33,3 @@ let {remote, branch, branchRemote = branch} = config; | ||
if (params.plan) { | ||
if (isDryRun(ci)) { | ||
console.log(chalk.cyan.bold('\n Will force push Git branch:\n')); | ||
@@ -35,0 +36,0 @@ console.log(util.inspect(config, { |
@@ -1,4 +0,10 @@ | ||
const log = (ci, params, msg) => { | ||
if (params.plan) { | ||
return; | ||
const chalk = require('chalk'); | ||
const isDryRun = require('../isDryRun'); | ||
const log = (ci, msg) => { | ||
if (isDryRun(ci)) { | ||
/* eslint-disable no-console */ | ||
console.log(chalk.cyan.bold('\n Will log message:')); | ||
console.log(chalk.magenta(`\n ${msg}\n`)); | ||
/* eslint-enable no-console */ | ||
} | ||
@@ -5,0 +11,0 @@ |
@@ -5,5 +5,6 @@ /* eslint-disable no-console */ | ||
const chalk = require('chalk'); | ||
const isDryRun = require('../isDryRun'); | ||
const {exec} = require('./util'); | ||
const npmBumpVersion = async (ci, params, opts) => { | ||
const npmBumpVersion = async (ci, opts) => { | ||
let parts = ['npm', 'version', opts.type]; | ||
@@ -25,3 +26,3 @@ | ||
if (params.plan) { | ||
if (isDryRun(ci)) { | ||
console.log(chalk.cyan.bold('\n Will bump NPM version:\n')); | ||
@@ -28,0 +29,0 @@ console.log(util.inspect(opts, { |
@@ -5,5 +5,8 @@ const util = require('util'); | ||
const evalParam = require('../evalParam'); | ||
const isDryRun = require('../isDryRun'); | ||
const request = async (ci, params, config) => { | ||
if (params.plan) { | ||
const request = async (ci, config) => { | ||
const {params} = ci; | ||
if (isDryRun(ci)) { | ||
// eslint-disable-next-line no-console | ||
@@ -10,0 +13,0 @@ console.log(chalk.cyan.bold('\n Will execute HTTP request:\n')); |
@@ -8,6 +8,7 @@ /* eslint-disable no-console */ | ||
const evalParam = require('../evalParam'); | ||
const isDryRun = require('../isDryRun'); | ||
http.globalAgent.maxSockets = https.globalAgent.maxSockets = 20; | ||
const s3UploadDir = (ci, params, config) => { | ||
const s3UploadDir = (ci, config) => { | ||
const { | ||
@@ -24,3 +25,11 @@ accessKeyId, | ||
if (params.plan) { | ||
if (isDryRun(ci)) { | ||
if (dest[0] === '/') { | ||
console.log(chalk.red( | ||
'Your S3 destination path starts with "/" forward slash. ' + | ||
'This will create an empty "" root folder. You might want to ' + | ||
'remove the forward slash.' | ||
)); | ||
} | ||
console.log(chalk.cyan.bold('\n Will upload to S3:\n')); | ||
@@ -35,3 +44,3 @@ console.log(util.inspect(config, { | ||
const isVerbose = evalParam(ci, params.verbose); | ||
const isVerbose = Boolean(evalParam(ci, ci.params.verbose)); | ||
@@ -38,0 +47,0 @@ const s3Config = { |
@@ -11,3 +11,3 @@ const createParamEvalWrapper = (ci) => [ | ||
const doEval = ci.params.eval || ci.params.e; | ||
const doEval = Boolean(ci.params.eval || ci.params.e); | ||
@@ -14,0 +14,0 @@ if (doEval) { |
/* eslint-disable no-console */ | ||
const getParams = require('./getParams'); | ||
const evalParam = require('./evalParam'); | ||
const createCi = require('./createCi'); | ||
@@ -40,8 +41,14 @@ | ||
const ci = await createCi(commands, params); | ||
const ci = createCi(commands, params); | ||
const fn = getFn(commands[0]); | ||
const commandParams = getParams(ci); | ||
ci.params = Object.assign(getParams(ci), ci.params); | ||
// eslint-disable-next-line guard-for-in | ||
for (const key in ci.params) { | ||
ci.params[key] = evalParam(ci, ci.params[key]); | ||
} | ||
try { | ||
const result = await fn(ci, commandParams); | ||
const result = await fn(ci); | ||
@@ -48,0 +55,0 @@ return result; |
{ | ||
"name": "ci-scripts", | ||
"version": "0.8.2", | ||
"version": "0.9.0", | ||
"bin": { | ||
@@ -12,3 +12,3 @@ "ci": "./bin/ci.js" | ||
"scripts": { | ||
"build": "echo 'There is no build script.' && exit 0", | ||
"build": "npm run build:readme", | ||
"build:readme": "mmarkdown --src ./build/readme.md --out README.md --scripts ./build/mmd.js", | ||
@@ -30,3 +30,4 @@ "test": "jest", | ||
"marked": "^0.3.19", | ||
"marked-terminal": "^2.0.0" | ||
"marked-terminal": "^2.0.0", | ||
"cross-ci": "^1.0.0" | ||
}, | ||
@@ -33,0 +34,0 @@ "devDependencies": { |
281
README.md
# ci-scripts | ||
Useful scripts to execute from your CI runner. For example, post to Slack: | ||
Useful scripts to execute from your CI runner. For example, | ||
post to Slack and GitHub when your build completes: | ||
``` | ||
ci slack --message="Build finished!" | ||
ci slack | ||
ci github-post | ||
``` | ||
Upload build artifacts to S3: | ||
Uses [`cross-ci`](https://github.com/streamich/cross-ci) to normalize environment variables. | ||
``` | ||
ci s3-upload | ||
``` | ||
Bump NPM version automatically using semantic semver and push changed `package.json` to origin: | ||
##### Install | ||
``` | ||
ci npm-bump --type=auto | ||
npm install ci-scripts | ||
``` | ||
See sample [Travis](./.travis.yml) and [CircleCI](./.circleci/config.yml) configurations. | ||
##### CLI usage | ||
## Usage | ||
You can use `ci-scripts` as a CLI tool as well as programmatically. | ||
### From Command Line | ||
Install globally or in your project repo to get started. | ||
``` | ||
npm install -g ci-scripts | ||
``` | ||
Test that it works. | ||
``` | ||
ci echo --message="It works" | ||
``` | ||
### From Node.js | ||
##### Node usage | ||
@@ -51,12 +35,8 @@ ```js | ||
## Docs | ||
## Environment Variables | ||
`ci-scripts` uses [`cross-ci`](https://github.com/streamich/cross-ci). | ||
##### CLI Params | ||
- `--plan` — don't execute the actual command, but show what it would do. | ||
- `--verbose` — log extra info. | ||
- `-e`, `--eval` — evaluate command line params as templat strings. | ||
- `-v`, `--version` — prints version. | ||
- `-h`, `--help` — prints README in terminal. | ||
## Docs | ||
@@ -70,2 +50,3 @@ | ||
- [`help`](#ci-help-script) | ||
- [`readme`](#ci-readme-script) | ||
- [`s3-upload`](#ci-s3-upload-script) | ||
@@ -78,27 +59,11 @@ - [`slack`](#ci-slack-script) | ||
##### Variables | ||
##### CLI Params | ||
- [`BUILD_BRANCH`](#build_branch-variable) | ||
- [`BUILD_NUM`](#build_num-variable) | ||
- [`BUILD_PR_NUM`](#build_pr_num-variable) | ||
- [`BUILD_PR_URL`](#build_pr_url-variable) | ||
- [`BUILD_URL`](#build_url-variable) | ||
- [`BUILD_VERSION`](#build_version-variable) | ||
- [`CI_NAME`](#ci_name-variable) | ||
- [`CI_PLATFORM`](#ci_platform-variable) | ||
- [`GITHUB_TOKEN`](#github_token-variable) | ||
- [`IS_PR`](#is_pr-variable) | ||
- [`IS_RELEASE`](#is_release-variable) | ||
- [`MONTH`](#month-variable) | ||
- [`PROJECT_NAME`](#project_name-variable) | ||
- [`PROJECT_OWNER`](#project_owner-variable) | ||
- [`PROJECT_URL`](#project_url-variable) | ||
- [`PROJECT_VERSION`](#project_version-variable) | ||
- [`RELEASE_BRANCHES`](#release_branches-variable) | ||
- [`UPLOAD_PATH`](#upload_path-variable) | ||
- [`YEAR`](#year-variable) | ||
- `--plan`, `--dry-run` — only show what would be done, without executing it. | ||
- `--verbose` — log extra info. | ||
- `-e`, `--eval` — evaluate command line params as template strings. | ||
- `-v`, `--version` — prints version. | ||
- `-h`, `--help` — prints README in terminal. | ||
## Scripts | ||
@@ -120,3 +85,2 @@ | ||
Using `--eval` parameters get wrapped in template string literals and evaluated. | ||
@@ -196,2 +160,11 @@ You can use that to pring useful data. | ||
### `ci readme` Script | ||
Prints README in terminal. | ||
### `ci s3-upload` Script | ||
@@ -293,4 +266,3 @@ | ||
Prints out the version of `ci-scripts`. Use it in | ||
one the three ways below. | ||
Prints out the version of `ci-scripts`. | ||
@@ -307,196 +279,1 @@ ``` | ||
## Variables | ||
`ci-scripts` pre-generates and normalizes across CI runners commonly used environment variables. | ||
The convetion is to use all upper case letters for "global" variables. | ||
#### `BUILD_BRANCH` Variable | ||
Name of the Git branch which is currently being built. | ||
In CircleCI the `CIRCLE_BRANCH` environment variable is used. | ||
In TravisCI it is set to `TRAVIS_PULL_REQUEST_BRANCH` if the build originated | ||
as a pull request, or `TRAVIS_BRANCH` otherwise. | ||
If `BUILD_BRANCH` environment variable is present, uses that. | ||
```shell | ||
BUILD_BRANCH=test ci echo --message "branch: \${BUILD_BRANCH}" | ||
``` | ||
#### `BUILD_NUM` Variable | ||
Build number, a numeric value uniquely identifying current build. | ||
In CircleCI equals to `CIRCLE_BUILD_NUM` environment variable. | ||
In TravisCI equals to `TRAVIS_BUILD_NUMBER` environment variable. | ||
Otherwise tries `BUILD_NUM` environment variable. | ||
If not build number detected, defaults to `0`. | ||
#### `BUILD_PR_NUM` Variable | ||
Number of the pull request on GitHub. | ||
In CircleCI pull request number is extracted from `CI_PULL_REQUEST` environment variable. | ||
Which is a link to the pull request of the current job. | ||
In TravicCI `TRAVIS_PULL_REQUEST` environment varialbe is used. | ||
Will also try `BUILD_PR_NUM` environment variable. | ||
Otherwise defaults to `0`. | ||
#### `BUILD_PR_URL` Variable | ||
URL to GitHub PR page. | ||
#### `BUILD_URL` Variable | ||
URL to CI build page. | ||
#### `BUILD_VERSION` Variable | ||
A human-readable string uniquely identifying current build. | ||
For pull requests will equal to something like `x.y.z-pr-1.1`. | ||
For build jobs that are not part of a pull request, | ||
it will contain a branch name, like `x.y.z-master.1`. | ||
#### `CI_NAME` Variable | ||
A user-friendly CI display name. | ||
- `CircleCI` for CircleCI | ||
- `Travis` for TravisCI | ||
#### `CI_PLATFORM` Variable | ||
A string identifying the CI platform. | ||
- `circle` for CircleCI | ||
- `travis` for TravisCI | ||
#### `GITHUB_TOKEN` Variable | ||
Equals to `GITHUB_TOKEN` or `GITHUB_ACCESS_TOKEN` environment variables, in that order. | ||
#### `IS_PR` Variable | ||
Boolean, `true` if the current build is triggered by a pull request. | ||
#### `IS_RELEASE` Variable | ||
Is `true` if currently built branch is one of `RELEASE_BRANCHES`. | ||
#### `MONTH` Variable | ||
Current month numeric value as a string of length two. | ||
#### `PROJECT_NAME` Variable | ||
GitHub project name. Below is a list of environment variables per CI used to | ||
detect project name: | ||
- CircleCI: [`CIRCLE_PROJECT_REPONAME`](https://circleci.com/docs/1.0/environment-variables/#build-details) | ||
- TravisCI: [`TRAVIS_REPO_SLUG`](https://docs.travis-ci.com/user/environment-variables/) | ||
If environment variables are empty, it will also try to extract | ||
project name from `package.json`. First it will try `name` field. | ||
If project name is not specified in `name` field, it will | ||
try `repository.url` field. | ||
#### `PROJECT_OWNER` Variable | ||
User name or organization name that owns the repository. | ||
In TravisCI it extracts repository owner from `user/repo` slug `TRAVIS_REPO_SLUG`. | ||
It will also try to extract repository owner from `package.json`, | ||
using `repository.url` field. | ||
#### `PROJECT_URL` Variable | ||
Link to project on GitHub. | ||
#### `PROJECT_VERSION` Variable | ||
Semver version of your project. Taken from `package.json`. | ||
#### `RELEASE_BRANCHES` Variable | ||
Names of branches which should trigger a release when they are built. | ||
Defaults to `['master', 'develop', 'next-release', 'release']`. | ||
#### `UPLOAD_PATH` Variable | ||
Relative upload path where artifacts will be stored. | ||
For a pull request it defaults to: | ||
```js | ||
`/builds/${PROJECT_NAME}/prs/${YEAR}-${MONTH}/${BUILD_VERSION}` | ||
``` | ||
Which results into something like: | ||
``` | ||
/builds/repo/prs/2018-04/1.2.3-pr-1.1` | ||
``` | ||
For not pull request it defaults to: | ||
```js | ||
`/builds/${PROJECT_NAME}/${BUILD_BRANCH}` | ||
``` | ||
Which results into something like: | ||
``` | ||
/builds/repo/master` | ||
``` | ||
#### `YEAR` Variable | ||
Current year as a four character long string. | ||
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 8 instances in 1 package
12
51471
11
49
1276
273
+ Addedcross-ci@^1.0.0
+ Addedcross-ci@1.7.0(transitive)
+ Addedcross-spawn@6.0.5(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedenv-ci@2.6.0(transitive)
+ Addedexeca@1.0.0(transitive)
+ Addedget-stream@4.1.0(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedjava-properties@0.2.10(transitive)
+ Addednice-try@1.0.5(transitive)
+ Addednpm-run-path@2.0.2(transitive)
+ Addedp-finally@1.0.0(transitive)
+ Addedpath-key@2.0.1(transitive)
+ Addedpump@3.0.0(transitive)
+ Addedshebang-command@1.2.0(transitive)
+ Addedshebang-regex@1.0.0(transitive)
+ Addedstrip-eof@1.0.0(transitive)
+ Addedwhich@1.3.1(transitive)