This repository has been archived by the owner on Jan 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathindex.js
67 lines (57 loc) · 2.44 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const {parse} = require('url');
const GitHubApi = require('github');
const parseGithubUrl = require('parse-github-url');
const deployOnce = require('travis-deploy-once');
const SemanticReleaseError = require('@semantic-release/error');
const resolveConfig = require('./lib/resolve-config');
module.exports = async function(pluginConfig, {options: {branch, repositoryUrl}}) {
const {githubToken, githubUrl, githubApiPathPrefix, travisUrl} = resolveConfig(pluginConfig);
if (process.env.TRAVIS !== 'true') {
throw new SemanticReleaseError(
'semantic-release didn’t run on Travis CI and therefore a new version won’t be published.\nYou can customize this behavior using "verifyConditions" plugins: git.io/sr-plugins',
'ENOTRAVIS'
);
}
if (
Object.prototype.hasOwnProperty.call(process.env, 'TRAVIS_PULL_REQUEST') &&
process.env.TRAVIS_PULL_REQUEST !== 'false'
) {
throw new SemanticReleaseError(
'This test run was triggered by a pull request and therefore a new version won’t be published.',
'EPULLREQUEST'
);
}
if (branch !== process.env.TRAVIS_BRANCH) {
throw new SemanticReleaseError(
`This test run was triggered on the branch ${
process.env.TRAVIS_BRANCH
}, while semantic-release is configured to only publish from ${branch}.\nYou can customize this behavior using the "branch" option: git.io/sr-options`,
'EBRANCHMISMATCH'
);
}
const {name: repo, owner} = parseGithubUrl(repositoryUrl);
if (!owner || !repo) {
throw new SemanticReleaseError(
`The git repository URL ${repositoryUrl} is not a valid Github URL.`,
'EINVALIDGITURL'
);
}
let {port, protocol, hostname: host} = githubUrl ? parse(githubUrl) : {};
protocol = (protocol || '').split(':')[0] || null;
const github = new GitHubApi({port, protocol, host, pathPrefix: githubApiPathPrefix});
github.authenticate({type: 'token', token: githubToken});
const {data: {private: pro}} = await github.repos.get({owner, repo});
const result = await deployOnce({travisOpts: {pro, enterprise: travisUrl}});
if (result === null) {
throw new SemanticReleaseError(
'This test run is not the build leader and therefore a new version won’t be published.',
'ENOBUILDLEADER'
);
}
if (result === false) {
throw new SemanticReleaseError(
'In this test run not all jobs passed and therefore a new version won’t be published.',
'EOTHERSFAILED'
);
}
};