Skip to content

Commit c1b5565

Browse files
author
Benjamin Muskalla
committed
Automation to regenerate framework models
1 parent ece952a commit c1b5565

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Regenerate framework models
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: "30 2 * * *"
7+
8+
jobs:
9+
regenerate-models:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
slug: ["placeholder"]
14+
ref: ["placeholder"]
15+
include:
16+
- slug: "apache/commons-io"
17+
ref: "8985de8fe74f6622a419b37a6eed0dbc484dc128"
18+
exclude:
19+
- slug: "placeholder"
20+
ref: "placeholder"
21+
steps:
22+
- name: Clone self (github/codeql)
23+
uses: actions/checkout@v2
24+
- name: Setup CodeQL binaries
25+
uses: ./.github/actions/fetch-codeql
26+
- name: Clone repositories
27+
uses: actions/checkout@v2
28+
with:
29+
path: repos/${{ matrix.ref }}
30+
ref: ${{ matrix.ref }}
31+
repository: ${{ matrix.slug }}
32+
- name: Build database
33+
env:
34+
SLUG: ${{ matrix.slug }}
35+
REF: ${{ matrix.ref }}
36+
run: |
37+
mkdir dbs
38+
cd repos/${REF}
39+
SHORTNAME=${SLUG//[^a-zA-Z0-9_]/}
40+
codeql database create --language=java ../../dbs/${SHORTNAME}
41+
- name: Regenerate models in-place
42+
env:
43+
SLUG: ${{ matrix.slug }}
44+
run: |
45+
SHORTNAME=${SLUG//[^a-zA-Z0-9_]/}
46+
java/ql/src/utils/model-generator/RegenerateModels.py "${SLUG}" dbs/${SHORTNAME}
47+
- name: Stage changes
48+
run: |
49+
find java -name "*.qll" -print0 | xargs -0 git add
50+
git status
51+
git diff --cached > models.patch
52+
- uses: actions/upload-artifact@v2
53+
with:
54+
name: patch
55+
path: models.patch
56+
retention-days: 7
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/python3
2+
3+
# Tool to regenerate existing framework CSV models.
4+
5+
from pathlib import Path
6+
import json
7+
import os
8+
import requests
9+
import shutil
10+
import subprocess
11+
import tempfile
12+
import sys
13+
14+
15+
lgtmSlugToModelFile = {
16+
# "apache/commons-beanutils": "java/ql/lib/semmle/code/java/frameworks/apache/BeanUtilsGenerated.qll",
17+
# "apache/commons-codec": "java/ql/lib/semmle/code/java/frameworks/apache/CodecGenerated.qll",
18+
# "apache/commons-lang": "java/ql/lib/semmle/code/java/frameworks/apache/Lang3Generated.qll",
19+
"apache/commons-io": "java/ql/lib/semmle/code/java/frameworks/apache/IOGenerated.qll",
20+
}
21+
22+
23+
def findGitRoot():
24+
return subprocess.check_output(
25+
["git", "rev-parse", "--show-toplevel"]).decode("utf-8").strip()
26+
27+
28+
def regenerateModel(lgtmSlug, extractedDb):
29+
tmpDir = tempfile.mkdtemp()
30+
print("============================================================")
31+
print("Generating models for " + lgtmSlug)
32+
print("============================================================")
33+
modelFile = lgtmSlugToModelFile[lgtmSlug]
34+
codeQlRoot = findGitRoot()
35+
targetModel = codeQlRoot + "/" + modelFile
36+
subprocess.check_call([codeQlRoot + "/java/ql/src/utils/model-generator/GenerateFlowModel.py", extractedDb,
37+
targetModel])
38+
print("Regenerated " + targetModel)
39+
shutil.rmtree(tmpDir)
40+
41+
42+
if len(sys.argv) == 3:
43+
lgtmSlug = sys.argv[1]
44+
db = sys.argv[2]
45+
regenerateModel(lgtmSlug, db)
46+
else:
47+
print('error')

0 commit comments

Comments
 (0)