|
| 1 | +name: Models as Data - Diff |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + projects: |
| 7 | + description: "The projects to generate models for" |
| 8 | + required: true |
| 9 | + default: '["netty/netty"]' |
| 10 | + pull_request: |
| 11 | + branches: |
| 12 | + - main |
| 13 | + paths: |
| 14 | + - "java/ql/src/utils/model-generator/**/*.*" |
| 15 | + - ".github/workflows/mad_modelDiff.yml" |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + |
| 20 | +jobs: |
| 21 | + model-diff: |
| 22 | + name: Model Difference |
| 23 | + runs-on: ubuntu-latest |
| 24 | + if: github.repository == 'github/codeql' |
| 25 | + strategy: |
| 26 | + matrix: |
| 27 | + slug: ${{fromJson(github.event.inputs.projects || '["apache/commons-codec", "apache/commons-io", "apache/commons-beanutils", "apache/commons-logging", "apache/commons-fileupload", "apache/commons-lang", "apache/commons-validator", "apache/commons-csv", "apache/dubbo"]' )}} |
| 28 | + steps: |
| 29 | + - name: Clone github/codeql from PR |
| 30 | + uses: actions/checkout@v2 |
| 31 | + if: github.event.pull_request |
| 32 | + with: |
| 33 | + path: codeql-pr |
| 34 | + - name: Clone github/codeql from main |
| 35 | + uses: actions/checkout@v2 |
| 36 | + with: |
| 37 | + path: codeql-main |
| 38 | + ref: main |
| 39 | + - uses: ./codeql-main/.github/actions/fetch-codeql |
| 40 | + - name: Download database |
| 41 | + env: |
| 42 | + SLUG: ${{ matrix.slug }} |
| 43 | + run: | |
| 44 | + set -x |
| 45 | + mkdir lib-dbs |
| 46 | + SHORTNAME=${SLUG//[^a-zA-Z0-9_]/} |
| 47 | + projectId=`curl -s https://lgtm.com/api/v1.0/projects/g/${SLUG} | jq .id` |
| 48 | + curl -L "https://lgtm.com/api/v1.0/snapshots/$projectId/java" -o "$SHORTNAME.zip" |
| 49 | + unzip -q -d "${SHORTNAME}-db" "${SHORTNAME}.zip" |
| 50 | + mkdir "lib-dbs/$SHORTNAME/" |
| 51 | + mv "${SHORTNAME}-db/"$(ls -1 "${SHORTNAME}"-db)/* "lib-dbs/${SHORTNAME}/" |
| 52 | + - name: Generate Models (PR and main) |
| 53 | + run: | |
| 54 | + set -x |
| 55 | + mkdir tmp-models |
| 56 | + MODELS=`pwd`/tmp-models |
| 57 | + DATABASES=`pwd`/lib-dbs |
| 58 | +
|
| 59 | + analyzeDatabaseWithCheckout() { |
| 60 | + QL_VARIANT=$1 |
| 61 | + DATABASE=$2 |
| 62 | + cd codeql-$QL_VARIANT |
| 63 | + SHORTNAME=`basename $DATABASE` |
| 64 | + python java/ql/src/utils/model-generator/GenerateFlowModel.py $DATABASE $MODELS/${SHORTNAME}.qll |
| 65 | + mv $MODELS/${SHORTNAME}.qll $MODELS/${SHORTNAME}Generated_${QL_VARIANT}.qll |
| 66 | + cd .. |
| 67 | + } |
| 68 | +
|
| 69 | + for d in $DATABASES/*/ ; do |
| 70 | + ls -1 "$d" |
| 71 | +
|
| 72 | + analyzeDatabaseWithCheckout "main" $d |
| 73 | + if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]] |
| 74 | + then |
| 75 | + analyzeDatabaseWithCheckout "pr" $d |
| 76 | + fi |
| 77 | + done |
| 78 | + - name: Install diff2html |
| 79 | + if: github.event.pull_request |
| 80 | + run: | |
| 81 | + npm install -g diff2html-cli |
| 82 | + - name: Generate Model Diff |
| 83 | + if: github.event.pull_request |
| 84 | + run: | |
| 85 | + set -x |
| 86 | + MODELS=`pwd`/tmp-models |
| 87 | + ls -1 tmp-models/ |
| 88 | + for m in $MODELS/*_main.qll ; do |
| 89 | + t="${m/main/"pr"}" |
| 90 | + basename=`basename $m` |
| 91 | + name="diff_${basename/_main.qll/""}" |
| 92 | + (diff -w -u $m $t | diff2html -i stdin -F $MODELS/$name.html) || true |
| 93 | + done |
| 94 | + - uses: actions/upload-artifact@v2 |
| 95 | + with: |
| 96 | + name: models |
| 97 | + path: tmp-models/*.qll |
| 98 | + retention-days: 20 |
| 99 | + - uses: actions/upload-artifact@v2 |
| 100 | + with: |
| 101 | + name: diffs |
| 102 | + path: tmp-models/*.html |
| 103 | + retention-days: 20 |
0 commit comments