semantic-release 23.0.0-beta.4 → 23.0.0-beta.5

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.
Files changed (3) hide show
  1. package/index.js +7 -4
  2. package/lib/git.js +39 -10
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -123,12 +123,15 @@ async function run(context, plugins) {
123
123
  if (options.dryRun) {
124
124
  logger.warn(`Skip ${nextRelease.gitTag} tag creation in dry-run mode`);
125
125
  } else {
126
- await addNote({ channels: [...currentRelease.channels, nextRelease.channel] }, nextRelease.gitHead, {
126
+ await addNote({ channels: [...currentRelease.channels, nextRelease.channel] }, nextRelease.gitTag, {
127
127
  cwd,
128
128
  env,
129
129
  });
130
130
  await push(options.repositoryUrl, { cwd, env });
131
- await pushNotes(options.repositoryUrl, { cwd, env });
131
+ await pushNotes(options.repositoryUrl, nextRelease.gitTag, {
132
+ cwd,
133
+ env,
134
+ });
132
135
  logger.success(
133
136
  `Add ${nextRelease.channel ? `channel ${nextRelease.channel}` : "default channel"} to tag ${
134
137
  nextRelease.gitTag
@@ -203,9 +206,9 @@ async function run(context, plugins) {
203
206
  } else {
204
207
  // Create the tag before calling the publish plugins as some require the tag to exists
205
208
  await tag(nextRelease.gitTag, nextRelease.gitHead, { cwd, env });
206
- await addNote({ channels: [nextRelease.channel] }, nextRelease.gitHead, { cwd, env });
209
+ await addNote({ channels: [nextRelease.channel] }, nextRelease.gitTag, { cwd, env });
207
210
  await push(options.repositoryUrl, { cwd, env });
208
- await pushNotes(options.repositoryUrl, { cwd, env });
211
+ await pushNotes(options.repositoryUrl, nextRelease.gitTag, { cwd, env });
209
212
  logger.success(`Created tag ${nextRelease.gitTag}`);
210
213
  }
211
214
 
package/lib/git.js CHANGED
@@ -2,6 +2,7 @@ import gitLogParser from "git-log-parser";
2
2
  import getStream from "get-stream";
3
3
  import { execa } from "execa";
4
4
  import debugGit from "debug";
5
+ import { merge } from "lodash-es";
5
6
  import { GIT_NOTE_REF } from "./definitions/constants.js";
6
7
 
7
8
  const debug = debugGit("semantic-release:git");
@@ -141,13 +142,9 @@ export async function fetch(repositoryUrl, branch, ciBranch, execaOptions) {
141
142
  */
142
143
  export async function fetchNotes(repositoryUrl, execaOptions) {
143
144
  try {
144
- await execa(
145
- "git",
146
- ["fetch", "--unshallow", repositoryUrl, `+refs/notes/${GIT_NOTE_REF}:refs/notes/${GIT_NOTE_REF}`],
147
- execaOptions
148
- );
145
+ await execa("git", ["fetch", "--unshallow", repositoryUrl, `+refs/notes/*:refs/notes/*`], execaOptions);
149
146
  } catch {
150
- await execa("git", ["fetch", repositoryUrl, `+refs/notes/${GIT_NOTE_REF}:refs/notes/${GIT_NOTE_REF}`], {
147
+ await execa("git", ["fetch", repositoryUrl, `+refs/notes/*:refs/notes/*`], {
151
148
  ...execaOptions,
152
149
  reject: false,
153
150
  });
@@ -246,8 +243,8 @@ export async function push(repositoryUrl, execaOptions) {
246
243
  *
247
244
  * @throws {Error} if the push failed.
248
245
  */
249
- export async function pushNotes(repositoryUrl, execaOptions) {
250
- await execa("git", ["push", repositoryUrl, `refs/notes/${GIT_NOTE_REF}`], execaOptions);
246
+ export async function pushNotes(repositoryUrl, ref, execaOptions) {
247
+ await execa("git", ["push", repositoryUrl, `refs/notes/${GIT_NOTE_REF}-${ref}`], execaOptions);
251
248
  }
252
249
 
253
250
  /**
@@ -307,8 +304,26 @@ export async function isBranchUpToDate(repositoryUrl, branch, execaOptions) {
307
304
  * @return {Object} the parsed JSON note if there is one, an empty object otherwise.
308
305
  */
309
306
  export async function getNote(ref, execaOptions) {
307
+ const handleError = (error) => {
308
+ if (error.exitCode === 1) {
309
+ return { stdout: "{}" };
310
+ }
311
+
312
+ debug(error);
313
+ throw error;
314
+ };
315
+
310
316
  try {
311
- return JSON.parse((await execa("git", ["notes", "--ref", GIT_NOTE_REF, "show", ref], execaOptions)).stdout);
317
+ return merge(
318
+ JSON.parse(
319
+ // Used for retro-compatibility
320
+ (await execa("git", ["notes", "--ref", GIT_NOTE_REF, "show", ref], execaOptions).catch(handleError)).stdout
321
+ ),
322
+ JSON.parse(
323
+ (await execa("git", ["notes", "--ref", `${GIT_NOTE_REF}-${ref}`, "show", ref], execaOptions).catch(handleError))
324
+ .stdout
325
+ )
326
+ );
312
327
  } catch (error) {
313
328
  if (error.exitCode === 1) {
314
329
  return {};
@@ -327,5 +342,19 @@ export async function getNote(ref, execaOptions) {
327
342
  * @param {Object} [execaOpts] Options to pass to `execa`.
328
343
  */
329
344
  export async function addNote(note, ref, execaOptions) {
330
- await execa("git", ["notes", "--ref", GIT_NOTE_REF, "add", "-f", "-m", JSON.stringify(note), ref], execaOptions);
345
+ await execa(
346
+ "git",
347
+ ["notes", "--ref", `${GIT_NOTE_REF}-${ref}`, "add", "-f", "-m", JSON.stringify(note), ref],
348
+ execaOptions
349
+ );
350
+ }
351
+
352
+ /**
353
+ * Get the reference of a tag
354
+ *
355
+ * @param {String} tag The tag name to get the reference of.
356
+ * @param {Object} [execaOpts] Options to pass to `execa`.
357
+ **/
358
+ export async function getTagRef(tag, execaOptions) {
359
+ return (await execa("git", ["show-ref", tag, "--hash"], execaOptions)).stdout;
331
360
  }
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": "23.0.0-beta.4",
4
+ "version": "23.0.0-beta.5",
5
5
  "type": "module",
6
6
  "author": "Stephan Bönnemann <stephan@boennemann.me> (http://boennemann.me)",
7
7
  "ava": {