Commit graph

283 commits

Author SHA1 Message Date
daz
be413309fa
First cut at actions for dependency-graph
- Dependency graph init-script references published version of plugin jar.
- `dependency-graph-generate` action will:
     - Provision Gradle if required
     - Execute Gradle with dependency-graph plugin to generate graph JSON
     - Upload dependency-graph JSON file as workflow artifact
- `dependency-graph-submit` action will:
    - Download dependency-graph JSON artifact
    - Submit the graph via the GitHub dependency submission API
2023-06-28 11:24:57 -06:00
daz
07023d3e3e
Refactor input parameters
Moved reading of all input parameters into a common source: `input-params.ts`.
This centralized all input parameter reads, and allowed an improved implementation
of reading boolean parameters. In particular, the implementation now provides a default
value for a boolean input parameter that isn't declared for an action.
2023-06-06 10:47:56 -06:00
daz
c94d573317
Refactor action execution for reuse
Introducing new actions for the GitHub dependency graph will involve reuse of much of
the action infrastructure. This commit reorganises things a little to facilitate reuse.
2023-06-03 14:09:52 -06:00
daz
2bf6bc3646
Include workflow name in cache key
Fixes #699 by avoiding cache key collisions between jobs with the
same name in different workflows.
2023-05-23 14:59:12 -06:00
daz
d23c38fad3
Remove incorrect comment 2023-05-04 08:25:28 -06:00
daz
a580d9bd57
Detect GE plugin applied in settingsEvaluated
The `PluginManager.hasPlugin` method was not detecting the GE plugin when it
was applied during settingsEvaluated.
Switching to `PluginManager.withPlugin` fixes this.

Fixes #626
2023-04-26 10:49:32 -06:00
Daz DeBoer
eb126d771e
Update for Gradle 8.1 release
With Gradle 8.1, the configuration-cache has changed and is now stable. 
As a temporary measure, this commit disables save/restore of the configuration-cache
data to avoid issues until we can deal with this change properly.
2023-04-14 16:23:09 -06:00
Jonathan Leitschuh
887e0bda35
Fix typo (#655)
Signed-off-by: Jonathan Leitschuh <Jonathan.Leitschuh@gmail.com>
2023-04-04 20:22:54 -06:00
Daz DeBoer
6095a76664
Update tests for Gradle 8 2023-02-18 13:25:58 -07:00
Daz DeBoer
b47aad4750
Remove use of deprecated fs.rmdir
Using fs.rm({recursive: true}) instead.

Fixes #502
2023-02-06 12:40:03 -07:00
Daz DeBoer
e444647395
Save/restore extracted JDK instead of archive
Gradle 7.6 changes the way the downloaded JDKs are saved and extracted.
To workaround this difference, save and restore the extracted JDK instead.
2022-12-07 20:07:40 +13:00
Daz DeBoer
3fbe033aaa
Retain 'set-output' command when GITHUB_OUTPUT is not set
This should maintain compatibility with older GitHub Enterprise versions
2022-10-22 08:20:16 -06:00
Daz DeBoer
3b959539de
Remove use of deprecated 'set-output' command
- Use GITHUB_OUTPUT file in init script
- Write to a marker file in configuratiion-cache tests

Fixes #461
2022-10-20 14:09:12 -06:00
Daz DeBoer
394498f89f
Avoid appending to existing build-results file
When configuration-cache is enabled, the invocationId may not be unique, which can result in
mulitple builds writing to the same file. Rather than failing the post-action, we simply
ignore any subsequent build results with the same ID.

Fixes #441
2022-09-26 11:03:26 -06:00
Daz DeBoer
0e4b100458
Use node to set file timestamps
Using `find` and `touch` will not work on windows, so this provides a
cross-platform mechanism.
2022-08-26 09:04:11 -06:00
Daz DeBoer
82bc72e1e7
Re-enable cache-cleanup on Windows 2022-08-26 09:03:58 -06:00
Daz DeBoer
531cc21aeb
Clarify comment 2022-08-25 20:26:16 -06:00
Daz DeBoer
cc60593845
Disable cache-cleanup on Windows
It does not seem possible to use `find .. -exec ..` on Windows,
so a node-only solution may be required.
2022-08-25 20:06:13 -06:00
Daz DeBoer
fb549a8417
Avoid using GNU-specific touch options
This makes cache-cleaner work correctly on MacOS.
2022-08-25 20:03:04 -06:00
Daz DeBoer
25ec178747
Add integration test for cache cleanup 2022-08-22 14:08:28 -06:00
Daz DeBoer
3cc0a8f6bb
Add some explanatory comments 2022-08-22 14:08:28 -06:00
Daz DeBoer
915123c493
Add experimental support for cache-cleanup
- Includes basic implementation as `CacheCleaner`
- Integration test that checks unused files are removed:
  - Downloaded dependencies
  - Local build cache entries
  - Wrapper distributions
2022-08-22 14:08:28 -06:00
Daz DeBoer
eb22e65b5b
Extract constant for Env Var name 2022-08-22 13:30:07 -06:00
Daz DeBoer
8a386f6915
Remove custom option for cache-read-timeout
Now that `@actions/cache` provides a env var override, we can remove our
custom configuration for setting the timeout on cache restore operations.

If the env var is NOT set, we continue to override the 60min default with 10mins.
2022-08-22 13:13:20 -06:00
Daz DeBoer
f0ec7fb780
Remove 'followSymbolicLinks: false' flag for Globber
It appears that when restoring the Gradle User Home directory, certain empty
directories are being identified by Node as broken symlinks. This results in
`Error: ENOENT: No such file or directory` when attempting to resolve a Glob pattern.

By using the default behaviour of Globber (followSymbolicLinks && ignoreBrokenLinks),
these bad files no longer cause errors when saving the Gradle User Home to cache.

Fixes #408
2022-08-18 17:10:03 -06:00
Daz DeBoer
8f9b7c7d7f
Add a configurable timeout for cache reads
Fixes #369
2022-08-16 17:37:41 -06:00
Daz DeBoer
b49446f8e1
Improved cache reporting
- Fix count of saved entries
- Catch and report errors on save and restore
- Correctly report entries that are never requested
2022-08-16 16:37:17 -06:00
Daz DeBoer
792a93a5e3
Do not write build-results file outside GitHub Actions context
The init-scripts added to Gradle User Home were assuming the presence of certain
GitHub Actions environment variables. With this fix, these init scripts behave
better without these env vars.

Fixes #350
2022-07-11 15:09:56 -06:00
Daz DeBoer
6965e8ed4c
Only stop Gradle Daemons when saving Gradle User Home state
Fixes #341
2022-06-22 16:41:03 -06:00
Daz DeBoer
884bca012f
Extracted some classes and refactored for clarity 2022-06-22 16:35:55 -06:00
Daz DeBoer
4cb86e9712
Report when cache not available 2022-06-20 20:17:36 -06:00
Daz DeBoer
eaed5520c4
Write job summary to logs when feature not available 2022-06-20 20:10:34 -06:00
Daz DeBoer
ec939a8c10
Disable caching when feature not available 2022-06-20 18:11:11 -06:00
Daz DeBoer
67f42d16a1
Write Job Summary HTML directly
This allows more control over the table layout, including centering of column content.
2022-06-19 10:42:34 -06:00
Daz DeBoer
56036f8577
Improve rendering of Job Summary 2022-06-19 09:40:27 -06:00
Daz DeBoer
df4c1902a6
Extract common functionality for recording build results 2022-06-15 08:29:55 -06:00
Daz DeBoer
132237ba05
Capture failure to publish build scan in results 2022-06-15 08:08:41 -06:00
Daz DeBoer
3d091fa7a8
Move initscripts into src/resources/init-scripts 2022-06-11 09:33:38 -06:00
Daz DeBoer
f3e4903860
Check that job summary support is available
Fixes #319
2022-06-09 09:26:30 -06:00
Daz DeBoer
93c31ca3b5
Don't fail if the file-to-delete no longer exists
Fixes #308
2022-06-06 15:35:57 -06:00
Daz DeBoer
7a15005377
Avoid printing "reason unknown" for extract entries
This was happening when the main Gradle User Home entry was not saved due to
having an unchanged cache key.

Fixes #309
2022-06-06 15:07:13 -06:00
Daz DeBoer
8096e65e0a
Better error reporting when file deletion fails
- Include file name in all logging
- Log inital attempts at debug to avoid noise
- Include output of 'jps -lm' when final attempt fails
2022-06-06 11:52:46 -06:00
Daz DeBoer
9cd70b5460
Report cache entry path for duplicate entry save 2022-06-06 08:48:03 -06:00
Daz DeBoer
63bcd47c1b
Allow Job Summary generation to be disabled 2022-06-06 07:13:23 -06:00
Daz DeBoer
213bb63776
Use java to determine user.home dir
Although convenient, the os.homedir() function can return a different value
that the 'user.home' SystemProperty in Java. The latter is used to locate
the Gradle User Home directory.

By switching to use Java to determine the value for 'user.home', we can use
the same process as Gradle to determine Gradle User Home.

Fixes #207
2022-06-05 22:13:36 -06:00
Daz DeBoer
0b5047ec4d
Prevent duplicate JSON being written to build-results 2022-06-05 21:55:11 -06:00
Daz DeBoer
52ebf2721a
Allow daemons to run across workflow steps
Now that we are stopping all Gradle daemons in the post-job action,
we can allow daemon processes to be re-used across steps in a workflow job.

Fixes #113
2022-06-05 09:20:54 -06:00
Daz DeBoer
aea6ddad5b
Attempt to stop all daemons on Job completion 2022-06-05 09:07:34 -06:00
Daz DeBoer
e644288a42
Use build-results file for root project dirs
Instead of using a separate mechanism and init script, reuse the information
captured in the build-results file.
2022-06-05 08:34:07 -06:00
Daz DeBoer
e234151ec9
Add more information to captured build results
- Root project dir: will allow us to replace project-root-capture init script
- Gradle home dir: will allow us to stop all started daemons
2022-06-05 08:18:25 -06:00
Daz DeBoer
3f2d9cde44
Capture build results when GE plugin is applied but no build-scan is published 2022-06-05 00:32:29 -06:00
Daz DeBoer
6001bc9edc
Improve build badgee for builds without scan links 2022-06-05 00:32:00 -06:00
Daz DeBoer
5203a0b09d
Capture build results when config-cache is enabled
When enabled, the configuration-cache will cause the build to fail when a
`buildFinished` listener is added. Instead, use a BuildService to listen for task
failures and to write the results on build completion.
2022-06-05 00:29:42 -06:00
Daz DeBoer
500607bc35
Capture build-results without build-scan publication
The `buildScanPublished` is only called when a build scan is published by the build.
Support other invocations by adding a `buildFinished` listener.
2022-06-05 00:28:24 -06:00
Daz DeBoer
748dc30fdc
Support and test Gradle 3.5.1
Fix build-scan-capture.init.gradle so that it applies to versions 3.+,
and include this version in test coverage.
2022-06-05 00:26:21 -06:00
Daz DeBoer
ece69c52b2
Save project-root-list in RUNNER_TEMP dir
This feels better than saving in Gradle User Home and is consistent
with where the build results are written.
2022-06-05 00:24:57 -06:00
Daz DeBoer
b02f4f1968
Disable cache-read-only when cache-write-only is set 2022-06-04 11:28:12 -06:00
Daz DeBoer
4fa0803854
Improve layout and formatting of Job Summary
- Move entire caching summary into details section
- Use core.summary.addTable for all table creation
- Include cache status in clickable description
2022-06-04 10:55:26 -06:00
Daz DeBoer
dff0fe1b20
Remove debug output from init script 2022-06-03 13:51:36 -06:00
Daz DeBoer
ae74c01440
Use a BuildService to always collect project root
Using `settingsEvaluated` meant that the project root was not recorded
when the build was run with a config-cache hit. This meant that the subsequent
build would not restore the config-cache, resulting in a cache miss.

In order to avoid issues running the init script on older versions of Gradle
the project-collection is extracted into a separate groovy file that is only
applied conditionally on Gradle 7 or higher.
2022-06-03 13:51:36 -06:00
Daz DeBoer
cde0632795
Update comment for accuracy 2022-06-03 07:50:08 -06:00
Daz DeBoer
6cc033f2b3
Make build-result-capture script compatible with config-cache 2022-06-03 07:12:23 -06:00
Daz DeBoer
7b79b2a752
Report on read-only / write-only cache 2022-06-02 23:16:52 -06:00
Daz DeBoer
143774290e
Add more details to cache summary report 2022-06-02 22:39:55 -06:00
Daz DeBoer
a9a5bcf180
Move writing of cache report into job-summary.ts 2022-06-02 22:39:09 -06:00
Daz DeBoer
f9c8fcf79f
Adding caching details to Job Summary 2022-06-02 14:21:10 -06:00
Daz DeBoer
86e82987ba
Write job summary in post action
- Save build results in file encoded as JSON
- Read all build results in post action and render as table in job summary
2022-06-02 12:58:49 -06:00
Daz DeBoer
8f3c97e3f1
Extract action state-tracking out of caches.ts 2022-06-02 12:20:01 -06:00
Daz DeBoer
d95713bd5d
Extract init scripts into resource files 2022-06-02 11:53:33 -06:00
Daz DeBoer
28b774ebdb
Allow override of sections of cache key
These internal env vars are designed primarily for testing,
but may also prove useful for folks to experiment with more optimal
caching setups.
2022-05-29 09:32:24 -06:00
Daz DeBoer
be62f7d934
Merge branch 'releases/v2.1'
* releases/v2.1:
  Build outputs
  Remove downloaded wrapper zips before caching
  Fix typo in worklow step
2022-05-29 09:23:36 -06:00
Daz DeBoer
f2bb19b43a
Remove downloaded wrapper zips before caching
The wrapper zip files are redundant, and not required after extraction.
Gradle 7.5+ will delete these automatically, but we delete them for older
versions to avoid caching the wrapper distributions twice.

Sinc the `gradle-home-cache-excludes` parameter does not support
wildcards, we remove them explicitly.
2022-05-29 08:49:36 -06:00
Daz DeBoer
7645e6e536
Replace emoji characters with markdown 2022-05-24 16:37:15 +02:00
Daz DeBoer
646074d659
Write build scan link to GHA job summary
The new Job Summary functionality permits better rendering of build
results, including clickable build scan links
2022-05-24 15:01:44 +02:00
Daz DeBoer
d63db6a05e
Remove unclickable buildScan link from failure
Build scan links will be rendered in GHA Job Summary.
2022-05-24 15:01:08 +02:00
Daz DeBoer
0e24fa1975
Save/restore exploded Gradle dist rather than zip
To save space, future versions of Gradle are likely to delete the downloaded distribution
after extracting it. See gradle/gradle#3605 and gradle/gradle#19495.
To cater for this we will now save/restore the extracted distribution rather than the
downloaded zip file.
2022-04-04 21:43:31 -06:00
Daz DeBoer
0d13054264
Log stack trace for cache errors 2022-03-18 13:56:40 -06:00
Daz DeBoer
53e57a851c
Make Gradle Home detection compatible with MacOS
MacOS runners are initialized with a Gradle User Home directory including
the `~/.gradle/notifications` directory. This was causing the action to skip
restoring the Gradle User Home on MacOS.

This fix limits the pre-existing GUH check to the `~/.gradle/caches` directory
which isn't pre-initialized in the runner.

Fixes #155
2022-02-03 09:46:37 -07:00
Daz DeBoer
702bb97ecb
Do not overwrite existing gradle.properties 2022-01-24 15:18:11 -07:00
Daz DeBoer
f75a3e8436
Make build-scan notice a WARNING for failed builds 2022-01-21 08:09:32 -07:00
Daz DeBoer
c349fa5b1f
Do not hide ReserveCacheError failures
When the target entry already exists, we are unable to save. Ensuring this situation
is logged helps make the logs more understandable.
2022-01-21 08:08:32 -07:00
Daz DeBoer
08d5b40ca5
Add experimental support for 'cache-write-only'
There may be cases where it a "fresh" cache entry would be beneficial,
for example if the Gradle User Home cache entry grows over time.

This setting would run the build as if no prior cache entry exists.
2022-01-20 15:04:11 -07:00
Daz DeBoer
0a5ede19a9
Improve cache-reporting when entry already exists 2022-01-20 15:04:11 -07:00
Daz DeBoer
a23ac1d61c
Add experimental support for 'strict-match' caching
By default, the action will attempt to restore a Gradle User Home
cache entry from a different set of matrix inputs (or a different Job entirely)
if an existing entry is not found for the current Job (including matrix inputs).

By specifying the experimental `gradle-home-cache-strict-match` parameter, a user
can avoid this fuzzy matching and ensure that a job execution starts with an
empty Gradle User Home if no entry from a prior execution is found.
2022-01-20 15:03:54 -07:00
Daz DeBoer
7dee0f45c2
Fix check for pre-existing Gradle User Home 2022-01-17 14:44:32 -07:00
Daz DeBoer
50ca2bca83
Improve messages for cache-disabled scenario 2022-01-17 14:44:32 -07:00
Daz DeBoer
3aa7bfe163
Initialize pre-existing Gradle User Home 2022-01-17 14:44:32 -07:00
Daz DeBoer
06d64212d3
Initialize the Gradle User Home even when caching is disabled 2022-01-17 14:29:11 -07:00
Daz DeBoer
42faf281e6
Include names of requested tasks in build scan notice
This should make it easier to differentiate between build scan notices for different
Gradle invocations in the same Job.

Fixes: #124
2021-12-31 10:34:53 -07:00
Daz DeBoer
13d93c1ca1
Check executable bit on Gradle script
Fixes #76
2021-12-30 21:40:27 -07:00
Daz DeBoer
76ea8a76b2
Treat configuration-cache as an extracted entry
Instead of using a fallback strategy to locate a configuration-cache entry
based on the current job and git SHA, these entries are now keyed based on their
file content with the keys persisted in the primary Gradle User Home entry.

This removes the chance of having a configuration-cache entry restored that is
incompatible with the restored Gradle User Home state, and makes the logic easier
to understand.

This change involved a fairly major refactor, with the CacheEntryExtractor being
split out from the primary cache implementation, and adding a separate extractor
implementation for configuration-cache.
2021-12-30 16:03:02 -07:00
Daz DeBoer
12fc52a49a
Combine java-toolchain entry definitions
- Remove configuration parameter for cache-entry-definitions. This allows richer modelling of extracted entries.
- Include both *.zip and *.tar.gz in entry definition for java-toolchains.
2021-12-30 16:03:02 -07:00
Daz DeBoer
c157d0a332
Cache downloaded Java Toolchains
Due to limitations with the way extracted entries are defined, a separate entry
is defined for *nix and windows.

Fixes #33
2021-12-30 16:02:02 -07:00
Daz DeBoer
0e8b9655a0
Allow action to be used without Gradle invocation
If the user supplies no 'arguments' parameter, the action will function as a
'setup-gradle' action, adding Gradle to the PATH and enabling other features
without actually running a Gradle build.

Any subsequent Gradle invocations in the workflow will benefit from:
- Save/restore of Gradle User Home
- Save/restore of configuration-cache data
- Capture of build-scan URLs

These features are enabled via Gradle User Home, so any Gradle invocation that
uses the same Gradle User Home will be included.
2021-12-17 10:29:58 -07:00
Daz DeBoer
e1f84aa44d
Restore/save configuration-cache data in first action
Previously, the action was restoring/saving the configuration-cache data for each
step that applied the action. In order to support Gradle invocations that are _not_
managed by the action, the configuration-cache restore is now performed in the initial
action step, and save is performed in the final post-action step.

The build root directories are recorded for each invocation via an init script.
2021-12-08 15:09:27 -07:00
Daz DeBoer
1041604f29
Ensure save/restore only on first action step
Instead of relying on the separate cache implementations to check for the
existence of cached products, we now explicitly track whether or not the execution
is the first time the action has been invoked for a job.
2021-12-08 15:09:27 -07:00
Daz DeBoer
253d6427fd
Extract cache-reporting into separate file
Cache reporting is self-contained enough that it deserves some separation.
2021-12-08 15:09:26 -07:00
Daz DeBoer
887e1a09ab
Include original error in log messages 2021-12-08 14:44:57 -07:00
Daz DeBoer
37f2880a8a Cache wrapper zips and generated jars individually
Using a single cache entry for all files of a type is necessary to avoid
overloading the cache service. However, this mechanism is not very efficient
for certain artifacts like wrapper zips and generated-gradle-jars, where the
same individual files are often shared between different jobs.

With this change, any configured file patterns that do not end in '*' will
be cached as individual files. At this time this includes downloaded wrapper
zips and generated-gradle-jars.

Fixes #78
2021-12-08 14:05:13 -07:00
Daz DeBoer
b88c4086b9
Don't overwrite title in build-scan notice 2021-12-08 13:07:52 -07:00