Skip to content

Commit c2135f1

Browse files
committed
Merge branch 'master' into 481/esm
2 parents e100d3c + 3c42e02 commit c2135f1

28 files changed

+4676
-12862
lines changed

.github/workflows/release.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,23 @@ name: Release
66
- next
77
- beta
88
- "*.x"
9+
permissions:
10+
contents: read # for checkout
911
jobs:
1012
release:
13+
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
17+
id-token: write # to enable use of OIDC for npm provenance
1118
name: release
1219
runs-on: ubuntu-latest
1320
steps:
14-
- uses: actions/checkout@v2
15-
- uses: actions/setup-node@v2
21+
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3
22+
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
1623
with:
1724
cache: npm
18-
node-version: 16
25+
node-version: lts/*
1926
- run: npm ci
2027
- run: npx semantic-release
2128
env:

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ jobs:
1919
- ubuntu-latest
2020
runs-on: "${{ matrix.os }}"
2121
steps:
22-
- uses: actions/checkout@v2
22+
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3
2323
- name: "Use Node.js ${{ matrix.node-version }}"
24-
uses: actions/setup-node@v2
24+
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
2525
with:
2626
node-version: "${{ matrix.node-version }}"
2727
cache: npm
@@ -31,8 +31,8 @@ jobs:
3131
runs-on: ubuntu-latest
3232
needs: test_matrix
3333
steps:
34-
- uses: actions/checkout@v2
35-
- uses: actions/setup-node@v2
34+
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3
35+
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
3636
with:
3737
node-version: 16
3838
cache: npm

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ When creating the token, the **minimum required scopes** are:
6363
_Note on GitHub Actions:_ You can use the default token which is provided in the secret _GITHUB_TOKEN_. However releases done with this token will NOT trigger release events to start other workflows.
6464
If you have actions that trigger on newly created releases, please use a generated token for that and store it in your repository's secrets (any other name than GITHUB_TOKEN is fine).
6565

66+
When using the _GITHUB_TOKEN_, the **minimum required permissions** are:
67+
68+
- `contents: write` to be able to publish a GitHub release
69+
- `issues: write` to be able to comment on released issues
70+
- `pull-requests: write` to be able to comment on released pull requests
71+
6672
### Environment variables
6773

6874
| Variable | Description |
@@ -86,6 +92,7 @@ If you have actions that trigger on newly created releases, please use a generat
8692
| `assignees` | The [assignees](https://help.github.com/articles/assigning-issues-and-pull-requests-to-other-github-users) to add to the issue created when a release fails. | - |
8793
| `releasedLabels` | The [labels](https://help.github.com/articles/about-labels) to add to each issue and pull request resolved by the release. Set to `false` to not add any label. See [releasedLabels](#releasedlabels). | `['released<%= nextRelease.channel ? \` on @\${nextRelease.channel}\` : "" %>']- |
8894
| `addReleases` | Will add release links to the GitHub Release. Can be `false`, `"bottom"` or `"top"`. See [addReleases](#addReleases). | `false` |
95+
| `draftRelease` | A boolean indicating if a GitHub Draft Release should be created instead of publishing an actual GitHub Release. | `false` |
8996

9097
#### proxy
9198

lib/add-channel.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default async function addChannel(pluginConfig, context) {
2020
context
2121
);
2222
const { owner, repo } = parseGithubUrl(repositoryUrl);
23-
const github = getClient({
23+
const octokit = getClient({
2424
githubToken,
2525
githubUrl,
2626
githubApiPathPrefix,
@@ -41,14 +41,21 @@ export default async function addChannel(pluginConfig, context) {
4141
try {
4242
({
4343
data: { id: releaseId },
44-
} = await github.repos.getReleaseByTag({ owner, repo, tag: gitTag }));
44+
} = await octokit.request("GET /repos/{owner}/{repo}/releases/tags/{tag}", {
45+
owner,
46+
repo,
47+
tag: gitTag,
48+
}));
4549
} catch (error) {
4650
if (error.status === 404) {
4751
logger.log("There is no release for tag %s, creating a new one", gitTag);
4852

4953
const {
5054
data: { html_url: url },
51-
} = await github.repos.createRelease({ ...release, body: notes });
55+
} = await octokit.request("POST /repos/{owner}/{repo}/releases", {
56+
...release,
57+
body: notes,
58+
});
5259

5360
logger.log("Published GitHub release: %s", url);
5461
return { url, name: RELEASE_NAME };
@@ -61,7 +68,10 @@ export default async function addChannel(pluginConfig, context) {
6168

6269
const {
6370
data: { html_url: url },
64-
} = await github.repos.updateRelease({ ...release, release_id: releaseId });
71+
} = await octokit.request(
72+
"PATCH /repos/{owner}/{repo}/releases/{release_id}",
73+
{ ...release, release_id: releaseId }
74+
);
6575

6676
logger.log("Updated GitHub release: %s", url);
6777

lib/definitions/errors.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,19 @@ Your configuration for the \`addReleases\` option is \`${stringify(
117117
};
118118
}
119119

120+
export function EINVALIDDRAFTRELEASE({ draftRelease }) {
121+
return {
122+
message: "Invalid `draftRelease` option.",
123+
details: `The [draftRelease option](${linkify(
124+
"README.md#options"
125+
)}) if defined, must be a \`Boolean\`.
126+
127+
Your configuration for the \`draftRelease\` option is \`${stringify(
128+
draftRelease
129+
)}\`.`,
130+
};
131+
}
132+
120133
export function EINVALIDGITHUBURL() {
121134
return {
122135
message: "The git repository URL is not a valid GitHub URL.",

lib/definitions/rate-limit.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

lib/definitions/retry.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Default exponential backoff configuration for retries.
3+
*/
4+
export const RETRY_CONF = {
5+
// By default, Octokit does not retry on 404s.
6+
// But we want to retry on 404s to account for replication lag.
7+
doNotRetry: [400, 401, 403, 422],
8+
};

lib/definitions/throttle.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* Default configuration for throttle.
3+
* @see https://github.com/octokit/plugin-throttling.js#options
4+
*/
5+
export const THROTTLE_CONF = {};

lib/fail.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,33 @@ export default async function fail(pluginConfig, context) {
3131
if (failComment === false || failTitle === false) {
3232
logger.log("Skip issue creation.");
3333
} else {
34-
const github = getClient({
34+
const octokit = getClient({
3535
githubToken,
3636
githubUrl,
3737
githubApiPathPrefix,
3838
proxy,
3939
});
4040
// In case the repo changed name, get the new `repo`/`owner` as the search API will not follow redirects
41-
const [owner, repo] = (
42-
await github.repos.get(parseGithubUrl(repositoryUrl))
43-
).data.full_name.split("/");
41+
const { data: repoData } = await octokit.request(
42+
"GET /repos/{owner}/{repo}",
43+
parseGithubUrl(repositoryUrl)
44+
);
45+
const [owner, repo] = repoData.full_name.split("/");
4446
const body = failComment
4547
? template(failComment)({ branch, errors })
4648
: getFailComment(branch, errors);
47-
const [srIssue] = await findSRIssues(github, failTitle, owner, repo);
49+
const [srIssue] = await findSRIssues(octokit, failTitle, owner, repo);
4850

4951
if (srIssue) {
5052
logger.log("Found existing semantic-release issue #%d.", srIssue.number);
5153
const comment = { owner, repo, issue_number: srIssue.number, body };
5254
debug("create comment: %O", comment);
5355
const {
5456
data: { html_url: url },
55-
} = await github.issues.createComment(comment);
57+
} = await octokit.request(
58+
"POST /repos/{owner}/{repo}/issues/{issue_number}/comments",
59+
comment
60+
);
5661
logger.log("Added comment to issue #%d: %s.", srIssue.number, url);
5762
} else {
5863
const newIssue = {
@@ -66,7 +71,7 @@ export default async function fail(pluginConfig, context) {
6671
debug("create issue: %O", newIssue);
6772
const {
6873
data: { html_url: url, number },
69-
} = await github.issues.create(newIssue);
74+
} = await octokit.request("POST /repos/{owner}/{repo}/issues", newIssue);
7075
logger.log("Created issue #%d: %s.", number, url);
7176
}
7277
}

lib/find-sr-issues.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { ISSUE_ID } from "./definitions/constants.js";
22

3-
export default async function findIssues(github, title, owner, repo) {
3+
export default async (octokit, title, owner, repo) => {
44
const {
55
data: { items: issues },
6-
} = await github.search.issuesAndPullRequests({
6+
} = await octokit.request("GET /search/issues", {
77
q: `in:title+repo:${owner}/${repo}+type:issue+state:open+${title}`,
88
});
99

1010
return issues.filter((issue) => issue.body && issue.body.includes(ISSUE_ID));
11-
}
11+
};

0 commit comments

Comments
 (0)