Skip to content

Commit eee03eb

Browse files
author
Benjamin Muskalla
authored
Merge pull request github#7767 from bmuskalla/regenerateModelScript
Java: Regenerate framework models automatically
2 parents e9b496b + bc5753c commit eee03eb

File tree

2 files changed

+115
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)