|
| 1 | +name: "Ruby: Build" |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - 'ruby/**' |
| 7 | + branches: |
| 8 | + - main |
| 9 | + - 'rc/*' |
| 10 | + pull_request: |
| 11 | + paths: |
| 12 | + - 'ruby/**' |
| 13 | + branches: |
| 14 | + - main |
| 15 | + - 'rc/*' |
| 16 | + workflow_dispatch: |
| 17 | + inputs: |
| 18 | + tag: |
| 19 | + description: "Version tag to create" |
| 20 | + required: false |
| 21 | + |
| 22 | +env: |
| 23 | + CARGO_TERM_COLOR: always |
| 24 | + |
| 25 | +defaults: |
| 26 | + run: |
| 27 | + working-directory: ruby |
| 28 | + |
| 29 | +jobs: |
| 30 | + build: |
| 31 | + strategy: |
| 32 | + fail-fast: false |
| 33 | + matrix: |
| 34 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 35 | + |
| 36 | + runs-on: ${{ matrix.os }} |
| 37 | + |
| 38 | + steps: |
| 39 | + - uses: actions/checkout@v2 |
| 40 | + - name: Install GNU tar |
| 41 | + if: runner.os == 'macOS' |
| 42 | + run: | |
| 43 | + brew install gnu-tar |
| 44 | + echo "/usr/local/opt/gnu-tar/libexec/gnubin" >> $GITHUB_PATH |
| 45 | + - uses: actions/cache@v2 |
| 46 | + with: |
| 47 | + path: | |
| 48 | + ~/.cargo/registry |
| 49 | + ~/.cargo/git |
| 50 | + ruby/target |
| 51 | + key: ${{ runner.os }}-rust-cargo-${{ hashFiles('**/Cargo.lock') }} |
| 52 | + - name: Check formatting |
| 53 | + run: cargo fmt --all -- --check |
| 54 | + - name: Build |
| 55 | + run: cargo build --verbose |
| 56 | + - name: Run tests |
| 57 | + run: cargo test --verbose |
| 58 | + - name: Release build |
| 59 | + run: cargo build --release |
| 60 | + - name: Generate dbscheme |
| 61 | + if: ${{ matrix.os == 'ubuntu-latest' }} |
| 62 | + run: target/release/ruby-generator --dbscheme ql/lib/ruby.dbscheme --library ql/lib/codeql/ruby/ast/internal/TreeSitter.qll |
| 63 | + - uses: actions/upload-artifact@v2 |
| 64 | + if: ${{ matrix.os == 'ubuntu-latest' }} |
| 65 | + with: |
| 66 | + name: ruby.dbscheme |
| 67 | + path: ruby/ql/lib/ruby.dbscheme |
| 68 | + - uses: actions/upload-artifact@v2 |
| 69 | + if: ${{ matrix.os == 'ubuntu-latest' }} |
| 70 | + with: |
| 71 | + name: TreeSitter.qll |
| 72 | + path: ruby/ql/lib/codeql/ruby/ast/internal/TreeSitter.qll |
| 73 | + - uses: actions/upload-artifact@v2 |
| 74 | + with: |
| 75 | + name: extractor-${{ matrix.os }} |
| 76 | + path: | |
| 77 | + ruby/target/release/ruby-autobuilder |
| 78 | + ruby/target/release/ruby-autobuilder.exe |
| 79 | + ruby/target/release/ruby-extractor |
| 80 | + ruby/target/release/ruby-extractor.exe |
| 81 | + retention-days: 1 |
| 82 | + compile-queries: |
| 83 | + runs-on: ubuntu-latest |
| 84 | + env: |
| 85 | + CODEQL_THREADS: 4 # TODO: remove this once it's set by the CLI |
| 86 | + steps: |
| 87 | + - uses: actions/checkout@v2 |
| 88 | + - name: Fetch CodeQL |
| 89 | + run: | |
| 90 | + LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | grep -v beta | sort --version-sort | tail -1) |
| 91 | + gh release download --repo https://github.com/github/codeql-cli-binaries --pattern codeql-linux64.zip "$LATEST" |
| 92 | + unzip -q codeql-linux64.zip |
| 93 | + env: |
| 94 | + GITHUB_TOKEN: ${{ github.token }} |
| 95 | + - name: Build Query Pack |
| 96 | + run: | |
| 97 | + codeql/codeql pack create ql/lib --output target/packs |
| 98 | + codeql/codeql pack install ql/src |
| 99 | + codeql/codeql pack create ql/src --output target/packs |
| 100 | + PACK_FOLDER=$(readlink -f target/packs/codeql/ruby-queries/*) |
| 101 | + codeql/codeql generate query-help --format=sarifv2.1.0 --output="${PACK_FOLDER}/rules.sarif" ql/src |
| 102 | + (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}/{}" \;) |
| 103 | + - name: Compile with previous CodeQL versions |
| 104 | + run: | |
| 105 | + 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 |
| 106 | + rm -f codeql-linux64.zip |
| 107 | + gh release download --repo https://github.com/github/codeql-cli-binaries --pattern codeql-linux64.zip "$version" |
| 108 | + rm -rf codeql; unzip -q codeql-linux64.zip |
| 109 | + codeql/codeql query compile target/packs/* |
| 110 | + done |
| 111 | + env: |
| 112 | + GITHUB_TOKEN: ${{ github.token }} |
| 113 | + - uses: actions/upload-artifact@v2 |
| 114 | + with: |
| 115 | + name: codeql-ruby-queries |
| 116 | + path: | |
| 117 | + ruby/target/packs/* |
| 118 | + retention-days: 1 |
| 119 | + |
| 120 | + package: |
| 121 | + runs-on: ubuntu-latest |
| 122 | + needs: [build, compile-queries] |
| 123 | + steps: |
| 124 | + - uses: actions/checkout@v2 |
| 125 | + - uses: actions/download-artifact@v2 |
| 126 | + with: |
| 127 | + name: ruby.dbscheme |
| 128 | + path: ruby/ruby |
| 129 | + - uses: actions/download-artifact@v2 |
| 130 | + with: |
| 131 | + name: extractor-ubuntu-latest |
| 132 | + path: ruby/linux64 |
| 133 | + - uses: actions/download-artifact@v2 |
| 134 | + with: |
| 135 | + name: extractor-windows-latest |
| 136 | + path: ruby/win64 |
| 137 | + - uses: actions/download-artifact@v2 |
| 138 | + with: |
| 139 | + name: extractor-macos-latest |
| 140 | + path: ruby/osx64 |
| 141 | + - run: | |
| 142 | + mkdir -p ruby |
| 143 | + cp -r codeql-extractor.yml tools ql/lib/ruby.dbscheme.stats ruby/ |
| 144 | + mkdir -p ruby/tools/{linux64,osx64,win64} |
| 145 | + cp linux64/ruby-autobuilder ruby/tools/linux64/autobuilder |
| 146 | + cp osx64/ruby-autobuilder ruby/tools/osx64/autobuilder |
| 147 | + cp win64/ruby-autobuilder.exe ruby/tools/win64/autobuilder.exe |
| 148 | + cp linux64/ruby-extractor ruby/tools/linux64/extractor |
| 149 | + cp osx64/ruby-extractor ruby/tools/osx64/extractor |
| 150 | + cp win64/ruby-extractor.exe ruby/tools/win64/extractor.exe |
| 151 | + chmod +x ruby/tools/{linux64,osx64}/{autobuilder,extractor} |
| 152 | + zip -rq codeql-ruby.zip ruby |
| 153 | + - uses: actions/upload-artifact@v2 |
| 154 | + with: |
| 155 | + name: codeql-ruby-pack |
| 156 | + path: ruby/codeql-ruby.zip |
| 157 | + retention-days: 1 |
| 158 | + - uses: actions/download-artifact@v2 |
| 159 | + with: |
| 160 | + name: codeql-ruby-queries |
| 161 | + path: ruby/qlpacks |
| 162 | + - run: | |
| 163 | + echo '{ |
| 164 | + "provide": [ |
| 165 | + "ruby/codeql-extractor.yml", |
| 166 | + "qlpacks/*/*/*/qlpack.yml" |
| 167 | + ] |
| 168 | + }' > .codeqlmanifest.json |
| 169 | + zip -rq codeql-ruby-bundle.zip .codeqlmanifest.json ruby qlpacks |
| 170 | + - uses: actions/upload-artifact@v2 |
| 171 | + with: |
| 172 | + name: codeql-ruby-bundle |
| 173 | + path: ruby/codeql-ruby-bundle.zip |
| 174 | + retention-days: 1 |
| 175 | + |
| 176 | + test: |
| 177 | + defaults: |
| 178 | + run: |
| 179 | + working-directory: ${{ github.workspace }} |
| 180 | + strategy: |
| 181 | + fail-fast: false |
| 182 | + matrix: |
| 183 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 184 | + |
| 185 | + runs-on: ${{ matrix.os }} |
| 186 | + needs: [package] |
| 187 | + steps: |
| 188 | + - uses: actions/checkout@v2 |
| 189 | + with: |
| 190 | + repository: Shopify/example-ruby-app |
| 191 | + ref: 67a0decc5eb550f3a9228eda53925c3afd40dfe9 |
| 192 | + - name: Fetch CodeQL |
| 193 | + shell: bash |
| 194 | + run: | |
| 195 | + LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | grep -v beta | sort --version-sort | tail -1) |
| 196 | + gh release download --repo https://github.com/github/codeql-cli-binaries --pattern codeql.zip "$LATEST" |
| 197 | + unzip -q codeql.zip |
| 198 | + env: |
| 199 | + GITHUB_TOKEN: ${{ github.token }} |
| 200 | + working-directory: ${{ runner.temp }} |
| 201 | + - name: Download Ruby bundle |
| 202 | + uses: actions/download-artifact@v2 |
| 203 | + with: |
| 204 | + name: codeql-ruby-bundle |
| 205 | + path: ${{ runner.temp }} |
| 206 | + - name: Unzip Ruby bundle |
| 207 | + shell: bash |
| 208 | + run: unzip -q -d "${{ runner.temp }}/ruby-bundle" "${{ runner.temp }}/codeql-ruby-bundle.zip" |
| 209 | + - name: Prepare test files |
| 210 | + shell: bash |
| 211 | + run: | |
| 212 | + echo "import ruby select count(File f)" > "test.ql" |
| 213 | + echo "| 4 |" > "test.expected" |
| 214 | + echo 'name: sample-tests |
| 215 | + version: 0.0.0 |
| 216 | + dependencies: |
| 217 | + codeql/ruby-all: 0.0.1 |
| 218 | + extractor: ruby |
| 219 | + tests: . |
| 220 | + ' > qlpack.yml |
| 221 | + - name: Run QL test |
| 222 | + shell: bash |
| 223 | + run: | |
| 224 | + "${{ runner.temp }}/codeql/codeql" test run --search-path "${{ runner.temp }}/ruby-bundle" --additional-packs "${{ runner.temp }}/ruby-bundle" . |
| 225 | + - name: Create database |
| 226 | + shell: bash |
| 227 | + run: | |
| 228 | + "${{ runner.temp }}/codeql/codeql" database create --search-path "${{ runner.temp }}/ruby-bundle" --language ruby --source-root . ../database |
| 229 | + - name: Analyze database |
| 230 | + shell: bash |
| 231 | + run: | |
| 232 | + "${{ runner.temp }}/codeql/codeql" database analyze --search-path "${{ runner.temp }}/ruby-bundle" --format=sarifv2.1.0 --output=out.sarif ../database ruby-code-scanning.qls |
0 commit comments