You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add functionality to enable use with the VS Code CodeQL extension (#20)
* Add local version pinning
This enables pinning a CodeQL version per working directory.
* Add install stub command
This installs a stub allowing the GH CodeQL extension to be used by the
VS Code extension.
* Add version override through environment variable
The environment variable `GH_CODEQL_VERSION` can be used to override the
global and local version specification. This is needed when we want to
override the CodeQL version used by the VS Code extension, because the
working directory used by the extension is `/` so we can't find any
local version specification part of the project using CodeQL.
With this override we can alias `code` to check for `.codeql-version` in
PWD or the path passed as an argument and set `GH_CODEQL_VERSION`.
* Update README with new commands
* Add description of local version pinning
* Add description of the `install-stub` command.
* Address incorrect indentation
* Add test for `install-stub` command
* Ensure the latest version is avaible for the test
* Add test for version override
* Restore the channel after the nightly version test
* Address spelling mistake in comment
* Remove superfluous download step
The selected version will be downloaded if not available.
* Address spelling mistake in comment
* Update install-stub command's descriptive comment
Explain what the command does.
* Address `jq` parser error
The version override causes a CodeQL CLI download that outputs cURL
outpuut which confuses the `jq` parser.
By running the command twice we remediate the issue.
* Add test for local pinned version modification
This test validates if we properly handle a local pinned version
modification without using the `set-local-version` command.
* Address pinning persistence influencing other tests
After each test using local pinning we unpin the version.
* Update error message when installing stub
When a directory doesn't exists, the user is asked to provide a
different directory to install a stub.
* Add permission check to install-stub command
Check if we can write to the provided/default directory and return an error message if we
can't.
* Disable per directory pinning by default
The command 'set-local-version' will show a warning when per directory
pinning is disabled (the default) and explicitly asks the user to enable
it.
* Update how we support local version
- Add explicit commands to enable/disable local version support.
- Show a warning when a local version is specified, but local version
support is disabled.
- Show a warning when enabling local version support.
- Show an error when a local version is set while local version support
is disabled.
* Address spelling mistake in test name
* Improve error message 'local-version' command
gh codeql <anything else># pass arguments to CodeQL CLI
25
28
26
29
Current channel: release.
@@ -39,12 +42,16 @@ You can list the installed versions from the current channel with `gh codeql lis
39
42
40
43
### Versions
41
44
42
-
The `gh codeql` command always works relative to a pinned version on the current channel. You can manually specify the pinned version using `gh codeql set-version`.
45
+
The `gh codeql` command always works relative to a pinned version on the current channel. You can manually specify the pinned version using `gh codeql set-version`. To pin a version to a working directory you can use the command `gh codeql set-local-version` and `gh codeql` will always use that version when running in that working directory. To remove a pin from a working directory run `gh codeql unset-local-version` in that working directory.
43
46
44
47
You can download additional versions without pinning them (perhaps to prepare for local comparisons) using `gh codeql download`.
45
48
46
49
To upgrade, run `gh codeql set-version latest`, which will pin you to the current latest version.
47
50
51
+
### CodeQL stub
52
+
53
+
If you want to use the GitHub CLI managed CodeQL version directly in a terminal or use it with the Visual Studio Code CodeQL extension then you can install a stub using the command `gh codeql install-stub` that will install a Bash script called `codeql` that invokes the GitHub CLI. The default install directory is `/usr/local/bin/`, but you can change this by passing an existing directory.
54
+
48
55
## Development
49
56
50
57
This extension is newly released and under active development. Contributions are very welcome, for more information about how you can contribute, please check our [CONTRIBUTING.md](CONTRIBUTING.md) file. For a list of outstanding issues, please take a look at [our backlog](https://github.com/github/gh-codeql/issues). If you encounter a problem that does not already have an open issue associated with it, please open one there.
gh codeql install-stub [dir] # install an executable script named 'codeql' that invokes 'gh codeql' with the passed arguments (default: /usr/local/bin/)
31
66
gh codeql <anything else> # pass arguments to CodeQL CLI
32
67
33
68
Current channel: ${channel:-not specified}.
@@ -131,7 +166,7 @@ function download() {
131
166
rm -rf "$tempdir"
132
167
}
133
168
134
-
functionset_version() {
169
+
functionvalidate_version() {
135
170
local version="$1"
136
171
if [ -z"$version" ];then
137
172
error "Version must be specified. Use 'latest' to automatically determine the latest version."
@@ -156,10 +191,49 @@ function set_version() {
156
191
error "Unknown version: '$1'."
157
192
fi
158
193
fi
194
+
echo"$version"
195
+
}
196
+
197
+
functionset_version() {
198
+
local version=$(validate_version "$1")
199
+
if [ -z"$version" ];then
200
+
exit 1
201
+
fi
159
202
download "$version"
160
203
gh config set extensions.codeql.version "$version"2> /dev/null # Ignore a warning about unrecognized custom keys
161
204
}
162
205
206
+
functionset_local_version() {
207
+
local version=$(validate_version "$1")
208
+
download "$version"
209
+
echo"$version"> .codeql-version
210
+
}
211
+
212
+
functioninstall_stub() {
213
+
local bindir="$1"
214
+
if [ -z"$bindir" ];then
215
+
bindir="/usr/local/bin"
216
+
fi
217
+
218
+
if [ !-e"$bindir" ];then
219
+
error "The directory $bindir doesn't exist, please provide a different directory like 'gh codeql install-stub [dir]' to install a stub."
220
+
fi
221
+
222
+
if [ -w"$bindir" ];then
223
+
224
+
cat << "_codeql_stub" > "$bindir/codeql"
225
+
#!/usr/bin/env bash
226
+
227
+
set -e
228
+
exec -a codeql gh codeql "$@"
229
+
_codeql_stub
230
+
231
+
chmod +x "$bindir/codeql"
232
+
else
233
+
error "Missing write permission on $bindir. Please provide a directory with write permissions to install a stub."
234
+
fi
235
+
}
236
+
163
237
# Handle the download command.
164
238
if [ "$1"="download" ];then
165
239
download "$2"
@@ -173,6 +247,31 @@ if [ "$1" = "set-version" ]; then
173
247
exec"$rootdir/dist/$channel/$version/codeql" version
174
248
fi
175
249
250
+
# Handle the set-local-version command
251
+
if [ "$1"="set-local-version" ];then
252
+
if [ "$local_version"="true" ];then
253
+
set_local_version "$2"
254
+
version="$(<.codeql-version)"||:# Supress an error and return empty if the file doesn't exist
255
+
exec"$rootdir/dist/$channel/$version/codeql" version
256
+
else
257
+
error "$(cat <<_message
258
+
Local version support is disabled by default to remove the opportunity from untrusted git repositories to
259
+
abuse older CodeQL CLIs. Enable local version support with the command 'gh codeql local-version on'.
0 commit comments