Skip to content

Commit 8a91940

Browse files
ci: trusted publishers (#713)
1 parent b3f44b0 commit 8a91940

File tree

11 files changed

+1155
-26
lines changed

11 files changed

+1155
-26
lines changed

.changeset/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changesets
2+
3+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4+
with multi-package repos, or single-package repos to help you version and publish your code. You can
5+
find the full documentation for it [in our repository](https://github.com/changesets/changesets).
6+
7+
We have a quick list of common questions to get you started engaging with this project in
8+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md).

.changeset/changelog-generator.mjs

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import { getInfo, getInfoFromPullRequest } from "@changesets/get-github-info";
2+
3+
/** @typedef {import("@changesets/types").ChangelogFunctions} ChangelogFunctions */
4+
5+
/**
6+
* @returns {{ GITHUB_SERVER_URL: string }} value
7+
*/
8+
function readEnv() {
9+
const GITHUB_SERVER_URL =
10+
process.env.GITHUB_SERVER_URL || "https://github.com";
11+
return { GITHUB_SERVER_URL };
12+
}
13+
14+
/** @type {ChangelogFunctions} */
15+
const changelogFunctions = {
16+
getDependencyReleaseLine: async (
17+
changesets,
18+
dependenciesUpdated,
19+
options,
20+
) => {
21+
if (!options.repo) {
22+
throw new Error(
23+
'Please provide a repo to this changelog generator like this:\n"changelog": ["@changesets/changelog-github", { "repo": "org/repo" }]',
24+
);
25+
}
26+
if (dependenciesUpdated.length === 0) return "";
27+
28+
const changesetLink = `- Updated dependencies [${(
29+
await Promise.all(
30+
changesets.map(async (cs) => {
31+
if (cs.commit) {
32+
const { links } = await getInfo({
33+
repo: options.repo,
34+
commit: cs.commit,
35+
});
36+
return links.commit;
37+
}
38+
}),
39+
)
40+
)
41+
.filter(Boolean)
42+
.join(", ")}]:`;
43+
44+
const updatedDependenciesList = dependenciesUpdated.map(
45+
(dependency) => ` - ${dependency.name}@${dependency.newVersion}`,
46+
);
47+
48+
return [changesetLink, ...updatedDependenciesList].join("\n");
49+
},
50+
getReleaseLine: async (changeset, type, options) => {
51+
const { GITHUB_SERVER_URL } = readEnv();
52+
if (!options || !options.repo) {
53+
throw new Error(
54+
'Please provide a repo to this changelog generator like this:\n"changelog": ["@changesets/changelog-github", { "repo": "org/repo" }]',
55+
);
56+
}
57+
58+
/** @type {number | undefined} */
59+
let prFromSummary;
60+
/** @type {string | undefined} */
61+
let commitFromSummary;
62+
/** @type {string[]} */
63+
const usersFromSummary = [];
64+
65+
const replacedChangelog = changeset.summary
66+
.replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/im, (_, pr) => {
67+
const num = Number(pr);
68+
if (!Number.isNaN(num)) prFromSummary = num;
69+
return "";
70+
})
71+
.replace(/^\s*commit:\s*([^\s]+)/im, (_, commit) => {
72+
commitFromSummary = commit;
73+
return "";
74+
})
75+
.replaceAll(/^\s*(?:author|user):\s*@?([^\s]+)/gim, (_, user) => {
76+
usersFromSummary.push(user);
77+
return "";
78+
})
79+
.trim();
80+
81+
const [firstLine, ...futureLines] = replacedChangelog
82+
.split("\n")
83+
.map((l) => l.trimEnd());
84+
85+
const links = await (async () => {
86+
if (prFromSummary !== undefined) {
87+
let { links } = await getInfoFromPullRequest({
88+
repo: options.repo,
89+
pull: prFromSummary,
90+
});
91+
if (commitFromSummary) {
92+
const shortCommitId = commitFromSummary.slice(0, 7);
93+
links = {
94+
...links,
95+
commit: `[\`${shortCommitId}\`](${GITHUB_SERVER_URL}/${options.repo}/commit/${commitFromSummary})`,
96+
};
97+
}
98+
return links;
99+
}
100+
const commitToFetchFrom = commitFromSummary || changeset.commit;
101+
if (commitToFetchFrom) {
102+
const { links } = await getInfo({
103+
repo: options.repo,
104+
commit: commitToFetchFrom,
105+
});
106+
return links;
107+
}
108+
return {
109+
commit: null,
110+
pull: null,
111+
user: null,
112+
};
113+
})();
114+
115+
const users = usersFromSummary.length
116+
? usersFromSummary
117+
.map(
118+
(userFromSummary) =>
119+
`[@${userFromSummary}](${GITHUB_SERVER_URL}/${userFromSummary})`,
120+
)
121+
.join(", ")
122+
: links.user;
123+
124+
let suffix = "";
125+
if (links.pull || links.commit || users) {
126+
suffix = `(${users ? `by ${users} ` : ""}in ${links.pull || links.commit})`;
127+
}
128+
129+
return `\n\n- ${firstLine} ${suffix}\n${futureLines.map((l) => ` ${l}`).join("\n")}`;
130+
},
131+
};
132+
133+
export default changelogFunctions;

.changeset/config.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/config@3.1.2/schema.json",
3+
"changelog": [
4+
"./changelog-generator.mjs",
5+
{ "repo": "webpack/webpack-bundle-analyzer" }
6+
],
7+
"fixed": [],
8+
"linked": [],
9+
"access": "public",
10+
"baseBranch": "main",
11+
"updateInternalDependencies": "patch",
12+
"ignore": []
13+
}

.changeset/fast-singers-rescue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack-bundle-analyzer": patch
3+
---
4+
5+
Fix a race condition in `writeStats` that could lead to incorrect content in `stats.json`.

.changeset/long-comics-sin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack-bundle-analyzer": patch
3+
---
4+
5+
Apply `prettier` and update dependencies.

.changeset/many-dolls-beg.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack-bundle-analyzer": minor
3+
---
4+
5+
Use new ECMA features in code.

.changeset/twenty-eggs-change.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack-bundle-analyzer": minor
3+
---
4+
5+
Added `propTypes` to client components.

.github/workflows/release.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
concurrency: ${{ github.workflow }}-${{ github.ref }}
9+
10+
permissions:
11+
id-token: write # Required for OIDC
12+
contents: write
13+
pull-requests: write
14+
15+
jobs:
16+
release:
17+
if: github.repository == 'webpack/webpack-bundle-analyzer'
18+
name: Release
19+
runs-on: ubuntu-latest
20+
outputs:
21+
published: ${{ steps.changesets.outputs.published }}
22+
steps:
23+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
24+
25+
- name: Use Node.js
26+
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
27+
with:
28+
node-version: lts/*
29+
cache: npm
30+
31+
- run: npm ci
32+
33+
- name: Create Release Pull Request or Publish to npm
34+
id: changesets
35+
uses: changesets/action@6a0a831ff30acef54f2c6aa1cbbc1096b066edaf # v1.7.0
36+
with:
37+
version: npm run version
38+
publish: npm run release
39+
commit: "chore(release): new release"
40+
title: "chore(release): new release"
41+
env:
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
NPM_TOKEN: "" # https://github.com/changesets/changesets/issues/1152#issuecomment-3190884868

CHANGELOG.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
# Changelog
22

3-
> **Tags:**
4-
> - [Breaking Change]
5-
> - [New Feature]
6-
> - [Improvement]
7-
> - [Bug Fix]
8-
> - [Internal]
9-
> - [Documentation]
10-
11-
_Note: Gaps between patch versions are faulty, broken or test releases._
12-
13-
## UNRELEASED
14-
15-
* **Bug Fix**
16-
* Fix a race condition in `writeStats` that could lead to incorrect content in `stats.json` ([#711](https://github.com/webpack/webpack-bundle-analyzer/pull/711) by [@colinaaa](https://github.com/colinaaa))
17-
183
## 5.2.0
194

205
* **New Feature**

0 commit comments

Comments
 (0)