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

feat(action): reuse args from package.json #106

Merged
merged 2 commits into from
Nov 29, 2024

Conversation

colinlienard
Copy link
Contributor

@colinlienard colinlienard commented Nov 26, 2024

If the action doesn't have the args param, and the root package.json contains a script called "sherif", pass the arguments of the sherif script to the action to avoid repeating the same args in the root package.json and the action

@colinlienard colinlienard marked this pull request as ready for review November 28, 2024 15:49
README.md Outdated
@@ -33,6 +33,8 @@ npx sherif@latest

We recommend running Sherif in your CI once [all errors are fixed](#autofix). Run it by **specifying a version instead of latest**. This is useful to prevent regressions (e.g. when adding a library to a package but forgetting to update the version in other packages of the monorepo).

By default, it will search for a `sherif` script in the root `package.json` and try to use the same arguments, so you can avoid repeating yourself. But you can override this behaviour with the `args` param.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
By default, it will search for a `sherif` script in the root `package.json` and try to use the same arguments, so you can avoid repeating yourself. But you can override this behaviour with the `args` param.
When using the GitHub Action, it will search for a `sherif` script in the root `package.json` and use the same arguments automatically to avoid repeating them twice. You can override this behaviour with the `args` parameter.

action/index.ts Outdated
Comment on lines 133 to 138
core.info('No scripts found in package.json');
return;
}

if (!('sherif' in packageJson.scripts)) {
core.info('No sherif script found in package.json');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to log here, it could get noisy for nothing.

}

// Select the args of the sherif script
const regexResult = /sherif\s([a-zA-Z\s\.-]*)(?=\s&&|$)/g.exec(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment to explain what this regex does?

action/index.ts Outdated
);
if (regexResult && regexResult.length > 1) {
const args = regexResult[1];
core.info(`Found args "${args}" package.json`);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
core.info(`Found args "${args}" package.json`);
core.info(`Using the arguments "${args}" from the root package.json`);

Copy link
Owner

@QuiiBz QuiiBz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@QuiiBz QuiiBz merged commit ec03fc5 into QuiiBz:main Nov 29, 2024
4 checks passed
@QuiiBz QuiiBz added the enhancement New feature or request label Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants