Skip to content

Commit deb1b7f

Browse files
authored
Merge pull request #2741 from semantic-release/beta
upgraded to next major version of the npm plugin
2 parents f1d6e65 + 2d7f607 commit deb1b7f

38 files changed

+11927
-6818
lines changed

.git-blame-ignore-revs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# style: prettier (#2670)
2+
b06c9bbe4c6be121c5561b356d8c465c1cadffba

.github/workflows/release.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ name: Release
77
- beta
88
- "*.x"
99
permissions:
10-
contents: read # for checkout
10+
contents: read # for checkout
1111
jobs:
1212
release:
1313
permissions:
14-
contents: write # to be able to publish a GitHub release
15-
issues: write # to be able to comment on released issues
16-
pull-requests: write # to be able to comment on released pull requests
14+
contents: write # to be able to publish a GitHub release
15+
issues: write # to be able to comment on released issues
16+
pull-requests: write # to be able to comment on released pull requests
17+
id-token: write # to enable use of OIDC for npm provenance
1718
name: release
1819
runs-on: ubuntu-latest
1920
steps:

lib/branches/expand.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import {isString, mapValues, omit, remove, template} from 'lodash-es';
2-
import micromatch from 'micromatch';
3-
import {getBranches} from '../git.js';
1+
import { isString, mapValues, omit, remove, template } from "lodash-es";
2+
import micromatch from "micromatch";
3+
import { getBranches } from "../git.js";
44

5-
export default async (repositoryUrl, {cwd}, branches) => {
6-
const gitBranches = await getBranches(repositoryUrl, {cwd});
5+
export default async (repositoryUrl, { cwd }, branches) => {
6+
const gitBranches = await getBranches(repositoryUrl, { cwd });
77

88
return branches.reduce(
99
(branches, branch) => [
1010
...branches,
1111
...remove(gitBranches, (name) => micromatch(gitBranches, branch.name).includes(name)).map((name) => ({
1212
name,
13-
...mapValues(omit(branch, 'name'), (value) => (isString(value) ? template(value)({name}) : value)),
13+
...mapValues(omit(branch, "name"), (value) => (isString(value) ? template(value)({ name }) : value)),
1414
})),
1515
],
1616
[]
1717
);
18-
}
18+
};

lib/branches/get-tags.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
1-
import {escapeRegExp, template} from 'lodash-es';
2-
import semver from 'semver';
3-
import pReduce from 'p-reduce';
4-
import debugTags from 'debug';
5-
import {getNote, getTags} from '../../lib/git.js';
1+
import { escapeRegExp, template } from "lodash-es";
2+
import semver from "semver";
3+
import pReduce from "p-reduce";
4+
import debugTags from "debug";
5+
import { getNote, getTags } from "../../lib/git.js";
66

7-
const debug = debugTags('semantic-release:get-tags');
7+
const debug = debugTags("semantic-release:get-tags");
88

9-
10-
export default async ({cwd, env, options: {tagFormat}}, branches) => {
9+
export default async ({ cwd, env, options: { tagFormat } }, branches) => {
1110
// Generate a regex to parse tags formatted with `tagFormat`
1211
// by replacing the `version` variable in the template by `(.+)`.
1312
// The `tagFormat` is compiled with space as the `version` as it's an invalid tag character,
1413
// so it's guaranteed to no be present in the `tagFormat`.
15-
const tagRegexp = `^${escapeRegExp(template(tagFormat)({version: ' '})).replace(' ', '(.+)')}`;
14+
const tagRegexp = `^${escapeRegExp(template(tagFormat)({ version: " " })).replace(" ", "(.+)")}`;
1615

1716
return pReduce(
1817
branches,
1918
async (branches, branch) => {
2019
const branchTags = await pReduce(
21-
await getTags(branch.name, {cwd, env}),
20+
await getTags(branch.name, { cwd, env }),
2221
async (branchTags, tag) => {
2322
const [, version] = tag.match(tagRegexp) || [];
2423
return version && semver.valid(semver.clean(version))
25-
? [...branchTags, {gitTag: tag, version, channels: (await getNote(tag, {cwd, env})).channels || [null]}]
24+
? [...branchTags, { gitTag: tag, version, channels: (await getNote(tag, { cwd, env })).channels || [null] }]
2625
: branchTags;
2726
},
2827
[]
2928
);
3029

31-
debug('found tags for branch %s: %o', branch.name, branchTags);
32-
return [...branches, {...branch, tags: branchTags}];
30+
debug("found tags for branch %s: %o", branch.name, branchTags);
31+
return [...branches, { ...branch, tags: branchTags }];
3332
},
3433
[]
3534
);
36-
}
35+
};

lib/branches/index.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
1-
import {isRegExp, isString} from 'lodash-es';
2-
import AggregateError from 'aggregate-error';
3-
import pEachSeries from 'p-each-series';
4-
import * as DEFINITIONS from '../definitions/branches.js';
5-
import getError from '../get-error.js';
6-
import {fetch, fetchNotes, verifyBranchName} from '../git.js';
7-
import expand from './expand.js';
8-
import getTags from './get-tags.js';
9-
import * as normalize from './normalize.js';
1+
import { isRegExp, isString } from "lodash-es";
2+
import AggregateError from "aggregate-error";
3+
import pEachSeries from "p-each-series";
4+
import * as DEFINITIONS from "../definitions/branches.js";
5+
import getError from "../get-error.js";
6+
import { fetch, fetchNotes, verifyBranchName } from "../git.js";
7+
import expand from "./expand.js";
8+
import getTags from "./get-tags.js";
9+
import * as normalize from "./normalize.js";
1010

1111
export default async (repositoryUrl, ciBranch, context) => {
12-
const {cwd, env} = context;
12+
const { cwd, env } = context;
1313

1414
const remoteBranches = await expand(
1515
repositoryUrl,
1616
context,
17-
context.options.branches.map((branch) => (isString(branch) || isRegExp(branch) ? {name: branch} : branch))
17+
context.options.branches.map((branch) => (isString(branch) || isRegExp(branch) ? { name: branch } : branch))
1818
);
1919

20-
await pEachSeries(remoteBranches, async ({name}) => {
21-
await fetch(repositoryUrl, name, ciBranch, {cwd, env});
20+
await pEachSeries(remoteBranches, async ({ name }) => {
21+
await fetch(repositoryUrl, name, ciBranch, { cwd, env });
2222
});
2323

24-
await fetchNotes(repositoryUrl, {cwd, env});
24+
await fetchNotes(repositoryUrl, { cwd, env });
2525

2626
const branches = await getTags(context, remoteBranches);
2727

2828
const errors = [];
2929
const branchesByType = Object.entries(DEFINITIONS).reduce(
3030
// eslint-disable-next-line unicorn/no-fn-reference-in-iterator
31-
(branchesByType, [type, {filter}]) => ({[type]: branches.filter(filter), ...branchesByType}),
31+
(branchesByType, [type, { filter }]) => ({ [type]: branches.filter(filter), ...branchesByType }),
3232
{}
3333
);
3434

35-
const result = Object.entries(DEFINITIONS).reduce((result, [type, {branchesValidator, branchValidator}]) => {
35+
const result = Object.entries(DEFINITIONS).reduce((result, [type, { branchesValidator, branchValidator }]) => {
3636
branchesByType[type].forEach((branch) => {
3737
if (branchValidator && !branchValidator(branch)) {
38-
errors.push(getError(`E${type.toUpperCase()}BRANCH`, {branch}));
38+
errors.push(getError(`E${type.toUpperCase()}BRANCH`, { branch }));
3939
}
4040
});
4141

4242
const branchesOfType = normalize[type](branchesByType);
4343

4444
if (!branchesValidator(branchesOfType)) {
45-
errors.push(getError(`E${type.toUpperCase()}BRANCHES`, {branches: branchesOfType}));
45+
errors.push(getError(`E${type.toUpperCase()}BRANCHES`, { branches: branchesOfType }));
4646
}
4747

48-
return {...result, [type]: branchesOfType};
48+
return { ...result, [type]: branchesOfType };
4949
}, {});
5050

5151
const duplicates = [...branches]
@@ -54,12 +54,12 @@ export default async (repositoryUrl, ciBranch, context) => {
5454
.filter((_, idx, array) => array[idx] === array[idx + 1] && array[idx] !== array[idx - 1]);
5555

5656
if (duplicates.length > 0) {
57-
errors.push(getError('EDUPLICATEBRANCHES', {duplicates}));
57+
errors.push(getError("EDUPLICATEBRANCHES", { duplicates }));
5858
}
5959

6060
await pEachSeries(branches, async (branch) => {
6161
if (!(await verifyBranchName(branch.name))) {
62-
errors.push(getError('EINVALIDBRANCHNAME', branch));
62+
errors.push(getError("EINVALIDBRANCHNAME", branch));
6363
}
6464
});
6565

@@ -68,4 +68,4 @@ export default async (repositoryUrl, ciBranch, context) => {
6868
}
6969

7070
return [...result.maintenance, ...result.release, ...result.prerelease];
71-
}
71+
};

lib/branches/normalize.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
import {isNil, sortBy} from 'lodash-es';
2-
import semverDiff from 'semver-diff';
3-
import {FIRST_RELEASE, RELEASE_TYPE} from '../definitions/constants.js';
1+
import { isNil, sortBy } from "lodash-es";
2+
import semverDiff from "semver-diff";
3+
import { FIRST_RELEASE, RELEASE_TYPE } from "../definitions/constants.js";
44
import {
55
getFirstVersion,
66
getLatestVersion,
7-
getLowerBound, getRange,
7+
getLowerBound,
8+
getRange,
89
getUpperBound,
910
highest,
1011
isMajorRange,
1112
lowest,
12-
tagsToVersions
13-
} from '../utils.js';
13+
tagsToVersions,
14+
} from "../utils.js";
1415

15-
export function maintenance({maintenance, release}) {
16+
export function maintenance({ maintenance, release }) {
1617
return sortBy(
17-
maintenance.map(({name, range, channel, ...rest}) => ({
18+
maintenance.map(({ name, range, channel, ...rest }) => ({
1819
...rest,
1920
name,
2021
range: range || name,
2122
channel: isNil(channel) ? name : channel,
2223
})),
23-
'range'
24-
).map(({name, range, tags, ...rest}, idx, branches) => {
24+
"range"
25+
).map(({ name, range, tags, ...rest }, idx, branches) => {
2526
const versions = tagsToVersions(tags);
2627
// Find the lower bound based on Maintenance branches
2728
const maintenanceMin =
@@ -44,7 +45,7 @@ export function maintenance({maintenance, release}) {
4445
const diff = semverDiff(min, max);
4546
return {
4647
...rest,
47-
type: 'maintenance',
48+
type: "maintenance",
4849
name,
4950
tags,
5051
range: getRange(min, max),
@@ -54,15 +55,15 @@ export function maintenance({maintenance, release}) {
5455
});
5556
}
5657

57-
export function release({release}) {
58+
export function release({ release }) {
5859
if (release.length === 0) {
5960
return release;
6061
}
6162

6263
// The intial lastVersion is the last release from the base branch of `FIRST_RELEASE` (1.0.0)
6364
let lastVersion = getLatestVersion(tagsToVersions(release[0].tags)) || FIRST_RELEASE;
6465

65-
return release.map(({name, tags, channel, ...rest}, idx) => {
66+
return release.map(({ name, tags, channel, ...rest }, idx) => {
6667
const versions = tagsToVersions(tags);
6768
// The new lastVersion is the highest version between the current branch last release and the previous branch lastVersion
6869
lastVersion = highest(getLatestVersion(versions), lastVersion);
@@ -79,7 +80,7 @@ export function release({release}) {
7980
...rest,
8081
channel: idx === 0 ? channel : isNil(channel) ? name : channel,
8182
tags,
82-
type: 'release',
83+
type: "release",
8384
name,
8485
range: getRange(lastVersion, bound),
8586
accept: bound ? RELEASE_TYPE.slice(0, RELEASE_TYPE.indexOf(diff)) : RELEASE_TYPE,
@@ -88,13 +89,13 @@ export function release({release}) {
8889
});
8990
}
9091

91-
export function prerelease({prerelease}) {
92-
return prerelease.map(({name, prerelease, channel, tags, ...rest}) => {
92+
export function prerelease({ prerelease }) {
93+
return prerelease.map(({ name, prerelease, channel, tags, ...rest }) => {
9394
const preid = prerelease === true ? name : prerelease;
9495
return {
9596
...rest,
9697
channel: isNil(channel) ? name : channel,
97-
type: 'prerelease',
98+
type: "prerelease",
9899
name,
99100
prerelease: preid,
100101
tags,

lib/definitions/branches.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import {isNil, uniqBy} from 'lodash-es';
2-
import semver from 'semver';
3-
import {isMaintenanceRange} from '../utils.js';
1+
import { isNil, uniqBy } from "lodash-es";
2+
import semver from "semver";
3+
import { isMaintenanceRange } from "../utils.js";
44

55
export const maintenance = {
6-
filter: ({name, range}) => (!isNil(range) && range !== false) || isMaintenanceRange(name),
7-
branchValidator: ({range}) => (isNil(range) ? true : isMaintenanceRange(range)),
8-
branchesValidator: (branches) => uniqBy(branches, ({range}) => semver.validRange(range)).length === branches.length,
6+
filter: ({ name, range }) => (!isNil(range) && range !== false) || isMaintenanceRange(name),
7+
branchValidator: ({ range }) => (isNil(range) ? true : isMaintenanceRange(range)),
8+
branchesValidator: (branches) => uniqBy(branches, ({ range }) => semver.validRange(range)).length === branches.length,
99
};
1010

1111
export const prerelease = {
12-
filter: ({prerelease}) => !isNil(prerelease) && prerelease !== false,
13-
branchValidator: ({name, prerelease}) =>
12+
filter: ({ prerelease }) => !isNil(prerelease) && prerelease !== false,
13+
branchValidator: ({ name, prerelease }) =>
1414
Boolean(prerelease) && Boolean(semver.valid(`1.0.0-${prerelease === true ? name : prerelease}.1`)),
15-
branchesValidator: (branches) => uniqBy(branches, 'prerelease').length === branches.length,
15+
branchesValidator: (branches) => uniqBy(branches, "prerelease").length === branches.length,
1616
};
1717

1818
export const release = {

lib/definitions/constants.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
export const RELEASE_TYPE = ['patch', 'minor', 'major'];
1+
export const RELEASE_TYPE = ["patch", "minor", "major"];
22

3-
export const FIRST_RELEASE = '1.0.0';
3+
export const FIRST_RELEASE = "1.0.0";
44

5-
export const FIRSTPRERELEASE = '1';
5+
export const FIRSTPRERELEASE = "1";
66

7-
export const COMMIT_NAME = 'semantic-release-bot';
7+
export const COMMIT_NAME = "semantic-release-bot";
88

9-
export const COMMIT_EMAIL = '[email protected]';
9+
export const COMMIT_EMAIL = "[email protected]";
1010

11-
export const RELEASE_NOTES_SEPARATOR = '\n\n';
11+
export const RELEASE_NOTES_SEPARATOR = "\n\n";
1212

13-
export const SECRET_REPLACEMENT = '[secure]';
13+
export const SECRET_REPLACEMENT = "[secure]";
1414

1515
export const SECRET_MIN_SIZE = 5;
1616

17-
export const GIT_NOTE_REF = 'semantic-release';
17+
export const GIT_NOTE_REF = "semantic-release";

0 commit comments

Comments
 (0)