|
| 1 | +name: Run QL for QL |
| 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 | + queries: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v2 |
| 17 | + - name: Find codeql |
| 18 | + id: find-codeql |
| 19 | + uses: github/codeql-action/init@erik-krogh/ql |
| 20 | + with: |
| 21 | + languages: javascript # does not matter |
| 22 | + - name: Get CodeQL version |
| 23 | + id: get-codeql-version |
| 24 | + run: | |
| 25 | + echo "::set-output name=version::$("${CODEQL}" --version | head -n 1 | rev | cut -d " " -f 1 | rev)" |
| 26 | + shell: bash |
| 27 | + env: |
| 28 | + CODEQL: ${{ steps.find-codeql.outputs.codeql-path }} |
| 29 | + - name: Cache queries |
| 30 | + id: cache-queries |
| 31 | + uses: actions/cache@v2 |
| 32 | + with: |
| 33 | + path: ${{ runner.temp }}/query-pack.zip |
| 34 | + key: queries-${{ hashFiles('ql/**/*.ql*') }}-${{ hashFiles('ql/ql/src/ql.dbscheme*') }}-${{ steps.get-codeql-version.outputs.version }} |
| 35 | + - name: Build query pack |
| 36 | + if: steps.cache-queries.outputs.cache-hit != 'true' |
| 37 | + run: | |
| 38 | + cd ql/ql/src |
| 39 | + "${CODEQL}" pack create |
| 40 | + cd .codeql/pack/codeql/ql-all/0.0.0 |
| 41 | + zip "${PACKZIP}" -r . |
| 42 | + env: |
| 43 | + CODEQL: ${{ steps.find-codeql.outputs.codeql-path }} |
| 44 | + PACKZIP: ${{ runner.temp }}/query-pack.zip |
| 45 | + - name: Upload query pack |
| 46 | + uses: actions/upload-artifact@v2 |
| 47 | + with: |
| 48 | + name: query-pack-zip |
| 49 | + path: ${{ runner.temp }}/query-pack.zip |
| 50 | + |
| 51 | + extractors: |
| 52 | + strategy: |
| 53 | + fail-fast: false |
| 54 | + |
| 55 | + runs-on: ubuntu-latest |
| 56 | + |
| 57 | + steps: |
| 58 | + - uses: actions/checkout@v2 |
| 59 | + - name: Cache entire extractor |
| 60 | + id: cache-extractor |
| 61 | + uses: actions/cache@v2 |
| 62 | + with: |
| 63 | + path: | |
| 64 | + ql/target/release/ql-autobuilder |
| 65 | + ql/target/release/ql-autobuilder.exe |
| 66 | + ql/target/release/ql-extractor |
| 67 | + ql/target/release/ql-extractor.exe |
| 68 | + key: ${{ runner.os }}-extractor-${{ hashFiles('ql/**/Cargo.lock') }}-${{ hashFiles('ql/**/*.rs') }} |
| 69 | + - name: Cache cargo |
| 70 | + if: steps.cache-extractor.outputs.cache-hit != 'true' |
| 71 | + uses: actions/cache@v2 |
| 72 | + with: |
| 73 | + path: | |
| 74 | + ~/.cargo/registry |
| 75 | + ~/.cargo/git |
| 76 | + ql/target |
| 77 | + key: ${{ runner.os }}-rust-cargo-${{ hashFiles('ql/**/Cargo.lock') }} |
| 78 | + - name: Check formatting |
| 79 | + if: steps.cache-extractor.outputs.cache-hit != 'true' |
| 80 | + run: cd ql; cargo fmt --all -- --check |
| 81 | + - name: Build |
| 82 | + if: steps.cache-extractor.outputs.cache-hit != 'true' |
| 83 | + run: cd ql; cargo build --verbose |
| 84 | + - name: Run tests |
| 85 | + if: steps.cache-extractor.outputs.cache-hit != 'true' |
| 86 | + run: cd ql; cargo test --verbose |
| 87 | + - name: Release build |
| 88 | + if: steps.cache-extractor.outputs.cache-hit != 'true' |
| 89 | + run: cd ql; cargo build --release |
| 90 | + - name: Generate dbscheme |
| 91 | + if: steps.cache-extractor.outputs.cache-hit != 'true' |
| 92 | + run: ql/target/release/ql-generator --dbscheme ql/ql/src/ql.dbscheme --library ql/ql/src/codeql_ql/ast/internal/TreeSitter.qll |
| 93 | + - uses: actions/upload-artifact@v2 |
| 94 | + with: |
| 95 | + name: extractor-ubuntu-latest |
| 96 | + path: | |
| 97 | + ql/target/release/ql-autobuilder |
| 98 | + ql/target/release/ql-autobuilder.exe |
| 99 | + ql/target/release/ql-extractor |
| 100 | + ql/target/release/ql-extractor.exe |
| 101 | + retention-days: 1 |
| 102 | + package: |
| 103 | + runs-on: ubuntu-latest |
| 104 | + |
| 105 | + needs: |
| 106 | + - extractors |
| 107 | + - queries |
| 108 | + |
| 109 | + steps: |
| 110 | + - uses: actions/checkout@v2 |
| 111 | + - uses: actions/download-artifact@v2 |
| 112 | + with: |
| 113 | + name: query-pack-zip |
| 114 | + path: query-pack-zip |
| 115 | + - uses: actions/download-artifact@v2 |
| 116 | + with: |
| 117 | + name: extractor-ubuntu-latest |
| 118 | + path: linux64 |
| 119 | + - run: | |
| 120 | + unzip query-pack-zip/*.zip -d pack |
| 121 | + cp -r ql/codeql-extractor.yml ql/tools ql/ql/src/ql.dbscheme.stats pack/ |
| 122 | + mkdir -p pack/tools/linux64 |
| 123 | + if [[ -f linux64/ql-autobuilder ]]; then |
| 124 | + cp linux64/ql-autobuilder pack/tools/linux64/autobuilder |
| 125 | + chmod +x pack/tools/linux64/autobuilder |
| 126 | + fi |
| 127 | + if [[ -f linux64/ql-extractor ]]; then |
| 128 | + cp linux64/ql-extractor pack/tools/linux64/extractor |
| 129 | + chmod +x pack/tools/linux64/extractor |
| 130 | + fi |
| 131 | + cd pack |
| 132 | + zip -rq ../codeql-ql.zip . |
| 133 | + - uses: actions/upload-artifact@v2 |
| 134 | + with: |
| 135 | + name: codeql-ql-pack |
| 136 | + path: codeql-ql.zip |
| 137 | + retention-days: 1 |
| 138 | + analyze: |
| 139 | + runs-on: ubuntu-latest |
| 140 | + strategy: |
| 141 | + matrix: |
| 142 | + folder: [cpp, csharp, java, javascript, python, ql, ruby] |
| 143 | + |
| 144 | + needs: |
| 145 | + - package |
| 146 | + |
| 147 | + steps: |
| 148 | + - name: Download pack |
| 149 | + uses: actions/download-artifact@v2 |
| 150 | + with: |
| 151 | + name: codeql-ql-pack |
| 152 | + path: ${{ runner.temp }}/codeql-ql-pack-artifact |
| 153 | + |
| 154 | + - name: Prepare pack |
| 155 | + run: | |
| 156 | + unzip "${PACK_ARTIFACT}/*.zip" -d "${PACK}" |
| 157 | + env: |
| 158 | + PACK_ARTIFACT: ${{ runner.temp }}/codeql-ql-pack-artifact |
| 159 | + PACK: ${{ runner.temp }}/pack |
| 160 | + - name: Hack codeql-action options |
| 161 | + run: | |
| 162 | + JSON=$(jq -nc --arg pack "${PACK}" '.resolve.queries=["--search-path", $pack] | .resolve.extractor=["--search-path", $pack] | .database.init=["--search-path", $pack]') |
| 163 | + echo "CODEQL_ACTION_EXTRA_OPTIONS=${JSON}" >> ${GITHUB_ENV} |
| 164 | + env: |
| 165 | + PACK: ${{ runner.temp }}/pack |
| 166 | + |
| 167 | + - name: Checkout repository |
| 168 | + uses: actions/checkout@v2 |
| 169 | + - name: Create CodeQL config file |
| 170 | + run: | |
| 171 | + echo "paths:" > ${CONF} |
| 172 | + echo " - ${FOLDER}" >> ${CONF} |
| 173 | + echo "paths-ignore:" >> ${CONF} |
| 174 | + echo " - ql/ql/test" >> ${CONF} |
| 175 | + echo "Config file: " |
| 176 | + cat ${CONF} |
| 177 | + env: |
| 178 | + CONF: ./ql-for-ql-config.yml |
| 179 | + FOLDER: ${{ matrix.folder }} |
| 180 | + |
| 181 | + - name: Initialize CodeQL |
| 182 | + uses: github/codeql-action/init@erik-krogh/ql |
| 183 | + with: |
| 184 | + languages: ql |
| 185 | + db-location: ${{ runner.temp }}/db |
| 186 | + config-file: ./ql-for-ql-config.yml |
| 187 | + |
| 188 | + - name: Perform CodeQL Analysis |
| 189 | + uses: github/codeql-action/analyze@erik-krogh/ql |
| 190 | + with: |
| 191 | + category: "ql-for-ql-${{ matrix.folder }}" |
| 192 | + |
0 commit comments