fix after review from @henrymercer
This commit is contained in:
parent
fc374f5e9a
commit
f398a65921
7 changed files with 39 additions and 37 deletions
52
README.md
52
README.md
|
|
@ -137,41 +137,35 @@ By default, this will override any queries specified in a config file. If you wi
|
||||||
|
|
||||||
### Configuration via `config` input
|
### Configuration via `config` input
|
||||||
|
|
||||||
|
|
||||||
You can alternatively configure CodeQL using the `config` input to the `init` Action. The value of this input must be a YAML string that follows the configuration file format documented at "[Using a custom configuration file](https://help.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#using-a-custom-configuration-file)."
|
You can alternatively configure CodeQL using the `config` input to the `init` Action. The value of this input must be a YAML string that follows the configuration file format documented at "[Using a custom configuration file](https://help.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#using-a-custom-configuration-file)."
|
||||||
|
|
||||||
|
#### Example configuration
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: github/codeql-action/init@v2
|
||||||
|
with:
|
||||||
|
languages: ${{ matrix.language }}
|
||||||
|
config: |
|
||||||
|
disable-default-queries: true
|
||||||
|
queries:
|
||||||
|
- uses: security-extended
|
||||||
|
- uses: security-and-quality
|
||||||
|
query-filters:
|
||||||
|
- include:
|
||||||
|
tags: /cwe-020/
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
- **Complete Configuration**
|
#### Sharing configuration across multiple repositories
|
||||||
|
|
||||||
```yaml
|
|
||||||
- uses: github/codeql-action/init@v2
|
|
||||||
with:
|
|
||||||
languages: ${{ matrix.language }}
|
|
||||||
config: |
|
|
||||||
disable-default-queries: true
|
|
||||||
queries:
|
|
||||||
- uses: security-extended
|
|
||||||
- uses: security-and-quality
|
|
||||||
query-filters:
|
|
||||||
- include:
|
|
||||||
tags: /cwe-020/
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
- **Actions Variables**
|
|
||||||
|
|
||||||
You can use actions or environment variables to share configuration across multiple repositories and to modify configuration without needing to edit the workflow file.
|
You can use Actions or environment variables to share configuration across multiple repositories and to modify configuration without needing to edit the workflow file. In the following example, `vars.CODEQL_CONF` is an [Actions configuration variable](https://docs.github.com/en/actions/learn-github-actions/variables#defining-configuration-variables-for-multiple-workflows):
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: github/codeql-action/init@v2
|
- uses: github/codeql-action/init@v2
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
languages: ${{ matrix.language }}
|
||||||
config: ${{ vars.CODEQL_CONF }}
|
config: ${{ vars.CODEQL_CONF }}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
where `vars.CODEQL_CONF` references an [Actions configuration variable](https://docs.github.com/en/actions/learn-github-actions/variables#defining-configuration-variables-for-multiple-workflows).
|
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
|
|
|
||||||
3
lib/config-utils.js
generated
3
lib/config-utils.js
generated
|
|
@ -936,6 +936,9 @@ async function initConfig(languagesInput, queriesInput, packsInput, registriesIn
|
||||||
let config;
|
let config;
|
||||||
// if configInput is set, it takes precedence over configFile
|
// if configInput is set, it takes precedence over configFile
|
||||||
if (configInput) {
|
if (configInput) {
|
||||||
|
if (configFile) {
|
||||||
|
logger.warning(`Both a config file and config input were provided. Ignoring config file.`);
|
||||||
|
}
|
||||||
configFile = path.resolve(workspacePath, "user-config-from-action.yml");
|
configFile = path.resolve(workspacePath, "user-config-from-action.yml");
|
||||||
fs.writeFileSync(configFile, configInput);
|
fs.writeFileSync(configFile, configInput);
|
||||||
logger.debug(`Using config from action input: ${configFile}`);
|
logger.debug(`Using config from action input: ${configFile}`);
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
6
lib/config-utils.test.js
generated
6
lib/config-utils.test.js
generated
|
|
@ -495,9 +495,9 @@ function queriesToResolvedQueryForm(queries) {
|
||||||
t.true(config.queries["javascript"].custom[2].queries[0].endsWith(`${path.sep}foo`));
|
t.true(config.queries["javascript"].custom[2].queries[0].endsWith(`${path.sep}foo`));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
(0, ava_1.default)("Queries can be specified in configuration, same as file", async (t) => {
|
(0, ava_1.default)("Queries can be specified using config input", async (t) => {
|
||||||
return await util.withTmpDir(async (tmpDir) => {
|
return await util.withTmpDir(async (tmpDir) => {
|
||||||
const inputFileContents = `
|
const configInput = `
|
||||||
name: my config
|
name: my config
|
||||||
queries:
|
queries:
|
||||||
- uses: ./foo
|
- uses: ./foo
|
||||||
|
|
@ -520,7 +520,7 @@ function queriesToResolvedQueryForm(queries) {
|
||||||
});
|
});
|
||||||
// Only JS, python packs will be ignored
|
// Only JS, python packs will be ignored
|
||||||
const languages = "javascript";
|
const languages = "javascript";
|
||||||
const config = await configUtils.initConfig(languages, undefined, undefined, undefined, undefined, undefined, inputFileContents, false, false, "", "", { owner: "github", repo: "example " }, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, testing_utils_1.createFeatures)([]), (0, logging_1.getRunnerLogger)(true));
|
const config = await configUtils.initConfig(languages, undefined, undefined, undefined, undefined, undefined, configInput, false, false, "", "", { owner: "github", repo: "example " }, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, testing_utils_1.createFeatures)([]), (0, logging_1.getRunnerLogger)(true));
|
||||||
// Check resolveQueries was called correctly
|
// Check resolveQueries was called correctly
|
||||||
// It'll be called once for the default queries
|
// It'll be called once for the default queries
|
||||||
// and once for `./foo` from the config file.
|
// and once for `./foo` from the config file.
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -925,9 +925,9 @@ test("Queries in workflow file can be added to the set of queries without overri
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Queries can be specified in configuration, same as file", async (t) => {
|
test("Queries can be specified using config input", async (t) => {
|
||||||
return await util.withTmpDir(async (tmpDir) => {
|
return await util.withTmpDir(async (tmpDir) => {
|
||||||
const inputFileContents = `
|
const configInput = `
|
||||||
name: my config
|
name: my config
|
||||||
queries:
|
queries:
|
||||||
- uses: ./foo
|
- uses: ./foo
|
||||||
|
|
@ -967,7 +967,7 @@ test("Queries can be specified in configuration, same as file", async (t) => {
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
inputFileContents,
|
configInput,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
"",
|
"",
|
||||||
|
|
|
||||||
|
|
@ -1708,6 +1708,11 @@ export async function initConfig(
|
||||||
|
|
||||||
// if configInput is set, it takes precedence over configFile
|
// if configInput is set, it takes precedence over configFile
|
||||||
if (configInput) {
|
if (configInput) {
|
||||||
|
if (configFile) {
|
||||||
|
logger.warning(
|
||||||
|
`Both a config file and config input were provided. Ignoring config file.`
|
||||||
|
);
|
||||||
|
}
|
||||||
configFile = path.resolve(workspacePath, "user-config-from-action.yml");
|
configFile = path.resolve(workspacePath, "user-config-from-action.yml");
|
||||||
fs.writeFileSync(configFile, configInput);
|
fs.writeFileSync(configFile, configInput);
|
||||||
logger.debug(`Using config from action input: ${configFile}`);
|
logger.debug(`Using config from action input: ${configFile}`);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue