Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential github action smells #2684

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ceddy4395
Copy link

@ceddy4395 ceddy4395 commented May 24, 2024

Purpose

Hey! 🙂
I've made the following changes to your workflow:

  • Use fixed version for runs-on argument
    • Using an explicit version for runs-on makes the developers more conscious about on what OS version they are testing/supporting. Furthermore, if breaking changes are introduced in the next version, they will not automatically break the pipeline.
  • Avoid jobs without timeouts
    • Jobs without a timeout can cause runners to be occupied when some process falls into an infinite loop or has multiple retries to perform a certain task, which will inevitably fail. Furthermore, it is also useful to be notified when a test-suite all of a sudden takes a lot longer than it used to, considering keeping tests fast is a good practice.
  • Steps should only perform a single command
    • Making sure every step has a single responsibility makes it easier to understand the workflow and, in case a workflow fails, it makes it clearer where and why it failed.

(These changes are part of a research Study at TU Delft looking at GitHub Action Smells. Find out more)

Description

Checklist

  • New code follows the Google Java Style Guide
    This is automatically checked by mvn verify, but can also be checked on its own using mvn spotless:check.
    Style violations can be fixed using mvn spotless:apply; this can be done in a separate commit to verify that it did not cause undesired changes.
  • If necessary, new public API validates arguments, for example rejects null
  • New public API has Javadoc
    • Javadoc uses @since $next-version$
      ($next-version$ is a special placeholder which is automatically replaced during release)
  • If necessary, new unit tests have been added
    • Assertions in unit tests use Truth, see existing tests
    • No JUnit 3 features are used (such as extending class TestCase)
    • If this pull request fixes a bug, a new test was added for a situation which failed previously and is now fixed
  • mvn clean verify javadoc:jar passes without errors

Copy link

google-cla bot commented May 24, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

- Use fixed version for runs-on argument
- Avoid jobs without timeouts
- Steps should only perform a single command
@ceddy4395 ceddy4395 changed the title Fix gha smells: Fix potential github action smells May 24, 2024
Copy link
Collaborator

@Marcono1234 Marcono1234 left a comment

Choose a reason for hiding this comment

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

Thanks!

To me this looks reasonable. I have added a few review comments but they are mainly about formatting.

A few general points though:

  • The hardcoded Ubuntu version might add some (very small) maintenance overhead due to having to remember to update it in the future
    But I assume that is acceptable.
  • The timeouts might be a bit too low, especially since the run duration probably depends on external factors we cannot control
  • It probably makes sense to apply these changes also to the other workflows under .github/workflows
    Would you like to do that as well?

@eamonnmcmanus, what do you think?

Comment on lines 70 to 71
run: |
mvn clean install --batch-mode --no-transfer-progress -Dproguard.skip -DskipTests
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could simplify this by moving the command in the same line:

Suggested change
run: |
mvn clean install --batch-mode --no-transfer-progress -Dproguard.skip -DskipTests
run: mvn clean install --batch-mode --no-transfer-progress -Dproguard.skip -DskipTests

Copy link
Author

Choose a reason for hiding this comment

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

I've fixed this. Also for the other files I've made the same change to keep everything consistent.

Comment on lines 72 to 74
# Run with `-Dbuildinfo.attach=false`; otherwise `artifact:compare` fails because it creates a `.buildinfo` file which
# erroneously references the existing `.buildinfo` file (respectively because it is overwriting it, a file with size 0)
# See https://issues.apache.org/jira/browse/MARTIFACT-57
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since these # Run with ... comments are only relevant for the mvn command below, it would be good to move them down (and adjust their indentation), so that they are between the name and the run below.

Copy link
Author

Choose a reason for hiding this comment

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

Ah yes moved them

@@ -65,11 +65,12 @@ jobs:
- name: "Verify no plugin issues"
run: mvn artifact:check-buildplan --batch-mode --no-transfer-progress

- name: "Verify reproducible build"
- name: "Do clean install of dependencies"
# See https://maven.apache.org/guides/mini/guide-reproducible-builds.html#how-to-test-my-maven-build-reproducibility
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might be good to move this # See ... comment above the name: "Do clean ... since it applies to both steps now and not just the mvn clean install.

Copy link
Author

Choose a reason for hiding this comment

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

Ah oke yes makes sense. I've updated this.

@@ -65,11 +65,12 @@ jobs:
- name: "Verify no plugin issues"
run: mvn artifact:check-buildplan --batch-mode --no-transfer-progress

- name: "Verify reproducible build"
- name: "Do clean install of dependencies"
Copy link
Collaborator

@Marcono1234 Marcono1234 May 24, 2024

Choose a reason for hiding this comment

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

This should probably rather say "Build project" or similar.

In Maven install is a lifecycle phase, and it includes all previous phases and therefore performs a full build (except for deployment), see https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#a-build-lifecycle-is-made-up-of-phases

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the suggestion, changed it!

- Increase timeout
- Change name for build step
- Move documentation closer to run.
- Use fixed version for runs-on argument
- Avoid jobs without timeouts
- Steps should only perform a single command
@ceddy4395
Copy link
Author

@Marcono1234 Thank you for the review! I've made the changes you've suggested, including bumping the timeouts.

I've also made the same fixes to the other workflow files!

@eamonnmcmanus
Copy link
Member

Thank you for doing this! Overall it looks good, but I'm not entirely convinced by this:

  • Use fixed version for runs-on argument
    • Using an explicit version for runs-on makes the developers more conscious about on what OS version they are testing/supporting. Furthermore, if breaking changes are introduced in the next version, they will not automatically break the pipeline.

Would Dependabot or something else notify us if the latest supported version changes? Otherwise I'm afraid we'll never think to update it. I think I might rather discover that an Ubuntu update breaks our build as soon as it happens rather than months later, even if that means the CI mysteriously failing.

mvn --batch-mode --no-transfer-progress org.codehaus.mojo:versions-maven-plugin:2.11.0:set -DnewVersion=JAPICMP-OLD
# Install artifacts with dummy version in local repository; used later by Maven plugin for comparison
mvn --batch-mode --no-transfer-progress install -DskipTests
- name: Set dummy version
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe the "used later by Maven plugin for comparison" should be preserved in some way (e.g. as comment) to make it clearer why this is done.

What about this?

Suggested change
- name: Set dummy version
# First sets a dummy project version, then installs the artifacts with that version in the local
# Maven repository, and in a later step uses it as 'old version' for the API compatibility check.
- name: Set dummy version

@Marcono1234
Copy link
Collaborator

Would Dependabot or something else notify us if the latest supported version changes?

No, that does not seem to be supported yet, see dependabot/dependabot-core#7182.

@eamonnmcmanus
Copy link
Member

Would Dependabot or something else notify us if the latest supported version changes?

No, that does not seem to be supported yet, see dependabot/dependabot-core#7182.

Thanks for that pointer. In that case, I'd suggest we leave this part as it is (with ubuntu-latest) until Dependabot does have that support.

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.

3 participants