Skip to content

Commit 42235cc

Browse files
authored
Allow the codeql-action to be run locally (#117)
* Allow the codeql-action to be run locally This change allows the codeql-action to be run locally through [act](https://github.com/nektos/act). In order to run the action locally, you need to do two things: 1. Add the `CODEQL_LOCAL_RUN: true` environment variable. The only way I could figure out how to do this was to add it directly in the workflow file in an `env` block. It _should_ be possible to add it through a `.env` file and pass it to `act`, but I couldn't get it working. 2. Run this command `act -j codeql -s GITHUB_TOKEN=<MY_PAT>` Setting the `CODEQL_LOCAL_RUN` env var will fill in missing env vars that the action needs, but isn't set by `act`. It will also avoid making api calls to github that would fail locally. This is a refactoring discussed in https://github.com/github/dsp-codeql/issues/36
1 parent 631929a commit 42235cc

25 files changed

+195
-20
lines changed

CONTRIBUTING.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,25 @@ This project also includes configuration to run tests from VSCode (with support
2626

2727
To see the effect of your changes and to test them, push your changes in a branch and then look at the [Actions output](https://github.com/github/codeql-action/actions) for that branch. You can also exercise the code locally by running the automated tests.
2828

29+
### Running the action locally
30+
31+
It is possible to run this action locally via [act](https://github.com/nektos/act) via the following steps:
32+
33+
1. Create a GitHub [Personal Access Token](https://github.com/settings/tokens) (PAT).
34+
1. Install [act](https://github.com/nektos/act) v0.2.10 or greater.
35+
1. Add a `.env` file in the root of the project you are running:
36+
37+
```bash
38+
CODEQL_LOCAL_RUN=true
39+
40+
# Optional, for better logging
41+
GITHUB_JOB=<ANY_JOB_NAME>
42+
```
43+
44+
1. Run `act -j codeql -s GITHUB_TOKEN=<PAT>`
45+
46+
Running locally will generate the CodeQL database and run all the queries, but it will avoid uploading and reporting results to GitHub. Note that this must be done on a repository that _consumes_ this action, not this repository. The use case is to debug failures of this action on specific repositories.
47+
2948
### Integration tests
3049

3150
As well as the unit tests (see _Common tasks_ above), there are integration tests, defined in `.github/workflows/integration-testing.yml`. These are run by a CI check. Depending on the change you’re making, you may want to add a test to this file or extend an existing one.

lib/api-client.js

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/api-client.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/autobuild.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/autobuild.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)