-
Notifications
You must be signed in to change notification settings - Fork 429
Move config parsing earlier + add to codeql search path #109
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
Conversation
sampart
left a comment
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.
This is a really great improvement. All my comments are stylistic, so I'm approving this. Thank you!
src/codeql.ts
Outdated
| } | ||
|
|
||
| /** | ||
| * Stores the CodeQL object, and is populated by `setupCodeQL`. |
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.
It might also be set by getCodeQL; I don't know if you need to mention that.
| return partialCodeql[methodName]; | ||
| } | ||
|
|
||
| export function setCodeQL(partialCodeql: Partial<CodeQL>) { |
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.
Do you need a comment saying "Only for use in tests?"
src/config-utils.ts
Outdated
| /** | ||
| * Get the file path where the parsed config will be stored. | ||
| */ | ||
| export function getParsedConfigFile(): string { |
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.
getParsedConfigFile sounds to me like you're returning the configuration itself. What about getPathToParsedConfigFile?
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.
If you do this, I guess the previous method should be renamed to something like getPathToParsedConfigFileFolder, although that does sound a bit clunky.
src/config-utils.ts
Outdated
| return languages; | ||
| } | ||
|
|
||
| export async function getBlankConfig(): Promise<Config> { |
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.
Would this be better as getDefaultConfig, since it does have content? That would also bring parity with addDefaultQueries.
src/config-utils.test.ts
Outdated
|
|
||
| // And the contents should parse correctly to the config that was returned | ||
| t.deepEqual(fs.readFileSync(configFile, 'utf8'), JSON.stringify(config)); | ||
| // And the same config should be returned again |
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.
"again" makes it sound like you're calling this function for the second time, but you're not
| // And the same config should be returned again | |
| // And that same newly-initialised config should now be returned by getConfig |
src/config-utils.ts
Outdated
| queryUses: string) { | ||
|
|
||
| // The logic for parsing the string is based on what actions does for | ||
| // parsing the 'uses' actions in the workflow file |
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.
Does this comment relate just to the 4 lines that follow? If not, I'd put it in the function-level comment.
src/config-utils.ts
Outdated
|
|
||
| // Property names from the user-supplied config file. | ||
| const NAME_PROPERTY = 'name'; | ||
| const DISPLAY_DEFAULT_QUERIES_PROPERTY = 'disable-default-queries'; |
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.
I know this wasn't added in this PR, but you're making use of it in your changed code, and that code would be much easier to read if it was called DISABLE_DEFAULT_QUERIES_PROPERTY.
Consider this bit, for example:
if (!parsedYAML[DISPLAY_DEFAULT_QUERIES_PROPERTY]) {
await addDefaultQueries(languages, queries);
}
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.
Thanks for spotting that. I think that must just be a slip of the keyboard from when that property was originally added.
src/config-utils.ts
Outdated
| * a default config. The parsed config is then stored to a known location. | ||
| */ | ||
| export async function initConfig(): Promise<Config> { | ||
| let configFile = core.getInput('config-file'); |
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.
| let configFile = core.getInput('config-file'); | |
| const configFile = core.getInput('config-file'); |
src/external-queries.test.ts
Outdated
| await externalQueries.checkoutExternalQueries(config); | ||
| await externalQueries.checkoutExternalRepository("github/codeql-go", "df4c6869212341b601005567381944ed90906b6b"); | ||
|
|
||
| // COPYRIGHT file existed in df4c6869212341b601005567381944ed90906b6b but not in master |
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.
| // COPYRIGHT file existed in df4c6869212341b601005567381944ed90906b6b but not in master | |
| // COPYRIGHT file existed in df4c6869212341b601005567381944ed90906b6b but not in main |
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.
The default branch on https://github.com/github/codeql-go is still called master. I'll make the comment more clear that it's talking about the default branch without naming it.
src/external-queries.ts
Outdated
|
|
||
| export async function checkoutExternalQueries(config: configUtils.Config) { | ||
| /** | ||
| * Checkout a repository at the given ref, and return the directory of the checkout. |
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.
| * Checkout a repository at the given ref, and return the directory of the checkout. | |
| * Check out repository at the given ref, and return the directory of the checkout. |
Removing the "a" makes it clearer how you're using the repository parameter.
This change started out just trying to add
--search-pathto the CodeQL args when resolving queries, however in doing that I wasn't able to get the data where I needed it nicely. A simpler but cruder answer could have been to stuff some extra fields in the objects already being passed around, but that didn't seem ideal to me. Instead this PR restructures how we parse and process the config considerably to move everything sooner and to one place.The main changes are:
initaction. Previously it was mostly in theinitaction, but there was a large chunk in theanalyzeaction where we checked out external repositories and converted the user-supplied list of queries and query suites to run into an explicit list of query files.This is quite a big change, but I think is has a few benefits:
initaction. Previously if you specified queries from a remote repository but the repository or file path didn't exist, then you wouldn't find out until after the code has been built.--search-pathbecause all of the data is available.Merge / deployment checklist