Skip to content

Commit 7bac6a0

Browse files
committed
Initial commit
0 parents  commit 7bac6a0

File tree

75 files changed

+32639
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+32639
-0
lines changed

.codeqlmanifest.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"provide": [
3+
"ql/src/qlpack.yml",
4+
"ql/consistency-queries/qlpack.yml",
5+
"ql/test/qlpack.yml",
6+
"ql/examples/qlpack.yml",
7+
"upgrades/qlpack.yml",
8+
"extractor-pack/codeql-extractor.yml"
9+
]
10+
}

.devcontainer/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.162.0/containers/rust/.devcontainer/base.Dockerfile
2+
3+
FROM mcr.microsoft.com/vscode/devcontainers/rust:0-1
4+
5+
RUN apt-key --keyring /usr/share/keyrings/githubcli-archive-keyring.gpg adv \
6+
--keyserver keyserver.ubuntu.com --recv-key C99B11DEB97541F0 && \
7+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages $(lsb_release -cs) main" \
8+
| tee /etc/apt/sources.list.d/github-cli2.list > /dev/null
9+
10+
11+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
12+
&& apt-get -y install --no-install-recommends gh
13+
14+
COPY post_create.sh /bin/post_create.sh
15+
COPY post_attach.sh /bin/post_attach.sh

.devcontainer/devcontainer.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.162.0/containers/rust
3+
{
4+
"name": "Rust",
5+
"build": {
6+
"dockerfile": "Dockerfile"
7+
},
8+
"runArgs": [
9+
"--cap-add=SYS_PTRACE",
10+
"--security-opt",
11+
"seccomp=unconfined"
12+
],
13+
// Set *default* container specific settings.json values on container create.
14+
"settings": {
15+
"terminal.integrated.shell.linux": "/bin/bash",
16+
"lldb.executable": "/usr/bin/lldb",
17+
// VS Code don't watch files under ./target
18+
"files.watcherExclude": {
19+
"**/target/**": true
20+
}
21+
},
22+
// Add the IDs of extensions you want installed when the container is created.
23+
"extensions": [
24+
"rust-lang.rust",
25+
"bungcip.better-toml",
26+
"vadimcn.vscode-lldb",
27+
"mutantdino.resourcemonitor",
28+
"ms-azuretools.vscode-docker",
29+
"github.vscode-codeql"
30+
],
31+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
32+
// "forwardPorts": [],
33+
// Use 'postCreateCommand' to run commands after the container is created.
34+
// "postCreateCommand": "rustc --version",
35+
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
36+
"remoteUser": "vscode",
37+
"postCreateCommand": [ "/bin/post_create.sh" ],
38+
"postAttachCommand": [ "flock", "-E", "0", "-n", "/var/lock/post_attach.lock", "/bin/post_attach.sh" ]
39+
}

.devcontainer/post_attach.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#! /bin/bash
2+
set -xe
3+
4+
echo "Check installed CodeQL version"
5+
CURRENT_CODEQL_BIN=$(readlink -e /usr/local/bin/codeql || echo "")
6+
LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | sort --version-sort | tail -1)
7+
8+
BASE_DIR=/home/vscode/codeql-binaries
9+
mkdir -p "${BASE_DIR}"
10+
LATEST_CODEQL_DIR="${BASE_DIR}/codeql-${LATEST}"
11+
LATEST_CODEQL_BIN="${LATEST_CODEQL_DIR}/codeql/codeql"
12+
13+
if [ "${CURRENT_CODEQL_BIN}" != "${LATEST_CODEQL_BIN}" ]; then
14+
echo "Installing CodeQL ${LATEST}"
15+
TMPDIR=$(mktemp -d -p "$(dirname ${LATEST_CODEQL_DIR})")
16+
gh release download --repo https://github.com/github/codeql-cli-binaries --pattern codeql-linux64.zip -D "${TMPDIR}" "$LATEST"
17+
unzip -oq "${TMPDIR}/codeql-linux64.zip" -d "${TMPDIR}"
18+
rm -f "${TMPDIR}/codeql-linux64.zip"
19+
mv "${TMPDIR}" "${LATEST_CODEQL_DIR}"
20+
test -x "${LATEST_CODEQL_BIN}" && sudo ln -sf "${LATEST_CODEQL_BIN}" /usr/local/bin/codeql
21+
if [[ "${CURRENT_CODEQL_BIN}" =~ .*/codeql/codeql ]]; then
22+
rm -rf "$(dirname $(dirname ${CURRENT_CODEQL_BIN}))"
23+
fi
24+
fi
25+
26+
echo "Build the Ruby extractor"
27+
28+
# clone the git dependencies using "git clone" because cargo's builtin git support is rather slow
29+
REPO_DIR="${CARGO_HOME:-/home/vscode/.cargo}/git/db"
30+
REPO_DIR_ERB="${REPO_DIR}/tree-sitter-embedded-template-4c796e3340c233b6"
31+
REPO_DIR_RUBY="${REPO_DIR}/tree-sitter-ruby-666a40ce046f8e7a"
32+
33+
mkdir -p "${REPO_DIR}"
34+
test -e "${REPO_DIR_RUBY}" || git clone -q --bare https://github.com/tree-sitter/tree-sitter-ql.git "${REPO_DIR_RUBY}"
35+
36+
./create-extractor-pack.sh

.devcontainer/post_create.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#! /bin/bash
2+
3+
mkdir -p /home/vscode/.config/codeql
4+
echo '--search-path /workspaces/codeql-ruby' >> /home/vscode/.config/codeql/config

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cargo.lock -diff -whitespace

.github/workflows/build.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Rust
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
build:
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
os: [ubuntu-latest, macos-latest, windows-latest]
18+
19+
runs-on: ${{ matrix.os }}
20+
21+
steps:
22+
- uses: actions/checkout@v2
23+
- name: Install GNU tar
24+
if: runner.os == 'macOS'
25+
run: |
26+
brew install gnu-tar
27+
echo "/usr/local/opt/gnu-tar/libexec/gnubin" >> $GITHUB_PATH
28+
- uses: actions/cache@v2
29+
with:
30+
path: |
31+
~/.cargo/registry
32+
~/.cargo/git
33+
target
34+
key: ${{ runner.os }}-rust-cargo-${{ hashFiles('**/Cargo.lock') }}
35+
- name: Check formatting
36+
run: cargo fmt --all -- --check
37+
- name: Build
38+
run: cargo build --verbose
39+
- name: Run tests
40+
run: cargo test --verbose
41+
- name: Release build
42+
run: cargo build --release
43+
- name: Generate dbscheme
44+
if: ${{ matrix.os == 'ubuntu-latest' }}
45+
run: target/release/ql-generator
46+
- uses: actions/upload-artifact@v2
47+
if: ${{ matrix.os == 'ubuntu-latest' }}
48+
with:
49+
name: ql.dbscheme
50+
path: ql/src/ql.dbscheme
51+
- uses: actions/upload-artifact@v2
52+
if: ${{ matrix.os == 'ubuntu-latest' }}
53+
with:
54+
name: TreeSitter.qll
55+
path: ql/src/codeql_ql/ast/internal/TreeSitter.qll
56+
- uses: actions/upload-artifact@v2
57+
with:
58+
name: extractor-${{ matrix.os }}
59+
path: |
60+
target/release/ql-extractor
61+
target/release/ql-extractor.exe
62+
retention-days: 1
63+
package:
64+
runs-on: ubuntu-latest
65+
needs: build
66+
steps:
67+
- uses: actions/checkout@v2
68+
- uses: actions/download-artifact@v2
69+
with:
70+
name: ql.dbscheme
71+
path: ruby
72+
- uses: actions/download-artifact@v2
73+
with:
74+
name: extractor-ubuntu-latest
75+
path: linux64
76+
- uses: actions/download-artifact@v2
77+
with:
78+
name: extractor-windows-latest
79+
path: win64
80+
- uses: actions/download-artifact@v2
81+
with:
82+
name: extractor-macos-latest
83+
path: osx64
84+
- run: |
85+
mkdir -p ruby
86+
cp -r codeql-extractor.yml tools ql/src/ql.dbscheme.stats ruby/
87+
mkdir -p ruby/tools/{linux64,osx64,win64}
88+
cp linux64/ql-extractor ruby/tools/linux64/extractor
89+
cp osx64/ql-extractor ruby/tools/osx64/extractor
90+
cp win64/ql-extractor.exe ruby/tools/win64/extractor.exe
91+
chmod +x ruby/tools/{linux64,osx64}/extractor
92+
zip -rq codeql-ruby.zip ruby
93+
- uses: actions/upload-artifact@v2
94+
with:
95+
name: codeql-ruby-pack
96+
path: codeql-ruby.zip
97+
retention-days: 1

.github/workflows/dataset_measure.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Collect database stats
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- ql/src/ql.dbscheme
8+
pull_request:
9+
branches: [main]
10+
paths:
11+
- ql/src/ql.dbscheme
12+
workflow_dispatch:
13+
14+
jobs:
15+
measure:
16+
env:
17+
CODEQL_THREADS: 4 # TODO: remove this once it's set by the CLI
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
repo: [rails/rails, discourse/discourse, spree/spree]
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v2
25+
26+
- name: Fetch CodeQL
27+
run: |
28+
LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | sort --version-sort | tail -1)
29+
gh release download --repo https://github.com/github/codeql-cli-binaries --pattern codeql-linux64.zip "$LATEST"
30+
unzip -q codeql-linux64.zip
31+
env:
32+
GITHUB_TOKEN: ${{ github.token }}
33+
- uses: actions/cache@v2
34+
with:
35+
path: |
36+
~/.cargo/registry
37+
~/.cargo/git
38+
target
39+
key: ${{ runner.os }}-qltest-cargo-${{ hashFiles('**/Cargo.lock') }}
40+
- name: Build Extractor
41+
run: env "PATH=$PATH:${{ github.workspace }}/codeql" ./create-extractor-pack.sh
42+
43+
- name: Checkout ${{ matrix.repo }}
44+
uses: actions/checkout@v2
45+
with:
46+
repository: ${{ matrix.repo }}
47+
path: ${{ github.workspace }}/repo
48+
- name: Create database
49+
run: |
50+
codeql/codeql database create \
51+
--search-path "${{ github.workspace }}" \
52+
--threads 4 \
53+
--language ruby --source-root "${{ github.workspace }}/repo" \
54+
"${{ runner.temp }}/database"
55+
- name: Measure database
56+
run: |
57+
mkdir -p "stats/${{ matrix.repo }}"
58+
codeql/codeql dataset measure --threads 4 --output "stats/${{ matrix.repo }}/stats.xml" "${{ runner.temp }}/database/db-ruby"
59+
- uses: actions/upload-artifact@v2
60+
with:
61+
name: measurements
62+
path: stats
63+
retention-days: 1
64+
65+
merge:
66+
runs-on: ubuntu-latest
67+
needs: measure
68+
steps:
69+
- uses: actions/checkout@v2
70+
- uses: actions/download-artifact@v2
71+
with:
72+
name: measurements
73+
path: stats
74+
- run: |
75+
python -m pip install --user lxml
76+
find stats -name 'stats.xml' | sort | xargs python scripts/merge_stats.py --output ql/src/ql.dbscheme.stats --normalise tokeninfo
77+
- uses: actions/upload-artifact@v2
78+
with:
79+
name: ql.dbscheme.stats
80+
path: ql/src/ql.dbscheme.stats

.github/workflows/qltest.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Run QL Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
qltest:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Fetch CodeQL
18+
run: |
19+
LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | sort --version-sort | tail -1)
20+
gh release download --repo https://github.com/github/codeql-cli-binaries --pattern codeql-linux64.zip "$LATEST"
21+
unzip -q codeql-linux64.zip
22+
env:
23+
GITHUB_TOKEN: ${{ github.token }}
24+
- uses: actions/cache@v2
25+
with:
26+
path: |
27+
~/.cargo/registry
28+
~/.cargo/git
29+
target
30+
key: ${{ runner.os }}-qltest-cargo-${{ hashFiles('**/Cargo.lock') }}
31+
- name: Build Extractor
32+
run: env "PATH=$PATH:${{ github.workspace }}/codeql" ./create-extractor-pack.sh
33+
- name: Run QL tests
34+
run: codeql/codeql test run --check-databases --check-unused-labels --check-repeated-labels --check-redefined-labels --check-use-before-definition --search-path "${{ github.workspace }}" --consistency-queries ql/consistency-queries ql/test
35+
- name: Check QL formatting
36+
run: find ql "(" -name "*.ql" -or -name "*.qll" ")" -print0 | xargs -0 codeql/codeql query format --check-only
37+
- name: Check QL compilation
38+
run: codeql/codeql query compile --check-only --threads=4 --warnings=error --search-path "${{ github.workspace }}" "ql/src" "ql/examples"

.github/workflows/sync_files.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Check synchronized files
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
sync:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
with:
15+
submodules: true
16+
- name: Check synchronized files
17+
run: scripts/sync-identical-files.py

0 commit comments

Comments
 (0)