8000 Merge remote-tracking branch 'upstream/master' · semantic-release/github@5e040f4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5e040f4

Browse files
Merge remote-tracking branch 'upstream/master'
2 parents 5221614 + c258b0c commit 5e040f4

21 files changed

+6210
-2326
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ jobs:
1818
name: release
1919
runs-on: ubuntu-latest
2020
steps:
21-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
22-
- uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
21+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
22+
- uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
2323
with:
2424
cache: npm
2525
node-version: lts/*

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ jobs:
2626
- ubuntu-latest
2727
runs-on: "${{ matrix.os }}"
2828
steps:
29-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
29+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3030
- name: "Use Node.js ${{ matrix.node-version }}"
31-
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
31+
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
3232
with:
3333
node-version: "${{ matrix.node-version }}"
3434
cache: npm
@@ -42,11 +42,11 @@ jobs:
4242
timeout-minutes: 5
4343

4444
steps:
45-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
45+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
4646
- run: git config --global user.name github-actions
4747
- run: git config --global user.email github-actions@github.com
4848
- name: Use Node.js from .nvmrc
49-
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
49+
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
5050
with:
5151
node-version-file: .nvmrc
5252
cache: npm

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20
1+
22

README.md

Lines changed: 80 additions & 34 deletions
Large diffs are not rendered by default.

lib/definitions/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export const ISSUE_ID = "<!-- semantic-release:github -->";
22

33 A92E
export const RELEASE_NAME = "GitHub release";
4+
5+
export const RELEASE_FAIL_LABEL = "semantic-release";

lib/definitions/errors.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,19 @@ By default the \`repositoryUrl\` option is retrieved from the \`repository\` pro
139139
};
140140
}
141141

142+
export function EMISMATCHGITHUBURL({ repositoryUrl, clone_url }) {
143+
return {
144+
message: "The git repository URL mismatches the GitHub URL.",
145+
details: `The **semantic-release** \`repositoryUrl\` option must have the same repository name and owner as the GitHub repo.
146+
147+
Your configuration for the \`repositoryUrl\` option is \`${stringify(repositoryUrl)}\` and the \`clone_url\` of your GitHub repo is \`${stringify(clone_url)}\`.
148+
149+
By default the \`repositoryUrl\` option is retrieved from the \`repository\` property of your \`package.json\` or the [git origin url](https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes) of the repository cloned by your CI environment.
150+
151+
Note: If you have recently changed your GitHub repository name or owner, update the value in **semantic-release** \`repositoryUrl\` option and the \`repository\` property of your \`package.json\` respectively to match the new GitHub URL.`,
152+
};
153+
}
154+
142155
export function EINVALIDPROXY({ proxy }) {
143156
return {
144157
message: "Invalid `proxy` option.",

lib/fail.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { template } from "lodash-es";
22
import debugFactory from "debug";
33

44
import parseGithubUrl from "./parse-github-url.js";
5-
import { ISSUE_ID } from "./definitions/constants.js";
5+
import { ISSUE_ID, RELEASE_FAIL_LABEL } from "./definitions/constants.js";
66
import resolveConfig from "./resolve-config.js";
77
import { toOctokitOptions } from "./octokit.js";
88
import findSRIssues from "./find-sr-issues.js";
@@ -23,14 +23,20 @@ export default async function fail(pluginConfig, context, { Octokit }) {
2323
githubApiPathPrefix,
2424
githubApiUrl,
2525
proxy,
26-
failComment,
2726
failTitle,
27+
failComment,
28+
failCommentCondition,
2829
labels,
2930
assignees,
3031
} = resolveConfig(pluginConfig, context);
3132

3233
if (failComment === false || failTitle === false) {
3334
logger.log("Skip issue creation.");
35+
logger.warn(
36+
`DEPRECATION: 'false' for 'failComment' or 'failTitle' is deprecated and will be removed in a future major version. Use 'failCommentCondition' instead.`,
37+
);
38+
} else if (failCommentCondition === false) {
39+
logger.log("Skip issue creation.");
3440
} else {
3541
const octokit = new Octokit(
3642
toOctokitOptions({
@@ -50,7 +56,23 @@ export default async function fail(pluginConfig, context, { Octokit }) {
5056
const body = failComment
5157
? template(failComment)({ branch, errors })
5258
: getFailComment(branch, errors);
53-
const [srIssue] = await findSRIssues(octokit, failTitle, owner, repo);
59+
const [srIssue] = await findSRIssues(
60+
octokit,
61+
logger,
62+
failTitle,
63+
labels,
64+
owner,
65+
repo,
66+
);
67+
68+
const canCommentOnOrCreateIssue = failCommentCondition
69+
? template(failCommentCondition)({ ...context, issue: srIssue })
70+
: true;
71+
72+
if (!canCommentOnOrCreateIssue) {
73+
logger.log("Skip commenting on or creating an issue.");
74+
return;
75+
}
5476

5577
if (srIssue) {
5678
logger.log("Found existing semantic-release issue #%d.", srIssue.number);
@@ -69,7 +91,7 @@ export default async function fail(pluginConfig, context, { Octokit }) {
6991
repo,
7092
title: failTitle,
7193
body: `${body}\n\n${ISSUE_ID}`,
72-
labels: labels || [],
94+
labels: (labels || []).concat([RELEASE_FAIL_LABEL]),
7395
assignees,
7496
};
7597
debug("create issue: %O", newIssue);

lib/find-sr-issues.js

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,63 @@
1-
import { ISSUE_ID } from "./definitions/constants.js";
1+
import { uniqBy } from "lodash-es";
2+
import { ISSUE_ID, RELEASE_FAIL_LABEL } from "./definitions/constants.js";
3+
4+
export default async (octokit, logger, title, labels, owner, repo) => {
5+
let issues = [];
26

3-
export default async (octokit, title, owner, repo) => {
47
const {
5-
data: { items: issues },
6-
} = await octokit.request("GET /search/issues", {
7-
q: `in:title+repo:${owner}/${repo}+type:issue+state:open+${title}`,
8+
repository: {
9+
issues: { nodes: issueNodes },
10+
},
11+
} = await octokit.graphql(loadGetSRIssuesQuery, {
12+
owner,
13+
repo,
14+
filter: {
15+
labels: (labels || []).concat([RELEASE_FAIL_LABEL]),
16+
},
817
});
918

10-
return issues.filter((issue) => issue.body && issue.body.includes(ISSUE_ID));
19+
issues.push(...issueNodes);
20+
21+
/**
22+
* BACKWARD COMPATIBILITY: Fallback to the search API if the issue was not found in the GraphQL response.
23+
* This fallback will be removed in a future release
24+
*/
25+
if (issueNodes.length === 0) {
26+
try {
27+
const {
28+
data: { items: backwardIssues },
29+
} = await octokit.request("GET /search/issues", {
30+
q: `in:title+repo:${owner}/${repo}+type:issue+state:open+${title}`,
31+
});
32+
issues.push(...backwardIssues);
33+
} catch (error) {
34+
logger.log(
35+
"An error occured fetching issue via fallback (with GH SearchAPI)",
36+
);
37+
}
38+
}
39+
40+
const uniqueSRIssues = uniqBy(
41+
issues.filter((issue) => issue.body && issue.body.includes(ISSUE_ID)),
42+
"number",
43+
);
44+
45+
return uniqueSRIssues;
1146
};
47+
48+
/**
49+
* GraphQL Query to et the semantic-release issues for a repository.
50+
*/
51+
const loadGetSRIssuesQuery = `#graphql
52+
query getSRIssues($owner: String!, $repo: String!, $filter: IssueFilters) {
53+
repository(owner: $owner, name: $repo) {
54+
issues(first: 100, states: OPEN, filterBy: $filter) {
55+
nodes {
56+
number
57+
title
58+
body
59+
}
60+
}
61+
}
62+
}
63+
`;

lib/glob-assets.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export default async function globAssets({ cwd }, assets) {
3030
const globbed = await globby(glob, {
3131
cwd,
3232
expandDirectories: false, // TODO Temporary workaround for https://github.com/mrmlnc/fast-glob/issues/47
33-
gitignore: false,
3433
dot: true,
3534
onlyFiles: false,
3635
});

lib/resolve-config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ export default function resolveConfig(
88
proxy,
99
assets,
1010
successComment,
11+
successCommentCondition,
1112
failTitle,
1213
failComment,
14+
failCommentCondition,
1315
labels,
1416
assignees,
1517
releasedLabels,
@@ -30,10 +32,12 @@ export default function resolveConfig(
3032
proxy: isNil(proxy) ? env.http_proxy || env.HTTP_PROXY || false : proxy,
3133
assets: assets ? castArray(assets) : assets,
3234
successComment,
35+
successCommentCondition,
3336
failTitle: isNil(failTitle)
3437
? "The automated release is failing 🚨"
3538
: failTitle,
3639
failComment,
40+
failCommentCondition,
3741
labels: isNil(labels)
3842
? ["semantic-release"]
3943
: labels === false

0 commit comments

Comments
 (0)
0