Visitar URL original
Java: Produce diffs for model generator changes by bmuskalla · Pull Request #7268 · github/codeql · GitHub
The Wayback Machine - https://web.archive.org/web/20260603204232/https://github.com/github/codeql/pull/7268
Skip to content

Java: Produce diffs for model generator changes#7268

Merged
bmuskalla merged 20 commits into
github:mainfrom
bmuskalla:modelDiffAction
Feb 2, 2022
Merged

Java: Produce diffs for model generator changes#7268
bmuskalla merged 20 commits into
github:mainfrom
bmuskalla:modelDiffAction

Conversation

@bmuskalla
Copy link
Copy Markdown
Contributor

@bmuskalla bmuskalla commented Nov 30, 2021 •

Introduces a new GitHub action that is setup for pull requests that contain changes to the model generator.

PR usecase

It uses the main branch and the PR branch to produce two models for a variety of common libraries and shows the diff. The helps engineers working on the model generator to double-check the impact of their changes to the model generator.
By default, it is configured to generate models and their respective diffs for several apache commons projects as well as dubbo. The jobs are setup to not fail on changes as those are expected on PRs for the model generator. The results of the jobs are meant to be manually reviewed.

Screenshot 2021-11-30 at 12 28 10

The job is implemented as matrix job to parallelize the work of model generation. The current setup of models finishes within a few minutes.

The generated models and the diff reports are uploaded as Artifacts of the job.

Screenshot 2021-11-30 at 12 27 55

The models.zip archive contains all models (baseline and PR models), the diff.zip archive contains html reports of the diff between the two models.

Screenshot 2021-11-30 at 12 34 50

Ad-hoc model usecase

The job can also be manually triggered for a specific project. This can be useful to let GitHub actions download a library database (anything that's available on lgtm.com) and generates a model for it. This is helpful to check the state of art on a specific library or to generate a model for ad-hoc security research.

Screenshot 2021-11-30 at 12 32 02

Benjamin Muskalla added 6 commits November 30, 2021 12:19
@bmuskalla bmuskalla added the Java label Nov 30, 2021
@bmuskalla
Copy link
Copy Markdown
Contributor Author

Here is a sample job

@yo-h yo-h requested a review from adityasharad December 2, 2021 18:42
Comment thread .github/workflows/java-model-diff.yml Outdated
# ["google/guava", "spring-projects/spring-framework", "apache/poi"]
# others
# ["FasterXML/jackson-core", "FasterXML/jackson-databind", "google/gson", "JodaOrg/joda-time"
slugs: ${{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"]' )}}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These defaults are different from the defaults in the workflow_dispatch block, which can be a little confusing. It means that your defaults for PR and push runs are different from your defaults for manual dispatch runs. Do you want that, or should we keep them identical?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: I would name this slug since you only get one for each matrix job, and can refer to it as matrix.slug.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference in default is intentional. We have essentially two usecases:

  • PR feedback
  • use the action to generate an adhoc model (that's why the dispatch default is just a simple example to showcase the format)
    Removed the push trigger as that was only used for testing

Comment thread .github/workflows/java-model-diff.yml Outdated
Comment thread .github/workflows/java-model-diff.yml
Comment thread .github/workflows/java-model-diff.yml Outdated
Comment thread .github/workflows/java-model-diff.yml Outdated
Comment on lines +47 to +52
SHORTNAME=${SLUG//[^a-zA-Z0-9_]/}
projectId=`curl -s https://lgtm.com/api/v1.0/projects/g/$SLUG | jq .id`
curl -L "https://lgtm.com/api/v1.0/snapshots/$projectId/java" -o $SHORTNAME.zip
unzip -q -d $SHORTNAME-db $SHORTNAME.zip
mkdir lib-dbs/$SHORTNAME/
mv $SHORTNAME-db/`ls -1 $SHORTNAME-db`/* lib-dbs/$SHORTNAME/
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General recommendation: double-quote everywhere you're using variables or names controlled by the external file. Your replacement will ensure the short name won't have spaces, but it's good to be defensive.

I prefer to use "$(...)" over `...` to handle spaces in the output, but that is partly personal style.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also why do you have to unzip and move rather than unzipping straight into lib-dbs/$SHORTNAME?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to handle the fact that we don't know the root folder of the zip archive (due to the naming pattern). With this indirection, we can move it to a known place (lib-dbs/$SHORTNAME)

Comment thread .github/workflows/java-model-diff.yml Outdated
Comment thread .github/workflows/java-model-diff.yml Outdated
Comment thread .github/workflows/java-model-diff.yml
description: "The projects to generate models for"
required: true
default: '["netty/netty"]'
pull_request:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How strict do you want to keep this? Actions runs from external contributors will not start unless we manually approve them, but it's good to be careful. Should this run only for maintainers, or only from PRs based within this repository (no forks)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We restrict it to only this repo now. Generally, I think external contribtors might find this useful but it's too early to invest into that. Is there anything else we need to only run this for maintainers for now?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if: github.repository == 'github/codeql' is true even for PRs opened against this repo from forks. Let's chat separately so I can understand exactly which PRs you want this to run on.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adityasharad Could you clarify you security concerns? The pull_request trigger is not particularly dangerous because pull requests from forks only run with (short-lived) read-only tokens.

Comment thread .github/workflows/java-model-diff.yml
Copy link
Copy Markdown
Collaborator

@adityasharad adityasharad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General structure of the diffing mechanism looks sensible, thanks. A few more suggestions on the basis of that.

Comment thread .github/workflows/java-model-diff.yml Outdated
Comment thread .github/workflows/java-model-diff.yml Outdated
Comment thread .github/workflows/java-model-diff.yml Outdated
Comment thread .github/workflows/java-model-diff.yml
Comment thread .github/workflows/java-model-diff.yml Outdated
Comment thread .github/workflows/java-model-diff.yml Outdated
@bmuskalla
Copy link
Copy Markdown
Contributor Author

Sorry for this mixed state PR @adityasharad - I was working on it and got sick in december, that's why you saw such an unfinished PR with only some of your comments applied. I think I got all the feedback now incorporated and also renamed a few things to make the branching clearer (head vs prhead).

@bmuskalla
Copy link
Copy Markdown
Contributor Author

Friendly ping @adityasharad - let me know if you don't have capacity for this one and I'll let someone else take it from here.

Copy link
Copy Markdown
Collaborator

@adityasharad adityasharad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the earlier comments. A few more observations, and one question I'll figure out with you live.

Comment thread .github/workflows/java-model-diff.yml Outdated
uses: actions/checkout@v2
with:
path: codeql-head
ref: ${{ github.ref }}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're in a pull_request event, github.ref isn't main -- it is the PR merge ref.

I think you want to compare PR head vs base, or PR merge vs base, but certainly not PR merge vs PR head. See what https://github.com/github/codeql/blob/62aa7b75bd7220d4854793f66596013fa73550ad/.github/workflows/csv-coverage-pr-artifacts.yml does for example.

Comment thread .github/workflows/java-model-diff.yml Outdated
description: "The projects to generate models for"
required: true
default: '["netty/netty"]'
pull_request:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if: github.repository == 'github/codeql' is true even for PRs opened against this repo from forks. Let's chat separately so I can understand exactly which PRs you want this to run on.

@bmuskalla
Copy link
Copy Markdown
Contributor Author

As discussed offline, we'll move the job elsewhere.

@bmuskalla bmuskalla closed this Jan 25, 2022
@bmuskalla bmuskalla reopened this Jan 27, 2022
Benjamin Muskalla added 2 commits January 27, 2022 12:27
Copy link
Copy Markdown
Collaborator

@adityasharad adityasharad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat. Thanks for addressing the comments, let's give this a go!

@bmuskalla bmuskalla merged commit d4c4e75 into github:main Feb 2, 2022
@bmuskalla
Copy link
Copy Markdown
Contributor Author

Thanks @adityasharad !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants