Skip to content

Commit a044f41

Browse files
authored
Merge pull request #188 from github/aibaars/qlpack
Build Ruby bundle
2 parents aea0c6f + 73aae5d commit a044f41

3 files changed

Lines changed: 73 additions & 20 deletions

File tree

.github/workflows/build.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,41 @@ jobs:
6060
target/release/ruby-extractor
6161
target/release/ruby-extractor.exe
6262
retention-days: 1
63+
compile-queries:
64+
runs-on: ubuntu-latest
65+
env:
66+
CODEQL_THREADS: 4 # TODO: remove this once it's set by the CLI
67+
steps:
68+
- uses: actions/checkout@v2
69+
- name: Fetch CodeQL
70+
run: |
71+
LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | sort --version-sort | tail -1)
72+
gh release download --repo https://github.com/github/codeql-cli-binaries --pattern codeql-linux64.zip "$LATEST"
73+
unzip -q codeql-linux64.zip
74+
env:
75+
GITHUB_TOKEN: ${{ github.token }}
76+
- name: Build Query Pack
77+
run: |
78+
codeql/codeql pack create ql/src --output target/packs
79+
codeql/codeql pack create upgrades --output target/packs
80+
cp -r ql/src/codeql-suites target/packs/github_codeql-ruby_*/
81+
- name: Compile with previous CodeQL versions
82+
run: |
83+
for version in $(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | sort --version-sort | tail -3 | head -2); do
84+
rm -f codeql-linux64.zip
85+
gh release download --repo https://github.com/github/codeql-cli-binaries --pattern codeql-linux64.zip "$version"
86+
rm -rf codeql; unzip -q codeql-linux64.zip
87+
codeql/codeql query compile target/packs/*
88+
done
89+
env:
90+
GITHUB_TOKEN: ${{ github.token }}
91+
- uses: actions/upload-artifact@v2
92+
with:
93+
name: codeql-ruby-queries
94+
path: |
95+
target/packs/*
96+
retention-days: 1
97+
6398
package:
6499
runs-on: ubuntu-latest
65100
needs: build
@@ -95,3 +130,20 @@ jobs:
95130
name: codeql-ruby-pack
96131
path: codeql-ruby.zip
97132
retention-days: 1
133+
- uses: actions/download-artifact@v2
134+
with:
135+
name: codeql-ruby-queries
136+
path: qlpacks
137+
- run: |
138+
echo '{
139+
"provide": [
140+
"ruby/codeql-extractor.yml",
141+
"qlpacks/*/qlpack.yml"
142+
]
143+
}' > .codeqlmanifest.json
144+
zip -rq codeql-ruby-bundle.zip .codeqlmanifest.json ruby qlpacks
145+
- uses: actions/upload-artifact@v2
146+
with:
147+
name: codeql-ruby-bundle
148+
path: codeql-ruby-bundle.zip
149+
retention-days: 1

extractor/src/main.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,24 @@ impl TrapCompression {
5454
* "If the number is positive, it indicates the number of threads that should
5555
* be used. If the number is negative or zero, it should be added to the number
5656
* of cores available on the machine to determine how many threads to use
57-
* (minimum of 1). If unspecified, should be considered as set to 1."
57+
* (minimum of 1). If unspecified, should be considered as set to -1."
5858
*/
5959
fn num_codeql_threads() -> usize {
60-
match std::env::var("CODEQL_THREADS") {
61-
// Use 1 thread if the environment variable isn't set.
62-
Err(_) => 1,
63-
64-
Ok(num) => match num.parse::<i32>() {
65-
Ok(num) if num <= 0 => {
66-
let reduction = -num as usize;
67-
num_cpus::get() - reduction
68-
}
69-
Ok(num) => num as usize,
70-
71-
Err(_) => {
72-
tracing::error!(
73-
"Unable to parse CODEQL_THREADS value '{}'; defaulting to 1 thread.",
74-
&num
75-
);
76-
1
77-
}
78-
},
60+
let threads_str = std::env::var("CODEQL_THREADS").unwrap_or("-1".to_owned());
61+
match threads_str.parse::<i32>() {
62+
Ok(num) if num <= 0 => {
63+
let reduction = -num as usize;
64+
std::cmp::max(1, num_cpus::get() - reduction)
65+
}
66+
Ok(num) => num as usize,
67+
68+
Err(_) => {
69+
tracing::error!(
70+
"Unable to parse CODEQL_THREADS value '{}'; defaulting to 1 thread.",
71+
&threads_str
72+
);
73+
1
74+
}
7975
}
8076
}
8177

ql/src/codeql-suites/ruby-code-scanning.qls

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
- qlpack: codeql-ruby
33
- apply: code-scanning-selectors.yml
44
from: codeql-suite-helpers
5+
# TODO: remove the selectors below
6+
- include:
7+
id:
8+
- rb/use-detect
9+
- rb/overly-permissive-file

0 commit comments

Comments
 (0)