Skip to content

Commit b3dfa25

Browse files
alex-pagesam-b-roseavelineisaacroldan
committed
v0.0.13
- Add `global_install` to show global npm installation instructions on the generated GitHub comment. - Add `github_comment_included_packages` to allow including just some packages on the generated GitHub comment. - Rename `custom_message` to `custom_message_prefix` - Add `custom_message_suffix` Co-Authored-By: Sam Rose <11774595+sam-b-rose@users.noreply.github.com> Co-Authored-By: aveline <aveline@users.noreply.github.com> Co-Authored-By: Isaac Roldán <isaac.roldan@gmail.com>
1 parent ad1361e commit b3dfa25

6 files changed

Lines changed: 107 additions & 28 deletions

File tree

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,45 @@ The comment to write to trigger the creation of a snapshot.
9393

9494
Push the changes to a branch instead of publishing to the NPM registry.
9595

96-
**`custom_message` (optional)**
96+
**`custom_message_prefix` (optional)**
9797

9898
Custom message to added to the beginning of the release GitHub comment.
99+
By default a generic message is shown: "Test the snapshots by updating your package.json with the newly published versions:"
100+
101+
**`custom_message_suffix` (optional)**
102+
103+
Custom message to added to the end of the release GitHub comment.
104+
105+
**`global_install` (optional)**
106+
107+
If true, the generated GitHub comment will show the command to install your packages globally.
108+
Otherwise, the default behaviour is to show a json example to update your local dependencies.
109+
110+
**`github_comment_included_packages` (optional)**
111+
112+
In workspaces where many packages are deployed, use this filter if you only want to include some of them in the release GitHub comment.
113+
(To specify multiple packages, separate using commas)
114+
115+
## Contributing
116+
117+
To contribute a change, bug fix or feature to snapit:
118+
119+
1. Make a new branch `my-branch`
120+
1. Make the changes you need
121+
1. Run `pnpm build`
122+
1. Push your changes to the branch
123+
1. In your repositories `main` branch point the `.github/snapit.yml` file to the `shopify/snapit` branch `uses: Shopify/snapit@my-branch`
124+
1. Create a pull request with changeset and write `/snapit` as a comment in the pull request
99125

100126
## Changelog
101127

128+
**`v0.0.13`**
129+
130+
- Add `global_install` to show global npm installation instructions on the generated GitHub comment.
131+
- Add `github_comment_included_packages` to allow including just some packages on the generated GitHub comment.
132+
- Rename `custom_message` to `custom_message_prefix`
133+
- Add `custom_message_suffix`
134+
102135
**`v0.0.12`**
103136

104137
- Fix typo in snapshot comment message

action.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ inputs:
99
default: '/snapit'
1010
branch:
1111
description: Push the changes to a branch instead of publishing to the NPM registry.
12-
custom_message:
13-
description: Custom message to added to the beginning of the release GitHub comment.
12+
custom_message_prefix:
13+
description: Custom message added to the beginning of the snapit GitHub comment. By default a generic message is shown.
14+
custom_message_suffix:
15+
description: Custom message added to the end of the snapit GitHub comment.
16+
global_install:
17+
description: If true, the GitHub comment will show instructions to install a global npm package instead of the normal JSON dependencies.
18+
github_comment_included_packages:
19+
description: Which packages to include in the final output. All pacakges are still published, but only those in this list are shown in the final message. If empty, all packages are included.
20+
1421
runs:
1522
using: node20
1623
main: dist/index.js

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.ts

Lines changed: 60 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,21 @@ try {
3131
};
3232

3333
const buildScript = core.getInput('build_script');
34+
const isGlobal = core.getInput('global_install') === 'true';
35+
const githubCommentIncludedPackages = core.getInput(
36+
'github_comment_included_packages',
37+
);
3438
const branch = core.getInput('branch');
39+
const customMessagePrefix = core.getInput('custom_message_prefix');
40+
const customMessageSuffix = core.getInput('custom_message_suffix');
41+
const commentCommands = core.getInput('comment_command');
3542
const octokit = github.getOctokit(process.env.GITHUB_TOKEN);
3643
const isYarn = existsSync('yarn.lock');
3744
const isPnpm = existsSync('pnpm-lock.yaml');
3845
const changesetBinary = path.join('node_modules/.bin/changeset');
3946
const versionPrefix = 'snapshot';
4047

41-
const commentCommands = core.getInput('comment_command').split(',');
42-
if (commentCommands.indexOf(payload.comment.body) !== -1) {
48+
if (commentCommands.split(',').indexOf(payload.comment.body) !== -1) {
4349
await octokit.rest.reactions.createForIssueComment({
4450
...ownerRepo,
4551
comment_id: payload.comment.id,
@@ -113,18 +119,33 @@ try {
113119
await exec(changesetBinary, ['version', '--snapshot', versionPrefix]);
114120

115121
const {packages} = await getPackages(process.cwd());
116-
const snapshots = [];
122+
123+
interface Snapshot {
124+
package: string;
125+
version: string;
126+
timestamp: string;
127+
fullString: string;
128+
}
129+
130+
const snapshots: Snapshot[] = [];
117131
packages.forEach(({packageJson}) => {
118132
const {name, version, private: isPrivate} = packageJson;
119-
if (name && version && !isPrivate && version.includes(versionPrefix))
120-
snapshots.push(`${name}@${version}`);
133+
if (name && version && !isPrivate && version.includes(versionPrefix)) {
134+
const timestamp = version.split('-').at(-1);
135+
snapshots.push({
136+
package: name,
137+
version,
138+
timestamp,
139+
fullString: `${name}@${version}`,
140+
});
141+
}
121142
});
122143

123144
if (!snapshots.length) {
124145
throw new Error('Changeset publish did not create new tags.');
125146
}
126147

127-
const snapshotTimestamp = snapshots[0].split('-').at(-1);
148+
const snapshotTimestamp = snapshots[0].timestamp;
128149

129150
// Run after `changeset version` so build scripts can use updated versions
130151
if (buildScript) {
@@ -183,31 +204,49 @@ try {
183204
]);
184205
}
185206

186-
const multiple = snapshots.length > 1;
207+
const filteredSnapshots = githubCommentIncludedPackages
208+
? snapshots.filter((snapshot: Snapshot) =>
209+
githubCommentIncludedPackages
210+
.split(',')
211+
.some((filter) => snapshot.package === filter),
212+
)
213+
: snapshots;
214+
const multiple = filteredSnapshots.length > 1;
187215

188216
const introMessage = branch
189217
? `Your snapshot${multiple ? 's are' : ' is'} being published.**\n\n`
190218
: `Your snapshot${multiple ? 's have' : ' has'} been published to npm.**\n\n`;
191219

192-
const customMessage = core.getInput('custom_message');
220+
const globalInstallMessage = isYarn
221+
? 'yarn global add'
222+
: isPnpm
223+
? 'pnpm i -g'
224+
: 'npm i -g';
193225

194-
const body =
195-
`🫰✨ **Thanks @${payload.comment.user.login}! ${introMessage}` +
196-
`${customMessage ? `${customMessage} ` : ''}` +
197-
`Test the snapshot${
198-
multiple ? 's' : ''
199-
} by updating your \`package.json\` ` +
200-
`with the newly published version${multiple ? 's' : ''}:\n` +
226+
const globalPackagesMessage =
227+
'```bash\n' +
228+
filteredSnapshots
229+
.map((pkg) => `${globalInstallMessage} ${pkg.fullString}`)
230+
.join('\n') +
231+
'\n```';
232+
233+
const localDependenciesMessage =
201234
'```json\n' +
202-
snapshots
203-
.map((tag) =>
204-
tag.startsWith('@')
205-
? `"@${tag.substring(1).split('@')[0]}": "${tag.substring(1).split('@')[1]}"`
206-
: `"${tag.split('@')[0]}": "${tag.split('@')[1]}"`,
207-
)
235+
filteredSnapshots
236+
.map((tag) => `"${tag.package}": "${tag.version}"`)
208237
.join(',\n') +
209238
'\n```';
210239

240+
const defaultMessage = isGlobal
241+
? `Test the snapshot by intalling your package globally:`
242+
: `Test the snapshot${multiple ? 's' : ''} by updating your \`package.json\` with the newly published version${multiple ? 's' : ''}:`;
243+
244+
const body =
245+
`🫰✨ **Thanks @${payload.comment.user.login}! ${introMessage}` +
246+
`${customMessagePrefix ? customMessagePrefix + ' ' : ''}${defaultMessage}\n` +
247+
`${isGlobal ? `${globalPackagesMessage}` : `${localDependenciesMessage}`}` +
248+
`${customMessageSuffix ? `\n\n${customMessageSuffix}` : ''}`;
249+
211250
await octokit.rest.issues.createComment({
212251
...ownerRepo,
213252
issue_number: payload.issue.number,

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "snapit",
33
"private": true,
4-
"version": "0.0.12",
4+
"version": "0.0.13",
55
"description": "Create a snapshot NPM release with `/snapit` comment in a PR",
66
"type": "module",
77
"scripts": {

0 commit comments

Comments
 (0)