| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
This input is exposed in the CodeQL CLI as the flag --source-root, allowing
users of the CLI to set --source-root different from --working-dir. However,
in codeql-action, these two paths are conflated and it poses problems for
users with complicated build environments, in which a source root may be
a child of the working directory.
Most users should not notice this, as the default value is
${{ github.workspace }}, as it is implied now (`path.resolve()`).
In the previous commit, the default value of the input is ${{ github.workspace }}
which means that most uses of this input would probably prefix their paths with
${{ github.workspace }}, especially since actions/checkout's 'path' input
must be under ${{ github.workspace }}. Therefore, it doesn't make much sense for
this to be an absolute file path.
Instead, it's more intuitive to make this relative to the repository.
It causes the action to break (or rather that context being unavailable causes it to fail), despite it being in the description field.
| required: true | ||
| default: 'true' | ||
| source-root: | ||
| description: Path to the root source-code directory, relative to the workspace. |
There was a problem hiding this comment.
I saw you had trouble using ${{ github.workspace }} in the description. In https://github.com/actions/checkout/blob/main/action.yml they use $GITHUB_WORKSPACE and it appears that
default: ${{ github.workspace }}
is also allowed.
Sorry, something went wrong.
There was a problem hiding this comment.
Yes, it is. That was in my first commit, but when I actually started to use it in my test, I found it inconvenient to always have to specify a ${{ github.workspace }} prefix. Hence, why I made it relative to the repo in subsequent commits.
Sorry, something went wrong.
There was a problem hiding this comment.
This looks good to me, thanks!
Sorry, something went wrong.
There was a problem hiding this comment.
I'm worried there are two usages changed within the runner but only one in the init-action. It looks like there's a use of getRequiredEnvParam("GITHUB_WORKSPACE") passed to initConfig in init-action.ts that also needs changing.
Although, I'm actually not sure that changing the calls to initConfig is the right thing to do. This will change how local queries are resolved and I'm not sure if that is intended or not.
In general it depends how this option will be used. Is it for when you want to analyze the whole repository but the repository is checked out to a non-standard location? If so then this change looks good to me (minus my comment above). If instead the intention is to be able to analyze only a subdirectory of a repository, then I think this may need deeper thought to know if this will work or not.
Finally, what manual testing has been done of this? Have you tried running it in a workflow.
Sorry, something went wrong.
|
To follow on from my comment above, looking at how it works in runner.ts currently, the option is used to control where the repository being analyzed is checked out to, but we haven't done it properly. It seems wrong to me that we currently use cmd.checkoutPath in initConfig but don't use it when initializing the codeql databases. So to a large degree the changes in this PR are just fixing a bug that was present already 👍 |
Sorry, something went wrong.
I think we should not change initConfig here. The source-root property is the equivalent of the --source-root flag of the CodeQL CLI and its only purpose it to inform CodeQL what the path to the "source files" is so it can produce the correct relative paths in the SARIF output. |
Sorry, something went wrong.
I've now come around to the other way of thinking. I think we should change initConfig (in the sense that we should pass the checkout path to it) because that's what we're already doing in the runnner. You can see we pass cmd.checkoutPath to initConfig and that's currently the only place we use it in the runner command.
What does "path to the source files" mean? Is that the root of the github repository, or a subdirectory within a repository? When talking about relative paths in the SARIF output we need those to be relative to the root of the repository, don't we? If not then showing files in the code scanning UI will not work. |
Sorry, something went wrong.
Yes that's right. It should be the path to the root of the github repository being analysed, or perhaps more precisely the repository to which the SARIF file will be uploaded. The use-case for this feature is for complex build setups that for example require a bunch of repositories (the repo to be analysed an its dependencies) to be checked out in a particular folder hierarchy that does not match the actions/checkout's defaults . |
Sorry, something went wrong.
I think there is no such thing as "the checkout path". A user can organise the workspace folder structure in any way they like either by configuring actions/checkout or even cloning repos "manually". I think a user could store the config file in another repo that is checked out somewhere in the workspace, or perhaps even have it in a fixed place on a self-hosted worker. |
Sorry, something went wrong.
Yes, I deliberately did not change initConfig because I believe that when someone specifies a local query in the config file, ./ has the connotation of the root of the repository. It would be very confusing to find that it changes based on the source-root specified elsewhere in the workflow file, in my opinion.
Yes, exactly, which, admittedly, is a minor use-case, but one that I have seen already and one which is supported in the CLI with the --source-root and --working-dir flags.
My intention was not to replace paths/paths-ignore. Although, it seems it could somewhat be used to that effect.
|
Sorry, something went wrong.
|
@mario-campos, sorry for the confusing comments above. You can likely ignore my comments and go with what @aibaars says. We had quite a long chat on this and I think we're now on the same page with this, so you can ignore anything contradictory that I said earlier. |
Sorry, something went wrong.
Previously, I had tried to refer to '${{ github.workspace }}', but that caused a problem in Actions. Trying to avoid the issue, I changed this to "the workspace," but this gives up quite a bit of specificity.
Co-authored-by: Arthur Baars <aibaars@github.com>
Thanks to @aibaars, `path.resolve()` should will nicely handle more use-cases, namely absolute paths better than `path.join()`. Co-authored-by: Arthur Baars <aibaars@github.com>
There was a problem hiding this comment.
Looks sensible. Would you be willing to add a test, here or in a follow up PR?
Sorry, something went wrong.
|
|
||
| ## [UNRELEASED] | ||
|
|
||
| - The `init` step of the Action now supports a `source-root` input to be able to specify a path under the GitHub workspace to be the root source-code directory. [#607](https://github.com/github/codeql-action/pull/607) |
There was a problem hiding this comment.
Could we mention that the default is the $GITHUB_WORKSPACE root?
Sorry, something went wrong.
There was a problem hiding this comment.
Done.
Sorry, something went wrong.
This addresses @adityasharad's suggestions in PR #607.
|
Yes, I can add tests. Where would I do that, though? I don't see a test file for init.ts. |
Sorry, something went wrong.
|
Hmm good point, we don't seem to have unit tests. Perhaps another test job in pr-checks.yml, that exercises the source-root field in the init step. I think you can copy the test-packaging-javascript-config job as a template, and remove the packs inputs there. Those tests use a simple multilanguage test folder checked into the repo, so you could point explicitly to that path as the source root. |
Sorry, something went wrong.
This config file 'ought to have some queries good for testing!
|
Huh. Any idea why a source root would be considered invalid (aside from it not existing)? A fatal error occurred: Invalid source root: /home/runner/work/codeql-action/codeql-action/tests/multi-language-repo. Error: Failure invoking /opt/hostedtoolcache/CodeQL/0.0.0-20210622/x64/codeql/codeql with arguments database,init,/home/runner/work/_temp/codeql_databases/javascript,--language=javascript,--source-root=/home/runner/work/codeql-action/codeql-action/tests/multi-language-repo. Exit code 2 and error was: A fatal error occurred: Invalid source root: /home/runner/work/codeql-action/codeql-action/tests/multi-language-repo. |
Sorry, something went wrong.
| run: | | ||
| mkdir ../action | ||
| mv * .github ../action/ | ||
| mv ../action/tests/multi-language-repo/{*,.github} . |
There was a problem hiding this comment.
I suspect this is the problem: it will move all the contents of multi-language-repo into the current directory, and not preserve the tests/multi-language-repo enclosing directories.
One option to try might be to avoid these moves entirely, and set source-root as you've done below. The moves are needed for other tests because they scan the entire repo from the workspace root, but the whole point of source-root is to customise that behaviour.
Sorry, something went wrong.
There was a problem hiding this comment.
Good call. That makes sense.
Sorry, something went wrong.
| mv ../action/.github/workflows .github | ||
| - uses: ./../action/init | ||
| with: | ||
| config-file: ".github/codeql/codeql-config-packaging.yml" |
There was a problem hiding this comment.
I think you may be able to remove this, and keep the test focused on only the source-root feature.
Sorry, something went wrong.
The test is not related to packaging. Co-authored-by: Aditya Sharad <6874315+adityasharad@users.noreply.github.com>
Moving the files into ../action was causing the job to fail because it couldn't find the test directory anymore. According to @adityasharad, these 'mv's should not be necessary. Removing these means changing the path to the actions. I'm also removing the 'config-file' input to keep the test minimal. I think this will mean that CodeQL will use the default query suite, so I hope that this doesn't change the results.
…tion into source-root-input
As this test is using only JS, it's not necessary to compile or analyze the other languages.
This is for PR #607, 'source-root' input test case.
There was a problem hiding this comment.
One test addition to actually build the database, then I think it's good to go!
Sorry, something went wrong.
Co-authored-by: Aditya Sharad <6874315+adityasharad@users.noreply.github.com>
This addresses @adityasharad's suggestions in PR github#607.
This is for PR github#607, 'source-root' input test case.
| Back | FazBrowse Home | New Git URL |
Merge / deployment checklist