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

Build components in CodeQL pipeline #1970

Merged
merged 1 commit into from
Nov 14, 2023
Merged

Conversation

helsaawy
Copy link
Contributor

@helsaawy helsaawy commented Nov 14, 2023

Need to build binaries for CodeQL to work:

For the compiled languages C/C++, C#, Go, Java, and Swift, the process of populating
this database involves building the code and extracting data.

https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages#about-the-codeql-analysis-workflow-and-compiled-languages

Without explicit build commands between CodeQL init and analyze steps, CodeQL will attempt to automatically build go code using the following logic:
https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages#autobuild-for-go

This can be see in the CodeQL Analyze step in out pipelines:

Attempting to automatically build go code
  Autobuilder was built with go1.21.3, environment has go1.20.10
  LGTM_SRC is /home/runner/work/hcsshim/hcsshim
  Found go.mod, enabling go modules
  Import path is 'github.com/microsoft/hcsshim'
  Makefile found.
  Trying build command make []
  make: *** No rule to make target 'base.tar.gz', needed by 'out/initrd.img'.  Stop.
  Running /usr/bin/make failed, continuing anyway: exit status 2
  Build failed, continuing to install dependencies.
  Skipping dependency installation because a Go vendor directory was found.
  Running extractor command '/opt/hostedtoolcache/CodeQL/2.15.2/x64/codeql/go/tools/linux64/go-extractor [-mod=vendor ./...]' from directory '.'.
  <...>

Rather than rely on autobuild, explicitly configure CodeQL and build necessary targets.

Skip running CodeQL on PRs if no code is changed.

Based on guidance from:
https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning
and workflow:
https://github.com/github/codeql/blob/0342b3eba242476cea815e601942021092d0bc10/.github/workflows/codeql-analysis.yml

@helsaawy helsaawy requested a review from a team as a code owner November 14, 2023 18:48
Copy link
Contributor

@anmaxvl anmaxvl left a comment

Choose a reason for hiding this comment

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

Thanks!

@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

Need to build binaries for CodeQL to work:

> For the compiled languages C/C++, C#, Go, Java, and Swift, the process of populating
> this database involves building the code and extracting data.

docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages#about-the-codeql-analysis-workflow-and-compiled-languages

Without explicit build commands between CodeQL `init` and `analyze`
steps, CodeQL will attempt to automatically build go code using the
following logic:
docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages#autobuild-for-go

This can be see in the `CodeQL Analyze` step in out pipelines:

```
Attempting to automatically build go code
  Autobuilder was built with go1.21.3, environment has go1.20.10
  LGTM_SRC is /home/runner/work/hcsshim/hcsshim
  Found go.mod, enabling go modules
  Import path is 'github.com/microsoft/hcsshim'
  Makefile found.
  Trying build command make []
  make: *** No rule to make target 'base.tar.gz', needed by 'out/initrd.img'.  Stop.
  Running /usr/bin/make failed, continuing anyway: exit status 2
  Build failed, continuing to install dependencies.
  Skipping dependency installation because a Go vendor directory was found.
  Running extractor command '/opt/hostedtoolcache/CodeQL/2.15.2/x64/codeql/go/tools/linux64/go-extractor [-mod=vendor ./...]' from directory '.'.
  <...>
```

Rather than rely on autobuild, explicitly configure CodeQL and build
necessary targets.

Skip running CodeQL on PRs if no code is changed.

Based on workflow:
github.com/github/codeql/blob/0342b3eba242476cea815e601942021092d0bc10/.github/workflows/codeql-analysis.yml

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
@helsaawy helsaawy merged commit 5c75f29 into microsoft:main Nov 14, 2023
18 of 19 checks passed
@helsaawy helsaawy deleted the codeql branch November 14, 2023 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants