codeql/.github/workflows/ruby-build.yml

223 строки
7.6 KiB
YAML
Исходник Обычный вид История

2021-10-14 14:32:50 +03:00
name: "Ruby: Build"
2020-10-27 16:25:22 +03:00
on:
push:
# No path requirement on branch pushes, so the cache is more effective.
2021-10-14 14:32:50 +03:00
branches:
- main
2021-11-03 13:52:29 +03:00
- "rc/*"
2020-10-27 16:25:22 +03:00
pull_request:
2021-10-14 14:32:50 +03:00
paths:
2021-11-03 13:52:29 +03:00
- "ruby/**"
- .github/workflows/ruby-build.yml
2022-08-02 17:33:21 +03:00
- .github/actions/fetch-codeql/action.yml
- codeql-workspace.yml
2021-10-14 14:32:50 +03:00
branches:
- main
2021-11-03 13:52:29 +03:00
- "rc/*"
2021-05-26 16:29:37 +03:00
workflow_dispatch:
inputs:
tag:
description: "Version tag to create"
required: false
2020-10-27 16:25:22 +03:00
env:
CARGO_TERM_COLOR: always
2021-10-14 14:32:50 +03:00
defaults:
run:
working-directory: ruby
2020-10-27 16:25:22 +03:00
jobs:
build:
strategy:
fail-fast: false
2020-10-27 17:50:30 +03:00
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
2020-10-27 16:25:22 +03:00
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
2020-12-03 18:40:37 +03:00
- name: Install GNU tar
if: runner.os == 'macOS'
run: |
brew install gnu-tar
echo "/usr/local/opt/gnu-tar/libexec/gnubin" >> $GITHUB_PATH
- uses: actions/cache@v3
2020-10-27 21:11:05 +03:00
with:
path: |
~/.cargo/registry
~/.cargo/git
2021-10-14 14:32:50 +03:00
ruby/target
2022-02-03 21:41:29 +03:00
key: ${{ runner.os }}-ruby-rust-cargo-${{ hashFiles('ruby/rust-toolchain.toml', 'ruby/**/Cargo.lock') }}
- name: Check formatting
run: cargo fmt --all -- --check
2020-10-27 17:50:30 +03:00
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- name: Release build
run: cargo build --release
2020-10-27 17:50:30 +03:00
- name: Generate dbscheme
if: ${{ matrix.os == 'ubuntu-latest' }}
2021-08-11 17:17:09 +03:00
run: target/release/ruby-generator --dbscheme ql/lib/ruby.dbscheme --library ql/lib/codeql/ruby/ast/internal/TreeSitter.qll
- uses: actions/upload-artifact@v3
2020-10-27 17:50:30 +03:00
if: ${{ matrix.os == 'ubuntu-latest' }}
with:
name: ruby.dbscheme
2021-10-14 14:32:50 +03:00
path: ruby/ql/lib/ruby.dbscheme
- uses: actions/upload-artifact@v3
if: ${{ matrix.os == 'ubuntu-latest' }}
with:
name: TreeSitter.qll
2021-10-14 14:32:50 +03:00
path: ruby/ql/lib/codeql/ruby/ast/internal/TreeSitter.qll
- uses: actions/upload-artifact@v3
2020-10-27 17:50:30 +03:00
with:
name: extractor-${{ matrix.os }}
path: |
2021-10-14 14:32:50 +03:00
ruby/target/release/ruby-autobuilder
ruby/target/release/ruby-autobuilder.exe
ruby/target/release/ruby-extractor
ruby/target/release/ruby-extractor.exe
2020-10-27 17:50:30 +03:00
retention-days: 1
2021-05-24 13:50:14 +03:00
compile-queries:
runs-on: ubuntu-latest
env:
CODEQL_THREADS: 4 # TODO: remove this once it's set by the CLI
steps:
- uses: actions/checkout@v3
2021-05-24 13:50:14 +03:00
- name: Fetch CodeQL
2022-08-01 13:38:59 +03:00
uses: ./.github/actions/fetch-codeql
- name: Cache compilation cache
id: query-cache
uses: ./.github/actions/cache-query-compilation
with:
key: ruby-build
2021-05-24 13:50:14 +03:00
- name: Build Query Pack
run: |
codeql pack create ../shared/ssa --output target/packs --compilation-cache "${{ steps.query-cache.outputs.cache-dir }}"
codeql pack create ../misc/suite-helpers --output target/packs --compilation-cache "${{ steps.query-cache.outputs.cache-dir }}"
codeql pack create ../shared/regex --output target/packs --compilation-cache "${{ steps.query-cache.outputs.cache-dir }}"
codeql pack create ql/lib --output target/packs --compilation-cache "${{ steps.query-cache.outputs.cache-dir }}"
codeql pack create ql/src --output target/packs --compilation-cache "${{ steps.query-cache.outputs.cache-dir }}"
PACK_FOLDER=$(readlink -f target/packs/codeql/ruby-queries/*)
2022-08-01 13:38:59 +03:00
codeql generate query-help --format=sarifv2.1.0 --output="${PACK_FOLDER}/rules.sarif" ql/src
2021-06-24 21:48:14 +03:00
(cd ql/src; find queries \( -name '*.qhelp' -o -name '*.rb' -o -name '*.erb' \) -exec bash -c 'mkdir -p "'"${PACK_FOLDER}"'/$(dirname "{}")"' \; -exec cp "{}" "${PACK_FOLDER}/{}" \;)
- uses: actions/upload-artifact@v3
2021-05-24 13:50:14 +03:00
with:
name: codeql-ruby-queries
path: |
2021-10-14 14:32:50 +03:00
ruby/target/packs/*
2021-05-24 13:50:14 +03:00
retention-days: 1
2020-10-27 17:50:30 +03:00
package:
runs-on: ubuntu-latest
needs: [build, compile-queries]
2020-10-27 17:50:30 +03:00
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
2020-10-27 17:50:30 +03:00
with:
name: ruby.dbscheme
2021-10-14 14:32:50 +03:00
path: ruby/ruby
- uses: actions/download-artifact@v3
2020-10-27 17:50:30 +03:00
with:
name: extractor-ubuntu-latest
2021-10-14 14:32:50 +03:00
path: ruby/linux64
- uses: actions/download-artifact@v3
2020-10-27 17:50:30 +03:00
with:
name: extractor-windows-latest
2021-10-14 14:32:50 +03:00
path: ruby/win64
- uses: actions/download-artifact@v3
2020-10-27 17:50:30 +03:00
with:
name: extractor-macos-latest
2021-10-14 14:32:50 +03:00
path: ruby/osx64
2020-10-27 17:50:30 +03:00
- run: |
mkdir -p ruby
cp -r codeql-extractor.yml tools ql/lib/ruby.dbscheme.stats ruby/
mkdir -p ruby/tools/{linux64,osx64,win64}
cp linux64/ruby-autobuilder ruby/tools/linux64/autobuilder
cp osx64/ruby-autobuilder ruby/tools/osx64/autobuilder
cp win64/ruby-autobuilder.exe ruby/tools/win64/autobuilder.exe
cp linux64/ruby-extractor ruby/tools/linux64/extractor
cp osx64/ruby-extractor ruby/tools/osx64/extractor
cp win64/ruby-extractor.exe ruby/tools/win64/extractor.exe
chmod +x ruby/tools/{linux64,osx64}/{autobuilder,extractor}
zip -rq codeql-ruby.zip ruby
- uses: actions/upload-artifact@v3
2020-10-27 17:50:30 +03:00
with:
name: codeql-ruby-pack
2021-10-14 14:32:50 +03:00
path: ruby/codeql-ruby.zip
2020-10-27 17:50:30 +03:00
retention-days: 1
- uses: actions/download-artifact@v3
2021-05-24 13:50:14 +03:00
with:
name: codeql-ruby-queries
2021-10-14 14:32:50 +03:00
path: ruby/qlpacks
2021-05-24 13:50:14 +03:00
- run: |
echo '{
"provide": [
"ruby/codeql-extractor.yml",
2021-06-24 17:09:45 +03:00
"qlpacks/*/*/*/qlpack.yml"
2021-05-24 13:50:14 +03:00
]
}' > .codeqlmanifest.json
zip -rq codeql-ruby-bundle.zip .codeqlmanifest.json ruby qlpacks
- uses: actions/upload-artifact@v3
2021-05-24 13:50:14 +03:00
with:
name: codeql-ruby-bundle
2021-10-14 14:32:50 +03:00
path: ruby/codeql-ruby-bundle.zip
2021-05-24 13:50:14 +03:00
retention-days: 1
2021-10-14 14:32:50 +03:00
2021-08-10 14:32:44 +03:00
test:
2021-10-14 14:32:50 +03:00
defaults:
run:
working-directory: ${{ github.workspace }}
2021-08-10 14:32:44 +03:00
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
needs: [package]
steps:
2022-08-01 14:36:05 +03:00
- uses: actions/checkout@v3
- name: Fetch CodeQL
uses: ./.github/actions/fetch-codeql
- uses: actions/checkout@v3
2021-08-10 14:32:44 +03:00
with:
repository: Shopify/example-ruby-app
ref: 67a0decc5eb550f3a9228eda53925c3afd40dfe9
2022-08-01 13:38:59 +03:00
2021-08-10 14:32:44 +03:00
- name: Download Ruby bundle
uses: actions/download-artifact@v3
2021-08-10 14:32:44 +03:00
with:
name: codeql-ruby-bundle
path: ${{ runner.temp }}
- name: Unzip Ruby bundle
shell: bash
run: unzip -q -d "${{ runner.temp }}/ruby-bundle" "${{ runner.temp }}/codeql-ruby-bundle.zip"
- name: Prepare test files
shell: bash
run: |
echo "import codeql.ruby.AST select count(File f)" > "test.ql"
2021-09-16 16:11:14 +03:00
echo "| 4 |" > "test.expected"
2021-08-10 14:32:44 +03:00
echo 'name: sample-tests
version: 0.0.0
dependencies:
2022-10-04 11:07:04 +03:00
codeql/ruby-all: "*"
2021-08-10 14:32:44 +03:00
extractor: ruby
tests: .
' > qlpack.yml
- name: Run QL test
shell: bash
run: |
2022-08-01 13:38:59 +03:00
codeql test run --search-path "${{ runner.temp }}/ruby-bundle" --additional-packs "${{ runner.temp }}/ruby-bundle" .
2021-08-10 14:32:44 +03:00
- name: Create database
shell: bash
run: |
2022-08-01 13:38:59 +03:00
codeql database create --search-path "${{ runner.temp }}/ruby-bundle" --language ruby --source-root . ../database
2021-08-10 14:32:44 +03:00
- name: Analyze database
shell: bash
run: |
2022-08-01 13:38:59 +03:00
codeql database analyze --search-path "${{ runner.temp }}/ruby-bundle" --format=sarifv2.1.0 --output=out.sarif ../database ruby-code-scanning.qls