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

Support Configuration Cache #244

Merged
merged 3 commits into from
Oct 23, 2023
Merged

Support Configuration Cache #244

merged 3 commits into from
Oct 23, 2023

Conversation

rpalcolea
Copy link
Member

This should support config cache by following https://docs.gradle.org/8.4/userguide/configuration_cache.html#config_cache:requirements:external_processes when executing Git

All the integration tests apply the following now:

        new File(projectDir, 'gradle.properties') << '''org.gradle.configuration-cache=true'''.stripIndent()

which will enforce configuration cache during tests across all the specs

* This is temporary until config cache serialization is fixed when writing tests
* More in https://github.com/gradle/gradle/issues/25898
*/
tasks.withType(Test).configureEach {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is temporary until gradle/gradle#25898 is addressed

@@ -48,6 +48,9 @@ abstract class GitVersioningIntegrationSpec extends IntegrationSpec {
build/
gradle.properties'''.stripIndent()

// Enable configuration cache :)
new File(projectDir, 'gradle.properties') << '''org.gradle.configuration-cache=true'''.stripIndent()
Copy link
Member Author

Choose a reason for hiding this comment

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

This enables config cache for all integration tests

@rpalcolea rpalcolea force-pushed the configuration-cache-support branch 3 times, most recently from cc294a2 to 08b937a Compare October 20, 2023 21:03
import org.gradle.api.tasks.TaskAction
import org.gradle.work.DisableCachingByDefault

@DisableCachingByDefault(because = "Publishing related tasks should not be cacheable")
Copy link
Member

Choose a reason for hiding this comment

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

💯

ByteArrayOutputStream error = new ByteArrayOutputStream()
List<String> commandLineArgs = ["git", "--git-dir=${rootDir.absolutePath}/.git".toString(), "--work-tree=${rootDir.absolutePath}".toString()]
commandLineArgs.addAll(args)
execOperations.exec {
Copy link
Member

Choose a reason for hiding this comment

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

Nice! 🎉

abstract ExecOperations getExecOperations()

@CompileDynamic
String executeGitCommand(Object ... args) {
Copy link
Member

Choose a reason for hiding this comment

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

Love how this takes args

* These read only git commands use ValueSource approach for configuration cache
* @see {@link https://docs.gradle.org/8.4/userguide/configuration_cache.html#config_cache:requirements:external_processes}
*/
abstract class GitReadCommand implements ValueSource<String, GitCommandParameters> {
Copy link
Member

Choose a reason for hiding this comment

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

💯 on documenting all these classes for usability and posterity


/**
* These git commands involve creating or pushing tags
* Because these happen at task execution level, we are fine with not using ValueSource
Copy link
Member

Choose a reason for hiding this comment

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

Great call-out! Thank you

@rpalcolea rpalcolea merged commit 336673b into main Oct 23, 2023
6 checks passed
@rpalcolea rpalcolea deleted the configuration-cache-support branch October 23, 2023 19:01
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