Skip to content

Commit 7c357a3

Browse files
Add shopify_registry and package_manager params
1 parent 5345972 commit 7c357a3

6 files changed

Lines changed: 36 additions & 16 deletions

File tree

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ jobs:
3838
with:
3939
build_script: pnpm build # Optional
4040
comment_command: /snapit # Default value not required
41+
package_manager: pnpm # Optional: override auto-detection
42+
shopify_registry: https://registry.npmjs.org # Optional: Shopify NPM registry URL
4143
```
4244
4345
**Deploy to branch**
@@ -67,6 +69,8 @@ jobs:
6769
with:
6870
branch: snapshot-release
6971
comment_command: /snapit # Default value not required
72+
package_manager: pnpm # Optional: override auto-detection
73+
shopify_registry: https://registry.npmjs.org # Optional: Shopify NPM registry URL
7074
```
7175
7276
## Environment Variables
@@ -93,6 +97,8 @@ A `NPM_TOKEN` needs to be created and added to the repository to [publish packag
9397
| `working_directory` | - | If specified, the action will run all commands for snapit in the specified directory. |
9498
| `post_install_script` | - | If specified, will run a script after dependencies are installed. |
9599
| `release_branch` | `changeset-release/main` | If specified, will use this branch name in place of the default |
100+
| `package_manager` | - | Package manager to show for global installation (`yarn`, `npm`, or `pnpm`). If not specified, auto-detects based on lock files. |
101+
| `shopify_registry` | - | Shopify NPM registry URL (e.g. `https://registry.npmjs.org`). Will be added as `--@shopify:registry=` to global installation command. |
96102

97103
## Contributing
98104

@@ -107,6 +113,11 @@ To contribute a change, bug fix or feature to snapit:
107113

108114
## Changelog
109115

116+
**`v0.0.16`**
117+
118+
- Add `package_manager` to specify which package manager to use instead of auto-detecting
119+
- Add `shopify_registry` to specify Shopify NPM registry URL (automatically adds `--@shopify:registry=` prefix)
120+
110121
**`v0.0.15`**
111122

112123
- Add `release_branch` to configure the default release branch. Default is `changeset-release/main`.

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ inputs:
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'
27+
package_manager:
28+
description: Package manager to show for global installation (yarn/npm/pnpm). If not specified, will auto-detect based on lock files.
29+
shopify_registry:
30+
description: Shopify NPM registry URL (e.g. https://registry.npmjs.org). Will be added as --@shopify:registry= to global installation command.
2731

2832
runs:
2933
using: node20

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: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ try {
4141
const customMessagePrefix = core.getInput('custom_message_prefix');
4242
const customMessageSuffix = core.getInput('custom_message_suffix');
4343
const commentCommands = core.getInput('comment_command');
44+
const specifiedPackageManager = core.getInput('package_manager');
45+
const shopifyRegistryUrl = core.getInput('shopify_registry');
4446
const octokit = github.getOctokit(process.env.GITHUB_TOKEN);
4547
const releaseBranch =
4648
core.getInput('release_branch') ?? 'changeset-release/main';
@@ -49,8 +51,12 @@ try {
4951
process.chdir(workingDirectory);
5052
}
5153

52-
const isYarn = existsSync('yarn.lock');
53-
const isPnpm = existsSync('pnpm-lock.yaml');
54+
// Auto-detect based on lock files
55+
let packageManager = 'npm';
56+
if (existsSync('yarn.lock')) packageManager = 'yarn';
57+
else if (existsSync('pnpm-lock.yaml')) packageManager = 'pnpm';
58+
59+
5460
const changesetBinary = path.join('node_modules/.bin/changeset');
5561
const versionPrefix = 'snapshot';
5662

@@ -117,12 +123,10 @@ try {
117123
}
118124

119125
// Running install to get the changesets package from the project
120-
if (isYarn) {
121-
await exec('yarn', ['install', '--frozen-lockfile']);
122-
} else if (isPnpm) {
123-
await exec('pnpm', ['install', '--frozen-lockfile']);
124-
} else {
126+
if (packageManager === 'npm') {
125127
await exec('npm', ['ci']);
128+
} else {
129+
await exec(packageManager, ['install', '--frozen-lockfile']);
126130
}
127131

128132
// Run post install script after dependencies are installed
@@ -227,11 +231,12 @@ try {
227231
? `Your snapshot${multiple ? 's are' : ' is'} being published.**\n\n`
228232
: `Your snapshot${multiple ? 's have' : ' has'} been published to npm.**\n\n`;
229233

230-
const globalInstallMessage = isYarn
231-
? 'yarn global add'
232-
: isPnpm
233-
? 'pnpm i -g'
234-
: 'npm i -g';
234+
const messagePackageManager = specifiedPackageManager?.toLowerCase() ?? packageManager;
235+
let globalInstallMessage =
236+
messagePackageManager === 'yarn' ? 'yarn global add' : `${messagePackageManager} i -g`;
237+
if (shopifyRegistryUrl) {
238+
globalInstallMessage = `${globalInstallMessage} --@shopify:registry=${shopifyRegistryUrl}`;
239+
}
235240

236241
const globalPackagesMessage =
237242
'```bash\n' +

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.15",
4+
"version": "0.0.16",
55
"description": "Create a snapshot NPM release with `/snapit` comment in a PR",
66
"type": "module",
77
"scripts": {

0 commit comments

Comments
 (0)