4.4.2 introduces a breaking change that the variable in a catch clause
is now `unknown` type. So, we need to cast the `e`, `err`, or `error`
variables to type `Error`.
This is a functionality that never worked perfectly and hasn't been
used for a while.
This allows developers to run the action on their local machine, but
the run was always flaky and never 100% mirrored what was happening on
the actions runner.
This PR ensures environment variables are set before any invocation of
the CLI. Here is a list of vars that are set:
https://github.com/github/codeql-coreql-team/issues/1124#issuecomment-852463521
This ensures the CLI knows the features and versions of the containing
actions/runner.
Additionally:
- Fix the user agent so that it more closely aligns with user agent
spec
- Refactor environment variable initialization so that it all happens in
one place and call.
- Move Mode, getRequiredEnvParam, setMode, getMode out of actions-util
and into util. actions-util is meant for utils only called by the
action, not the runner.
The `prepareLocalRunEnvironment()` method is most likely deprecated and
should be removed. I originally added it because I had a way of working
where I would run the action from my local machine to test out changes,
but this was always a little flaky. So, I no longer use this way of
working. I will probably remove it soon.
This commit changes the way the action determines if running in action
or runner mode. There is now an environment variable that is set at the
beginning of the process and elsewhere in the process, we can check to
see if the variable is set.
* 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