semantic-release 17.2.1 → 17.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -105,3 +105,6 @@
|
|
|
105
105
|
- `verifyConditions`: Locate and validate a `.gemspec` file, locate and validate a `lib/**/version.rb` file, verify the presence of the `GEM_HOST_API_KEY` environment variable, and create a credentials file with the API key.
|
|
106
106
|
- `prepare`: Update the version in the `lib/**/version.rb` version file and [build](https://guides.rubygems.org/command-reference/#gem-build) the gem.
|
|
107
107
|
- `publish`: [Push the Ruby gem](https://guides.rubygems.org/command-reference/#gem-push) to the gem server.
|
|
108
|
+
- [semantic-release-npm-deprecate-old-versions](https://github.com/ghusse/semantic-release-npm-deprecate-old-versions)
|
|
109
|
+
- `verifyConditions`: Validates configuration.
|
|
110
|
+
- `publish`: Deprecates old versions, based on the declaration of supported versions in the config.
|
package/lib/get-git-auth-url.js
CHANGED
|
@@ -4,6 +4,48 @@ const hostedGitInfo = require('hosted-git-info');
|
|
|
4
4
|
const {verifyAuth} = require('./git');
|
|
5
5
|
const debug = require('debug')('semantic-release:get-git-auth-url');
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Machinery to format a repository URL with the given credentials
|
|
9
|
+
*
|
|
10
|
+
* @param {String} protocol URL protocol (which should not be present in repositoryUrl)
|
|
11
|
+
* @param {String} repositoryUrl User-given repository URL
|
|
12
|
+
* @param {String} gitCredentials The basic auth part of the URL
|
|
13
|
+
*
|
|
14
|
+
* @return {String} The formatted Git repository URL.
|
|
15
|
+
*/
|
|
16
|
+
function formatAuthUrl(protocol, repositoryUrl, gitCredentials) {
|
|
17
|
+
const [match, auth, host, basePort, path] =
|
|
18
|
+
/^(?!.+:\/\/)(?:(?<auth>.*)@)?(?<host>.*?):(?<port>\d+)?:?\/?(?<path>.*)$/.exec(repositoryUrl) || [];
|
|
19
|
+
const {port, hostname, ...parsed} = parse(
|
|
20
|
+
match ? `ssh://${auth ? `${auth}@` : ''}${host}${basePort ? `:${basePort}` : ''}/${path}` : repositoryUrl
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
return format({
|
|
24
|
+
...parsed,
|
|
25
|
+
auth: gitCredentials,
|
|
26
|
+
host: `${hostname}${protocol === 'ssh:' ? '' : port ? `:${port}` : ''}`,
|
|
27
|
+
protocol: protocol && /http[^s]/.test(protocol) ? 'http' : 'https',
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Verify authUrl by calling git.verifyAuth, but don't throw on failure
|
|
33
|
+
*
|
|
34
|
+
* @param {Object} context semantic-release context.
|
|
35
|
+
* @param {String} authUrl Repository URL to verify
|
|
36
|
+
*
|
|
37
|
+
* @return {String} The authUrl as is if the connection was successfull, null otherwise
|
|
38
|
+
*/
|
|
39
|
+
async function ensureValidAuthUrl({cwd, env, branch}, authUrl) {
|
|
40
|
+
try {
|
|
41
|
+
await verifyAuth(authUrl, branch.name, {cwd, env});
|
|
42
|
+
return authUrl;
|
|
43
|
+
} catch (error) {
|
|
44
|
+
debug(error);
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
7
49
|
/**
|
|
8
50
|
* Determine the the git repository URL to use to push, either:
|
|
9
51
|
* - The `repositoryUrl` as is if allowed to push
|
|
@@ -15,7 +57,8 @@ const debug = require('debug')('semantic-release:get-git-auth-url');
|
|
|
15
57
|
*
|
|
16
58
|
* @return {String} The formatted Git repository URL.
|
|
17
59
|
*/
|
|
18
|
-
module.exports = async (
|
|
60
|
+
module.exports = async (context) => {
|
|
61
|
+
const {cwd, env, branch} = context;
|
|
19
62
|
const GIT_TOKENS = {
|
|
20
63
|
GIT_CREDENTIALS: undefined,
|
|
21
64
|
GH_TOKEN: undefined,
|
|
@@ -30,6 +73,7 @@ module.exports = async ({cwd, env, branch, options: {repositoryUrl}}) => {
|
|
|
30
73
|
BITBUCKET_TOKEN_BASIC_AUTH: '',
|
|
31
74
|
};
|
|
32
75
|
|
|
76
|
+
let {repositoryUrl} = context.options;
|
|
33
77
|
const info = hostedGitInfo.fromUrl(repositoryUrl, {noGitPlus: true});
|
|
34
78
|
const {protocol, ...parsed} = parse(repositoryUrl);
|
|
35
79
|
|
|
@@ -47,24 +91,30 @@ module.exports = async ({cwd, env, branch, options: {repositoryUrl}}) => {
|
|
|
47
91
|
await verifyAuth(repositoryUrl, branch.name, {cwd, env});
|
|
48
92
|
} catch (_) {
|
|
49
93
|
debug('SSH key auth failed, falling back to https.');
|
|
94
|
+
const envVars = Object.keys(GIT_TOKENS).filter((envVar) => !isNil(env[envVar]));
|
|
95
|
+
|
|
96
|
+
// Skip verification if there is no ambiguity on which env var to use for authentication
|
|
97
|
+
if (envVars.length === 1) {
|
|
98
|
+
const gitCredentials = `${GIT_TOKENS[envVars[0]] || ''}${env[envVars[0]]}`;
|
|
99
|
+
return formatAuthUrl(protocol, repositoryUrl, gitCredentials);
|
|
100
|
+
}
|
|
50
101
|
|
|
51
|
-
|
|
52
|
-
|
|
102
|
+
if (envVars.length > 1) {
|
|
103
|
+
debug(`Found ${envVars.length} credentials in environment, trying all of them`);
|
|
53
104
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
);
|
|
105
|
+
const candidateRepositoryUrls = [];
|
|
106
|
+
for (const envVar of envVars) {
|
|
107
|
+
const gitCredentials = `${GIT_TOKENS[envVar] || ''}${env[envVar]}`;
|
|
108
|
+
const authUrl = formatAuthUrl(protocol, repositoryUrl, gitCredentials);
|
|
109
|
+
candidateRepositoryUrls.push(ensureValidAuthUrl(context, authUrl));
|
|
110
|
+
}
|
|
61
111
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
112
|
+
const validRepositoryUrls = await Promise.all(candidateRepositoryUrls);
|
|
113
|
+
const chosenAuthUrlIndex = validRepositoryUrls.findIndex((url) => url !== null);
|
|
114
|
+
if (chosenAuthUrlIndex > -1) {
|
|
115
|
+
debug(`Using "${envVars[chosenAuthUrlIndex]}" to authenticate`);
|
|
116
|
+
return validRepositoryUrls[chosenAuthUrlIndex];
|
|
117
|
+
}
|
|
68
118
|
}
|
|
69
119
|
}
|
|
70
120
|
|
package/package.json
CHANGED