semantic-release 26.0.0-beta.2 → 26.0.0-beta.3
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.
- package/index.js +8 -12
- package/lib/get-git-auth-url.js +6 -2
- package/lib/git.js +41 -11
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -83,19 +83,15 @@ async function run(context, plugins) {
|
|
|
83
83
|
}`
|
|
84
84
|
);
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
`The local branch ${context.branch.name} is behind the remote one, therefore a new version won't be published.`
|
|
93
|
-
);
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
86
|
+
if (!(await isBranchUpToDate(options.repositoryUrl, context.branch.name, { cwd, env }))) {
|
|
87
|
+
logger.log(
|
|
88
|
+
`The local branch ${context.branch.name} is behind the remote one, therefore a new version won't be published.`
|
|
89
|
+
);
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
96
92
|
|
|
97
|
-
|
|
98
|
-
}
|
|
93
|
+
try {
|
|
94
|
+
await verifyAuth(options.repositoryUrl, { cwd, env });
|
|
99
95
|
} catch (error) {
|
|
100
96
|
logger.error(`The command "${error.command}" failed with the error message ${error.stderr}.`);
|
|
101
97
|
throw getError("EGITNOPERMISSION", context);
|
package/lib/get-git-auth-url.js
CHANGED
|
@@ -16,6 +16,10 @@ const debug = debugAuthUrl("semantic-release:get-git-auth-url");
|
|
|
16
16
|
* @return {String} The formatted Git repository URL.
|
|
17
17
|
*/
|
|
18
18
|
function formatAuthUrl(protocol, repositoryUrl, gitCredentials) {
|
|
19
|
+
if (protocol === "file:") {
|
|
20
|
+
return repositoryUrl;
|
|
21
|
+
}
|
|
22
|
+
|
|
19
23
|
const [match, auth, host, basePort, path] =
|
|
20
24
|
/^(?!.+:\/\/)(?:(?<auth>.*)@)?(?<host>.*?):(?<port>\d+)?:?\/?(?<path>.*)$/.exec(repositoryUrl) || [];
|
|
21
25
|
const { port, hostname, ...parsed } = parse(
|
|
@@ -40,7 +44,7 @@ function formatAuthUrl(protocol, repositoryUrl, gitCredentials) {
|
|
|
40
44
|
*/
|
|
41
45
|
async function ensureValidAuthUrl({ cwd, env, branch }, authUrl) {
|
|
42
46
|
try {
|
|
43
|
-
await verifyAuth(authUrl,
|
|
47
|
+
await verifyAuth(authUrl, { cwd, env });
|
|
44
48
|
return authUrl;
|
|
45
49
|
} catch (error) {
|
|
46
50
|
debug(error);
|
|
@@ -90,7 +94,7 @@ export default async (context) => {
|
|
|
90
94
|
// Test if push is allowed without transforming the URL (e.g. is ssh keys are set up)
|
|
91
95
|
try {
|
|
92
96
|
debug("Verifying ssh auth by attempting to push to %s", repositoryUrl);
|
|
93
|
-
await verifyAuth(repositoryUrl,
|
|
97
|
+
await verifyAuth(repositoryUrl, { cwd, env });
|
|
94
98
|
} catch {
|
|
95
99
|
debug("SSH key auth failed, falling back to https.");
|
|
96
100
|
const envVars = Object.keys(GIT_TOKENS).filter((envVar) => !isNil(env[envVar]));
|
package/lib/git.js
CHANGED
|
@@ -198,18 +198,32 @@ export async function isGitRepo(execaOptions) {
|
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
/**
|
|
201
|
-
* Verify the write access authorization to remote repository with push dry-run.
|
|
201
|
+
* Verify the write access authorization to remote repository with tags push dry-run.
|
|
202
202
|
*
|
|
203
203
|
* @param {String} repositoryUrl The remote repository URL.
|
|
204
|
-
* @param {String} branch The repository branch for which to verify write access.
|
|
205
204
|
* @param {Object} [execaOpts] Options to pass to `execa`.
|
|
206
205
|
*
|
|
207
206
|
* @throws {Error} if not authorized to push.
|
|
208
207
|
*/
|
|
209
|
-
export async function verifyAuth(repositoryUrl,
|
|
208
|
+
export async function verifyAuth(repositoryUrl, execaOptions) {
|
|
210
209
|
try {
|
|
211
|
-
await execa("git", ["push", "--dry-run", "--no-verify", "--", repositoryUrl
|
|
210
|
+
await execa("git", ["push", "--dry-run", "--no-verify", "--", repositoryUrl], execaOptions);
|
|
211
|
+
|
|
212
|
+
const tags = (await execa("git", ["tag", "--list"], execaOptions)).stdout
|
|
213
|
+
.split("\n")
|
|
214
|
+
.map((tag) => tag.trim())
|
|
215
|
+
.filter(Boolean);
|
|
216
|
+
|
|
217
|
+
if (tags.length > 0) {
|
|
218
|
+
await execa("git", ["push", "--dry-run", "--no-verify", "--tags", "--", repositoryUrl], execaOptions);
|
|
219
|
+
}
|
|
212
220
|
} catch (error) {
|
|
221
|
+
const message = `${error.stderr ?? ""}\n${error.message ?? ""}`;
|
|
222
|
+
|
|
223
|
+
if (/tip of your current branch is behind|rejected|non-fast-forward/i.test(message)) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
|
|
213
227
|
debug(error);
|
|
214
228
|
throw error;
|
|
215
229
|
}
|
|
@@ -291,15 +305,31 @@ export async function verifyBranchName(branch, execaOptions) {
|
|
|
291
305
|
* @param {String} branch The repository branch for which to verify status.
|
|
292
306
|
* @param {Object} [execaOpts] Options to pass to `execa`.
|
|
293
307
|
*
|
|
294
|
-
* @return {Boolean} `true`
|
|
308
|
+
* @return {Boolean} `true` only if the local branch is ahead of the remote branch, falsy otherwise.
|
|
295
309
|
*/
|
|
296
310
|
export async function isBranchUpToDate(repositoryUrl, branch, execaOptions) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
);
|
|
311
|
+
const localHead = await getGitHead(execaOptions);
|
|
312
|
+
const { stdout } = await execa("git", ["ls-remote", "--heads", "--", repositoryUrl, branch], execaOptions);
|
|
313
|
+
const remoteHead = stdout.match(/^(?<ref>\w+)/)?.[0];
|
|
314
|
+
|
|
315
|
+
if (!remoteHead) return false;
|
|
316
|
+
if (localHead === remoteHead) return true;
|
|
317
|
+
|
|
318
|
+
try {
|
|
319
|
+
const { exitCode } = await execa("git", ["merge-base", "--is-ancestor", "--", remoteHead, localHead], {
|
|
320
|
+
...execaOptions,
|
|
321
|
+
reject: false,
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Exit code 0 means remote is BEHIND local (local is AHEAD) - return true
|
|
326
|
+
* Any other exit code means local is either BEHIND or DIVERGED of remote - return false
|
|
327
|
+
*/
|
|
328
|
+
return exitCode === 0;
|
|
329
|
+
} catch (error) {
|
|
330
|
+
debug(error);
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
303
333
|
}
|
|
304
334
|
|
|
305
335
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "semantic-release",
|
|
3
3
|
"description": "Automated semver compliant package publishing",
|
|
4
|
-
"version": "26.0.0-beta.
|
|
4
|
+
"version": "26.0.0-beta.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Stephan Bönnemann <stephan@boennemann.me> (http://boennemann.me)",
|
|
7
7
|
"ava": {
|