|
7 | 7 | "os" |
8 | 8 | "strings" |
9 | 9 | "time" |
| 10 | + |
| 11 | + "github.com/github/codeql-go/extractor/util" |
10 | 12 | ) |
11 | 13 |
|
12 | 14 | type sourceStruct struct { |
@@ -154,14 +156,42 @@ func EmitCannotFindPackages(pkgPaths []string) { |
154 | 156 | secondLine += fmt.Sprintf(" and %d more", numPkgPaths-maxNumPkgPaths) |
155 | 157 | } |
156 | 158 |
|
| 159 | + message := fmt.Sprintf( |
| 160 | + "%d package%s could not be found:\n\n%s.\n\n"+ |
| 161 | + "CodeQL is able to analyze your code without those packages, but definitions from them may not be recognized and "+ |
| 162 | + "source files that use them may only be partially analyzed.\n\n"+ |
| 163 | + "To ensure that you have comprehensive alert coverage, check that the paths are correct and make sure any private packages can be accessed by CodeQL. ", |
| 164 | + numPkgPaths, |
| 165 | + plural(len(pkgPaths), "", "s"), |
| 166 | + secondLine, |
| 167 | + ) |
| 168 | + |
| 169 | + // Depending on the environment we are running in, provide a different message for how to configure access to private registries. |
| 170 | + if util.IsDynamicActionsWorkflow() { |
| 171 | + // For GitHub-managed (dynamic) workflows, we offer built-in support for private registries that customers can set up. |
| 172 | + message = message + |
| 173 | + "Organizations [can grant access to private registries for GitHub security products](https://docs.github.com/en/code-security/how-tos/secure-at-scale/configure-organization-security/manage-usage-and-access/giving-org-access-private-registries). " |
| 174 | + } else { |
| 175 | + if util.IsActionsWorkflow() { |
| 176 | + // For custom workflows, users can add a workflow step to set up credentials or environment variables. |
| 177 | + message = message + |
| 178 | + "To set up access to a private registry, add a step to your workflow which sets up the necessary credentials and environment variables. " |
| 179 | + } else { |
| 180 | + // Otherwise, we are running locally or in some other CI system. |
| 181 | + message = message + |
| 182 | + "To set up access to private registries, ensure that the necessary credentials and environment variables are set up for `go` to use. " |
| 183 | + } |
| 184 | + |
| 185 | + // This should be less likely since we improved Go project discovery. We only include it in the message if we are not running in a |
| 186 | + // GitHub-managed workflow, since users would not be able to act on this there. |
| 187 | + message = message + |
| 188 | + "If any of the packages are already present in the repository, but were not found, then you may need a [custom build command](https://docs.github.com/en/code-security/how-tos/scan-code-for-vulnerabilities/manage-your-configuration/codeql-code-scanning-for-compiled-languages)." |
| 189 | + } |
| 190 | + |
157 | 191 | emitDiagnostic( |
158 | 192 | "go/autobuilder/package-not-found", |
159 | 193 | "Some packages could not be found", |
160 | | - fmt.Sprintf( |
161 | | - "%d package%s could not be found:\n\n%s.\n\nDefinitions in those packages may not be recognized by CodeQL, and files that use them may only be partially analyzed.\n\nCheck that the paths are correct and make sure any private packages can be accessed. If any of the packages are present in the repository then you may need a [custom build command](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-the-codeql-workflow-for-compiled-languages).", |
162 | | - numPkgPaths, |
163 | | - plural(len(pkgPaths), "", "s"), |
164 | | - secondLine), |
| 194 | + message, |
165 | 195 | severityWarning, |
166 | 196 | fullVisibility, |
167 | 197 | noLocation, |
|
0 commit comments