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 the GitHub actions cron job #11256

Merged
merged 1 commit into from Apr 28, 2022
Merged

Conversation

mkurz
Copy link
Member

@mkurz mkurz commented Apr 28, 2022

The problem:

  1. Let's assume the cache is empty.
  2. A scheduled job starts and will fetch the current akka snapshot version
  3. Afterwards publishLocal. Because we are using akka snapshots, the published Play version will be something like 2.8.1+1638-55238a2b-SNAPSHOT-akka-2.6.19+52-00c1da99-SNAPSHOT-akka-http-10.1.15+4-8e825ed4-SNAPSHOT. Artifacts will be cached with play-published-local-jdk8-${{ github.sha }}. (github.sha is the commit from the Play repo)
  4. scripted test reuse artifacts from cache play-published-local-jdk8-${{ github.sha }}
  5. Everything works

The scheduled jobs finished, nothing changed (and nothing will be changing) in the Play repository. But, because the akka team isn't lazy, new commits get pushed to akka (or akka-http)! So the next nightly looks like this:

  1. The cache still contains the key play-published-local-jdk8-${{ github.sha }}
  2. A scheduled job starts and will fetch the new current akka snapshot version
  3. Afterwards publishLocal. Because of the new akka snapshot version the published Play version will change to 2.8.1+1638-55238a2b-SNAPSHOT-akka-2.6.19+58-af1e7560-SNAPSHOT-akka-http-10.1.15+4-8e825ed4-SNAPSHOT. These artifacts will not be cached anymore since there was a cache hit for play-published-local-jdk8-${{ github.sha }} already, because the Play commit-sha did not change. Since the GHA cache is immutable, the cache will not be updated.
  4. scripted test reuse artifacts from cache play-published-local-jdk8-${{ github.sha }}. Since the cache for the github.sha id was not updated, the artifacts build with the new akka snapshot version is missing.
  5. Fail!

@@ -85,7 +85,7 @@ jobs:
rm -rf ~/.ivy2/local
sbt "${{needs.extra-vars.outputs.akka_version_opts}}" "${{needs.extra-vars.outputs.akka_http_version_opts}}" crossScalaVersions crossSbtVersions +publishLocal
cache-path: ~/.ivy2/local/com.typesafe.play
cache-key: play-published-local-jdk8-${{ github.sha }}
cache-key: play-published-local-jdk8-${{ github.sha }}-${{ github.event_name != 'schedule' || github.run_id }}
Copy link
Member Author

Choose a reason for hiding this comment

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

So this is a bit of a hacky way to generate a unique cache key for scheduled jobs, but not for pull request jobs.

So when a pull request gets build the cache-key will be something like:

play-published-local-jdk8-55238a2b-true

That way the cache can be reused across multiple pull requests (remember, for pull requests we do not use akka snapshots, but stable versions. So if the pr base branch did not change between pull requests we are absolutely fine reusing the cache containing the local published Play artifacts)

For schedules jobs however we always want to create a new cache for each workflow run, since we don't know if the akka(-http) snapshot version changed between two nightly runs (so the cache is effectively only used by the scripted jobs after it got filled by the publish local step). The key will then look like:

play-published-local-jdk8-55238a2b-2238770949

I did test this expression here: https://github.com/mkurz/release-drafter-test/runs/6209442291?check_suite_focus=true#step:8:10 (you can have a look in the workflow file)

I can not see in the docs how to achieve that in another way, since we can't have if conditions within expressions (also no elvis operator): https://docs.github.com/en/actions/learn-github-actions/expressions
If someone has a nicer way to do that, please let me know 😉

Copy link
Member

Choose a reason for hiding this comment

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

As another variant, we can to use the Akka versions. Something like

Suggested change
cache-key: play-published-local-jdk8-${{ github.sha }}-${{ github.event_name != 'schedule' || github.run_id }}
cache-key: play-published-local-jdk8-${{ github.sha }}-${{needs.extra-vars.outputs.akka_version_opts}}-${{needs.extra-vars.outputs.akka_http_version_opts}}

For PR's it will be play-published-local-jdk8-55238a2b-- and for sheduler play-published-local-jdk8-55238a2b-2.6.19+52-00c1da99-SNAPSHOT-10.1.15+4-8e825ed4-SNAPSHOT.

PS: But I like your variant and don't see a matter to change it. Only one moment, that we should understand that run_id will not change if we will re-run failed shedule action. (https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables)

A unique number for each workflow run within a repository. This number does not change if you re-run the workflow run. For example, 1658821493.

Copy link
Member Author

Choose a reason for hiding this comment

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

Only one moment, that we should understand that run_id will not change if we will re-run failed shedule action.

Yes, but the akka version might also not have changed when you re-run the workflow, so it's similiar (if not the same in most cases). Also, when a job fails the post hook to fill the cache will not run anyway, so this should not be a problem at all.

@mkurz
Copy link
Member Author

mkurz commented Apr 28, 2022

All checks passed 👍

@mkurz mkurz merged commit 2a65ca3 into playframework:main Apr 28, 2022
@mkurz mkurz deleted the fix_cron_jobs branch April 28, 2022 11:32
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.

None yet

2 participants