Package Exports
- travis-deploy-once
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (travis-deploy-once) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
travis-deploy-once
Run a deployment script only once in the Travis test matrix.
On Travis builds running multiple jobs (to test with multiple Node versions and/or OSs), run some code from the after_success
phase only once, after all other jobs have completed successfully.
Your code will run only on the job identified as the build leader, which is determined as follow, by order of priority:
- The job with the ID defined in BUILD_LEADER_ID.
- The job configured with the latest Node version (
node_js: node
). - The job with the highest node version
Note: If multiple jobs match, the one with the highest job ID (which corresponds to the last one defined in .travis.yml
) will be identified as the build leader.
Install
npm install --save travis-deploy-once
Usage
const deployOnce = require('travis-deploy-once');
try {
const result = await deployOnce({travisOpts: {pro: true}, GH_TOKEN: 'xxxxxx', BUILD_LEADER_ID: 1});
if (result === true) deployMyThing();
if (result === false) console.log('Some job(s) failed');
if (result === null) console.log('Did not run as the build leader');
} catch (err) {
// something went wrong, and err will tell you what
}
API
deployOnce([options])
Returns a Promise
that resolves to:
true
if the current Travis job is the build leader, the currentscript
phase is successful and all other job have completed successfully. => Your code can safely run.false
if at least one Travis job failed. => Your code should not run.null
if the current Travis job is not the build leader. => Your code should not run, and will be executed on the build leader.
Throws an Error
if:
- It doesn't run on Travis.
- The Github authentication token is missing.
- The Github authentication token is not authorized with Travis.
- It doesn't run on after_success step.
options
Type: Object
GH_TOKEN
Type: String
Default: process.env.GH_TOKEN
or process.env.GITHUB_TOKEN
GitHub OAuth token.
BUILD_LEADER_ID
Type: Number
Default: process.env.BUILD_LEADER_ID
Defined which Travis job will run the script (build leader). If not defined the build leader will be the Travis job running on the highest Node version.
travisOpts
Type: Object
pro
Type: Boolean
Default: false
true
to use Travis Pro, false
to use Travis for Open Source.
enterprise
Type: String
Travis Enterprise URL. If defined, the pro option will be ignored.
Note: This is the URL of the API endpoint, for example https://travis.example.com/api
.