Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat build_script as optional #24

Merged
merged 2 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ To contribute a change, bug fix or feature to snapit:

1. Make a new branch `my-branch`
1. Make the changes you need
1. Run `pnpm build`
1. Run `npm run build`
1. Push your changes to the branch
1. In your repositories `main` branch point the `.github/snapit.yml` file to the `shopify/snapit` branch `uses: Shopify/snapit@my-branch`
1. Create a pull request with changeset and write `/snapit` as a comment in the pull request
Expand Down
4 changes: 4 additions & 0 deletions dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: snapit
up:
- node:
version: v22.12.0
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

196 changes: 98 additions & 98 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,110 +160,110 @@ try {
);
}
}
}

if (branch) {
// We all think this is weird
// Context: https://github.com/orgs/community/discussions/26560
await exec('git', [
'config',
'--global',
'user.email',
'41898282+github-actions[bot]@users.noreply.github.com',
]);
await exec('git', [
'config',
'--global',
'user.name',
'github-actions[bot]',
]);
await exec('git', ['add', '.']);
await exec('git', [
'commit',
'-m',
`${payload.issue.title} ${versionPrefix}-${snapshotTimestamp}`,
]);
await exec('git', ['checkout', '-b', branch]);
await exec('git', ['push', '--force', 'origin', branch]);
} else {
if (!process.env.NPM_TOKEN) {
throw new Error(
'Please provide the NPM_TOKEN to the snapit GitHub action',
);
}

await exec(
'bash',
[
'-c',
`echo "//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}" > "$HOME/.npmrc"`,
],
silentOption,
if (branch) {
// We all think this is weird
// Context: https://github.com/orgs/community/discussions/26560
await exec('git', [
'config',
'--global',
'user.email',
'41898282+github-actions[bot]@users.noreply.github.com',
]);
await exec('git', [
'config',
'--global',
'user.name',
'github-actions[bot]',
]);
await exec('git', ['add', '.']);
await exec('git', [
'commit',
'-m',
`${payload.issue.title} ${versionPrefix}-${snapshotTimestamp}`,
]);
await exec('git', ['checkout', '-b', branch]);
await exec('git', ['push', '--force', 'origin', branch]);
} else {
if (!process.env.NPM_TOKEN) {
throw new Error(
'Please provide the NPM_TOKEN to the snapit GitHub action',
);

await exec(changesetBinary, [
'publish',
'--no-git-tags',
'--snapshot',
'--tag',
versionPrefix,
]);
}

const filteredSnapshots = githubCommentIncludedPackages
? snapshots.filter((snapshot: Snapshot) =>
githubCommentIncludedPackages
.split(',')
.some((filter) => snapshot.package === filter),
)
: snapshots;
const multiple = filteredSnapshots.length > 1;

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

const globalInstallMessage = isYarn
? 'yarn global add'
: isPnpm
? 'pnpm i -g'
: 'npm i -g';

const globalPackagesMessage =
'```bash\n' +
filteredSnapshots
.map((pkg) => `${globalInstallMessage} ${pkg.fullString}`)
.join('\n') +
'\n```';

const localDependenciesMessage =
'```json\n' +
filteredSnapshots
.map((tag) => `"${tag.package}": "${tag.version}"`)
.join(',\n') +
'\n```';

const defaultMessage = isGlobal
? `Test the snapshot by installing your package globally:`
: `Test the snapshot${multiple ? 's' : ''} by updating your \`package.json\` with the newly published version${multiple ? 's' : ''}:`;

const body =
`🫰✨ **Thanks @${payload.comment.user.login}! ${introMessage}` +
`${customMessagePrefix ? customMessagePrefix + ' ' : ''}${defaultMessage}\n` +
`${isGlobal ? `${globalPackagesMessage}` : `${localDependenciesMessage}`}` +
`${customMessageSuffix ? `\n\n${customMessageSuffix}` : ''}`;

await octokit.rest.issues.createComment({
...ownerRepo,
issue_number: payload.issue.number,
body,
});
await exec(
'bash',
[
'-c',
`echo "//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}" > "$HOME/.npmrc"`,
],
silentOption,
);

await octokit.rest.reactions.createForIssueComment({
...ownerRepo,
comment_id: payload.comment.id,
content: 'rocket',
});
await exec(changesetBinary, [
'publish',
'--no-git-tags',
'--snapshot',
'--tag',
versionPrefix,
]);
}

const filteredSnapshots = githubCommentIncludedPackages
? snapshots.filter((snapshot: Snapshot) =>
githubCommentIncludedPackages
.split(',')
.some((filter) => snapshot.package === filter),
)
: snapshots;
const multiple = filteredSnapshots.length > 1;

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

const globalInstallMessage = isYarn
? 'yarn global add'
: isPnpm
? 'pnpm i -g'
: 'npm i -g';

const globalPackagesMessage =
'```bash\n' +
filteredSnapshots
.map((pkg) => `${globalInstallMessage} ${pkg.fullString}`)
.join('\n') +
'\n```';

const localDependenciesMessage =
'```json\n' +
filteredSnapshots
.map((tag) => `"${tag.package}": "${tag.version}"`)
.join(',\n') +
'\n```';

const defaultMessage = isGlobal
? `Test the snapshot by installing your package globally:`
: `Test the snapshot${multiple ? 's' : ''} by updating your \`package.json\` with the newly published version${multiple ? 's' : ''}:`;

const body =
`🫰✨ **Thanks @${payload.comment.user.login}! ${introMessage}` +
`${customMessagePrefix ? customMessagePrefix + ' ' : ''}${defaultMessage}\n` +
`${isGlobal ? `${globalPackagesMessage}` : `${localDependenciesMessage}`}` +
`${customMessageSuffix ? `\n\n${customMessageSuffix}` : ''}`;

await octokit.rest.issues.createComment({
...ownerRepo,
issue_number: payload.issue.number,
body,
});

await octokit.rest.reactions.createForIssueComment({
...ownerRepo,
comment_id: payload.comment.id,
content: 'rocket',
});
}
} catch (error) {
core.setFailed(error.message);
Expand Down
Loading