-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -11,7 +11,7 @@ async function run(): Promise<void> { | |||||
// Get inputs | ||||||
const version = core.getInput('version'); | ||||||
const token = core.getInput('github-token'); | ||||||
const additionalArgs = core.getInput('args'); | ||||||
let additionalArgs = core.getInput('args'); | ||||||
|
||||||
// Initialize octokit | ||||||
const octokit = github.getOctokit(token); | ||||||
|
@@ -91,6 +91,9 @@ async function run(): Promise<void> { | |||||
core.info('Sherif has been installed successfully'); | ||||||
|
||||||
// Prepare arguments | ||||||
if (!additionalArgs) { | ||||||
additionalArgs = (await getArgsFromPackageJson()) || ''; | ||||||
} | ||||||
const args = additionalArgs.split(' ').filter(arg => arg !== ''); | ||||||
|
||||||
// Configure output options to preserve colors | ||||||
|
@@ -119,4 +122,35 @@ async function run(): Promise<void> { | |||||
} | ||||||
} | ||||||
|
||||||
async function getArgsFromPackageJson() { | ||||||
try { | ||||||
const packageJsonFile = await fsp.readFile( | ||||||
path.resolve(process.cwd(), 'package.json') | ||||||
); | ||||||
const packageJson = JSON.parse(packageJsonFile.toString()); | ||||||
|
||||||
if (!('scripts' in packageJson)) { | ||||||
core.info('No scripts found in package.json'); | ||||||
return; | ||||||
} | ||||||
|
||||||
if (!('sherif' in packageJson.scripts)) { | ||||||
core.info('No sherif script found in package.json'); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||
return; | ||||||
} | ||||||
|
||||||
// Select the args of the sherif script | ||||||
const regexResult = /sherif\s([a-zA-Z\s\.-]*)(?=\s&&|$)/g.exec( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a comment to explain what this regex does? |
||||||
packageJson.scripts.sherif | ||||||
); | ||||||
if (regexResult && regexResult.length > 1) { | ||||||
const args = regexResult[1]; | ||||||
core.info(`Found args "${args}" package.json`); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return args; | ||||||
} | ||||||
} catch { | ||||||
core.info('Failed to extract args from package.json'); | ||||||
} | ||||||
} | ||||||
|
||||||
run(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.