Skip to content

Big Pipeline Update - #18

Merged
MatKuhr merged 76 commits into
mainfrom
unified-pipeline
Aug 21, 2023
Merged

MatKuhr merged 76 commits into
mainfrom
unified-pipeline

Conversation

@MatKuhr

@MatKuhr MatKuhr commented Aug 14, 2023 •

Copy link
Copy Markdown
Member

Context Information

BLI: SAP/cloud-sdk-java-backlog#121

This PR does a couple of things:

  • Add OpenAPI modules
  • Change the pipeline to be a single job (to enable PMD + Spotbugs and improve performance)
    • Implement multi-stage parallel pipeline for better performance
    • Add an equivalent, simplified i.e. linear version of the pipeline as daily cron job to serve as a sanity check
  • Actually make use of modules-bom
  • Upgrade to version 4.20.0
  • Clean up some unnecessary stuff from the parent pom
  • Add file change detection
  • Fix PMD scripts to work with suppressions
  • Enhance scripts to allow for unlimited findings
  • Merge latest state from main/v5

@Johannes-Schneider Johannes-Schneider left a comment

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.

Just from the looks of this PR, it seems like you spent significant manual effort for getting the pipeline and entire maven setup to somehow work...
Additionally, there seems to be a lot of clean up contained in the added modules.

IMO, this is not a good approach.
If we start investing so much clean up / setup effort for just a few modules, merging the rest of the code base in here is going to be a nightmare.
So I'd suggest to stick with the approach we aligned on:

  • Remove all the internal modules in our existing repo first
  • (We can still update the pipeline as suggested in this PR)
  • Once that is done, simply force push everything into this repo
  • THEN start cleaning up and fixing things
  • (Crossing all fingers that we don't have to migrate changes coming from v4)

Comment thread .github/workflows/build.yaml Outdated
- name: Compile
# we need to use install here because otherwise the code checks below don't work
# they seem to require "mvn dependency:resolve" to work, why is unclear honestly...
# Problem: With caching the maven repo this might? maybe? produce race conditions / side effects between different executions

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.

I'm also worried about this...

As by the documentation:

The format of the used cache key is setup-java-${{ platform }}-${{ packageManager }}-${{ fileHash }}, where the hash is based on the following files [...]

  • maven: **/pom.xml

Therefore, it seems like the cache key would always be the exact same for different execution instances (which is bad) 😔

I'm wondering about the entire setup in general: The path $HOME/.m2/repository doesn't seem to be different for different runs... So we would always share the same .m2.
Therefore, I feel like we might need to come up with our own "caching" strategy to avoid leaking state from one job run into an other one?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yeah, this is first in the ToDo list to come up with a solution for.

For now it's kinda fine, because the cache doesn't properly work anyway. The cache key is indeed the same, as I could tell from the logs, but the content is still lost between jobs (even in the same workflow). Part of the reason why I had to merge everything into one job...

Comment thread .pipeline/scripts/print-spotbugs.py Outdated
print(f"warnings high: {findings['1']}, allowed is {threshold_high}")

if findings['3'] > threshold_low or findings['2'] > threshold_normal or findings['1'] > threshold_high:
if findings['1'] > threshold_high: # or findings['2'] > threshold_normal or findings['3'] > threshold_low:

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.

I assume you commented the rest of the condition for testing, right?
If so, we should probably revert this before merging.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

no, we have around 80 normal findings which we would all have to fix or increase the threshold otherwise. to me it looked like minor stuff not worth failing over.

Comment thread pom.xml Resolved

@Johannes-Schneider Johannes-Schneider left a comment •

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.

I just reviewed at the pipeline changes, which looked pretty nice 👍

Comment on lines +39 to +43
- name: Load Maven Repository
uses: actions/cache/restore@v3
with:
path: ~/.m2/repository
key: maven

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.

[question]

Is this step going to create the cache (for the very first pipeline run of a new branch, for example)?
And, if so, is it a problem that we are using it inside a matrix (i.e. have multiple executions of it running in parallel)?


Edit:

I saw there is an extra actions/cache/save action, so I assume that this will not automatically create a cache for the first pipeline run 👍

Comment thread .github/workflows/build.yaml Resolved
echo "There are local changes in the following files:"
echo $CHANGED_FILES
echo "Printing the git diff:"
git --no-pager diff

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.

Ufff... this might be getting HUGE if we decided to change some service specification (in one of the sample modules, for example), right.
So it this really a good idea? 😅

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

sure, but why not? I don't think you will get flamed for too many log output lines that quickly.. and even if we do, worst case the run is aborted, which is fine since it already failed anyway..

Comment thread .github/workflows/build.yaml Resolved
Comment thread .github/workflows/build.yaml Outdated

- name: Test
run: |
mvn $MVN_CLI_ARGS test jacoco:report

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.

This is NOT compiling the code as we restored the (previously built) target dirs, right?

@Johannes-Schneider Johannes-Schneider Aug 17, 2023 •

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.

Actually, when checking the output of the last successful run (at this point in time), I can see that the code is indeed still getting compiled:

(From the Test stage)

[INFO] --- maven-compiler-plugin:3.11.0:compile (default-compile) @ fluent-result ---
[INFO] Changes detected - recompiling the module! :source
[INFO] Compiling 35 source files with javac [debug deprecation release 8] to target/classes

...

[INFO] --- maven-compiler-plugin:3.11.0:testCompile (default-testCompile) @ fluent-result ---
[INFO] Changes detected - recompiling the module! :dependency
[INFO] Compiling 2 source files with javac [debug deprecation release 8] to target/test-classes

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.

It looks like this can be fixed rather easily by directly invoking the surefire plugin (mvn surefire:test ...) instead of just mvn test - verified manually on my local machine 👍

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

uff, good that you checked that. It was working at some point, I swear 😄
My best guess is that it stopped working when I switched to the zip file approach. It can also be fixed by simply touching all files after unzipping, which I added.

However, I now see that man test runs a bunch of other plugins again as well eg. the enforcer plugin. Those take some time and already run during install, so I would go with surefire:test

Remaining question is: Is there any plugin/goal that we don't execute, if we run install -DskipTests and surefire:test compared to install?
I think I'm just gonna compare the logs to see if I can find any diff

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.

Remaining question is: Is there any plugin/goal that we don't execute, if we run install -DskipTests and surefire:test compared to install?

Good question.
How about being more precise in the compilation step by actually just skipping the surefire:test phase?
(I saw that there seems to be an option in the plugin config to skip the execution, so that could be done using our regular property approach - but not sure if really achieves the desired result)

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.

🚨🚨🚨🚨

It looks like the most recent approach (mvn jacoco:prepare-agent surefire:test jacoco:report) produces a different test coverage result compared the "regular" approach (mvn test jcoco:report).

I compared run #168 vs. run #161:

(run 168)
coverage = 0.668060439038297
branch coverage = 0.5957746478873239

 vs. 

(run 161)
coverage = 0.5919857235561323
branch coverage = 0.5228365384615384

@MatKuhr

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We are already doing that. The source for the surefire option is:

<parameter>
          <name>skipTests</name>
          <type>boolean</type>
          <since>2.4</since>
          <required>false</required>
          <editable>true</editable>
          <description>Set this to &quot;true&quot; to skip running tests, but still compile them. Its use is NOT RECOMMENDED, but quite convenient on occasion.
Failsafe plugin deprecated the parameter skipTests and the parameter will be removed in Failsafe 3.0.0 as it is a source of conflicts between Failsafe and Surefire plugin.</description>
</parameter>

I was only concerned about other plugins that bind to the test maven lifecycle (and may or may not also use the same property as flag). But I checked and other than the prepare-agent from Jacoco there is nothing running in addition when comparing surefire:test with test that didn't already run during install -DskipTests, so we should be safe.

And the benefit is quite substantial, as we don't unnecessarily re-run enforcer and dependency plugins.

@MatKuhr MatKuhr changed the title Unified pipeline Big Pipeline Update Aug 18, 2023

@Johannes-Schneider Johannes-Schneider left a comment

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.

Just a few more (minor) things. Otherwise LGTM

Comment on lines +49 to +54
- name: Generate JaCoCo Badge
id: jacoco
uses: cicirello/jacoco-badge-generator@v2
with:
generate-branches-badge: true
jacoco-csv-file: "**/jacoco.csv"

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.

I'd say let's not generate the JaCoCo Badge from this pipeline (we do that from our regular pipeline, which runs on every main build anyways, right?).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not sure if the badge is used anywhere. Instead, we use the outputs of the step to determine the coverage %, which we will enforce via thresholds in the future. I would leave it to the ticket to figure out the details on this..

Comment thread .github/workflows/build-sanity.yaml Outdated
Comment on lines +28 to +32
- name: Load Maven Repository
uses: actions/cache/restore@v3
with:
path: ~/.m2/repository
key: maven

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.

As we are aiming for a sanity check, let's remove external factors (such as this) to be extra sure everything is indeed working as intended (maybe we messed up something in the caching in our other pipeline and we don't notice because we made the same mistake here?).

Ultimately, since this runs only once a day, performance doesn't really matter here.

on:
push:
branches: ["main", "poc_pipeline"]
branches: ["main"]

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.

[comment - no action needed in this PR]

Do we plan on sticking with our aligned branch naming strategy?
(I.e. rename main to main/v5?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was thinking about this too. But with the current timeline I figured we should leave it out for now and just use main, until there is a need for a v6.

Comment thread .github/workflows/build.yaml Outdated
name: Build, Test and Verify JDK ${{ matrix.Java }}
name: Build
env:
CHANGED_FILES: ""

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.

Why is this needed?
This variable should be defined in the Local Changes Check no matter what, right?

@MatKuhr
MatKuhr merged commit 87530d1 into main Aug 21, 2023
@MatKuhr
MatKuhr deleted the unified-pipeline branch August 21, 2023 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants