Skip to content

Commit 9f048f6

Browse files
alex-pagegithub-actions[bot]
authored andcommitted
Update GitHub Action Inputs to be more cohesive (#32)
1 parent 3eeca65 commit 9f048f6

File tree

5 files changed

+48
-49
lines changed

5 files changed

+48
-49
lines changed

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
3838
with:
3939
build_script: pnpm build # Optional
40-
comment_command: /snapit # Default value not required
40+
trigger_comment: /snapit # Default value not required
4141
```
4242
4343
**Deploy to branch**
@@ -66,7 +66,7 @@ jobs:
6666
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6767
with:
6868
branch: snapshot-release
69-
comment_command: /snapit # Default value not required
69+
trigger_comment: /snapit # Default value not required
7070
```
7171
7272
## Environment Variables
@@ -79,20 +79,20 @@ The `GITHUB_TOKEN` is needed for changesets to look up the current changeset whe
7979

8080
A `NPM_TOKEN` needs to be created and added to the repository to [publish packages from GitHub actions to the npm registry](https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages#publishing-packages-to-the-npm-registry).
8181

82-
## Action workflow options
83-
84-
| Option | Default | Description |
85-
| ---------------------------------- | ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
86-
| `build_script` | - | The build script to run before publishing. |
87-
| `comment_command` | `/snapit` | The comment to write to trigger the creation of a snapshot. |
88-
| `branch` | - | Push the changes to a branch instead of publishing to the NPM registry. |
89-
| `custom_message_prefix` | - | Custom message to add to the beginning of the release GitHub comment. Default: "Test the snapshots by updating your package.json with the newly published versions:" |
90-
| `custom_message_suffix` | - | Custom message to add to the end of the release GitHub comment. |
91-
| `global_install` | `false` | If true, the generated GitHub comment will show the command to install your packages globally. Otherwise, shows a JSON example to update local dependencies. |
92-
| `github_comment_included_packages` | - | Filter to include specific packages in the release GitHub comment. Separate multiple packages with commas. |
93-
| `working_directory` | - | If specified, the action will run all commands for snapit in the specified directory. |
94-
| `post_install_script` | - | If specified, will run a script after dependencies are installed. |
95-
| `release_branch` | `changeset-release/main` | If specified, will use this branch name in place of the default |
82+
## GitHub Action Inputs
83+
84+
| Inputs (All Optional) | Description |
85+
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
86+
| `trigger_comment` | Default: `/snapit`. Comma seperated list of comments to write to trigger the creation of a snapshot. |
87+
| `comment_prefix` | Custom message to add to the beginning of the release GitHub comment. Default: "Test the snapshots by updating your package.json with the newly published versions:" |
88+
| `comment_suffix` | Custom message to add to the end of the release GitHub comment. |
89+
| `comment_packages` | Filter to include specific packages in the release GitHub comment. Separate multiple packages with commas. |
90+
| `comment_is_global` | If true, the generated GitHub comment will show the command to install your packages globally. Otherwise, shows a JSON example to update local dependencies. |
91+
| `cwd` | If specified, the action will run all commands for snapit in the specified directory. |
92+
| `branch` | Push the changes to a branch instead of publishing to the NPM registry. |
93+
| `post_install_script` | If specified, will run a script after dependencies are installed. |
94+
| `build_script` | The build script to run before publishing. |
95+
| `release_branch` | Default: `changeset-release/main`. If specified, will use this branch name in place of the default |
9696

9797
## Contributing
9898

action.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@ name: snapit-release
22
description: Create a snapshot NPM release with `/snapit` comment in a PR
33
author: Shopify
44
inputs:
5-
build_script:
6-
description: Build script for building the repository before publishing.
7-
post_install_script:
8-
description: Script to run after dependencies are installed.
9-
comment_command:
5+
trigger_comment:
106
description: A comma seperated list of comment commands to trigger the action
117
default: '/snapit'
12-
branch:
13-
description: Push the changes to a branch instead of publishing to the NPM registry.
14-
custom_message_prefix:
8+
comment_prefix:
159
description: Custom message added to the beginning of the snapit GitHub comment. By default a generic message is shown.
16-
custom_message_suffix:
10+
comment_suffix:
1711
description: Custom message added to the end of the snapit GitHub comment.
18-
global_install:
19-
description: If true, the GitHub comment will show instructions to install a global npm package instead of the normal JSON dependencies.
20-
github_comment_included_packages:
12+
comment_packages:
2113
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.
22-
working_directory:
14+
comment_is_global:
15+
description: If true, the generated GitHub comment will show the command to install your packages globally. Otherwise, shows a JSON example to update local dependencies.
16+
cwd:
2317
description: If specified, the action will run all commands for snapit in the specified directory.
18+
branch:
19+
description: Push the changes to a branch instead of publishing to the NPM registry.
20+
build_script:
21+
description: Build script for building the repository before publishing.
22+
post_install_script:
23+
description: Script to run after dependencies are installed.
2424
release_branch:
2525
description: If specified, will use this branch name in place of the default `changeset-release/main` branch.
2626
default: 'changeset-release/main'

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: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,29 @@ try {
3030
repo: payload.repository.name,
3131
};
3232

33+
const branch = core.getInput('branch');
34+
const commentCommand = core.getInput('comment_command');
35+
const commentPrefix = core.getInput('commment_prefix');
36+
const commentSuffix = core.getInput('commment_suffix');
37+
const commentIsGlobal = core.getInput('comment_is_global') === 'true';
3338
const postInstallScript = core.getInput('post_install_script');
3439
const buildScript = core.getInput('build_script');
35-
const isGlobal = core.getInput('global_install') === 'true';
36-
const githubCommentIncludedPackages = core.getInput(
37-
'github_comment_included_packages',
38-
);
39-
const branch = core.getInput('branch');
40-
const workingDirectory = core.getInput('working_directory');
41-
const customMessagePrefix = core.getInput('custom_message_prefix');
42-
const customMessageSuffix = core.getInput('custom_message_suffix');
43-
const commentCommands = core.getInput('comment_command');
40+
const commentPackages = core.getInput('comment_packages');
41+
const cwd = core.getInput('cwd');
4442
const octokit = github.getOctokit(process.env.GITHUB_TOKEN);
4543
const releaseBranch =
4644
core.getInput('release_branch') ?? 'changeset-release/main';
4745

48-
if (workingDirectory) {
49-
process.chdir(workingDirectory);
46+
if (cwd) {
47+
process.chdir(cwd);
5048
}
5149

5250
const isYarn = existsSync('yarn.lock');
5351
const isPnpm = existsSync('pnpm-lock.yaml');
5452
const changesetBinary = path.join('node_modules/.bin/changeset');
5553
const versionPrefix = 'snapshot';
5654

57-
if (commentCommands.split(',').indexOf(payload.comment.body) !== -1) {
55+
if (commentCommand.split(',').indexOf(payload.comment.body) !== -1) {
5856
await octokit.rest.reactions.createForIssueComment({
5957
...ownerRepo,
6058
comment_id: payload.comment.id,
@@ -214,9 +212,9 @@ try {
214212
]);
215213
}
216214

217-
const filteredSnapshots = githubCommentIncludedPackages
215+
const filteredSnapshots = commentPackages
218216
? snapshots.filter((snapshot: Snapshot) =>
219-
githubCommentIncludedPackages
217+
commentPackages
220218
.split(',')
221219
.some((filter) => snapshot.package === filter),
222220
)
@@ -247,15 +245,15 @@ try {
247245
.join(',\n') +
248246
'\n```';
249247

250-
const defaultMessage = isGlobal
248+
const defaultMessage = commentIsGlobal
251249
? `Test the snapshot by installing your package globally:`
252250
: `Test the snapshot${multiple ? 's' : ''} by updating your \`package.json\` with the newly published version${multiple ? 's' : ''}:`;
253251

254252
const body =
255253
`🫰✨ **Thanks @${payload.comment.user.login}! ${introMessage}` +
256-
`${customMessagePrefix ? customMessagePrefix + ' ' : ''}${defaultMessage}\n` +
257-
`${isGlobal ? `${globalPackagesMessage}` : `${localDependenciesMessage}`}` +
258-
`${customMessageSuffix ? `\n\n${customMessageSuffix}` : ''}`;
254+
`${commentPrefix ? commentPrefix + ' ' : ''}${defaultMessage}\n` +
255+
`${commentIsGlobal ? `${globalPackagesMessage}` : `${localDependenciesMessage}`}` +
256+
`${commentSuffix ? `\n\n${commentSuffix}` : ''}`;
259257

260258
await octokit.rest.issues.createComment({
261259
...ownerRepo,

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@
3939
"singleQuote": true,
4040
"bracketSpacing": false,
4141
"trailingComma": "all"
42-
}
42+
},
43+
"packageManager": "pnpm@8.15.5+sha256.4b4efa12490e5055d59b9b9fc9438b7d581a6b7af3b5675eb5c5f447cee1a589"
4344
}

0 commit comments

Comments
 (0)