-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: add gradle Helm dependency update task #393
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...dle-plugin/src/main/java/com/hedera/fullstack/gradle/plugin/HelmDependencyUpdateTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (C) 2023 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hedera.fullstack.gradle.plugin; | ||
|
||
import com.hedera.fullstack.helm.client.HelmClient; | ||
import com.hedera.fullstack.helm.client.HelmClientBuilder; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Objects; | ||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.provider.Property; | ||
import org.gradle.api.tasks.Input; | ||
import org.gradle.api.tasks.Optional; | ||
import org.gradle.api.tasks.TaskAction; | ||
import org.gradle.api.tasks.options.Option; | ||
|
||
public abstract class HelmDependencyUpdateTask extends DefaultTask { | ||
@Input | ||
@Option(option = "chartName", description = "The name of the chart to run the dependency update against") | ||
public abstract Property<String> getChartName(); | ||
|
||
@Input | ||
@Optional | ||
@Option(option = "workingDirectory", description = "The working directory to run the dependency update from") | ||
public abstract Property<String> getWorkingDirectory(); | ||
|
||
@TaskAction | ||
void dependencyUpdate() { | ||
HelmClientBuilder helmClientBuilder = HelmClient.builder(); | ||
try { | ||
final String chartName = getChartName().getOrNull(); | ||
Objects.requireNonNull(chartName, "chartName must be set"); | ||
final String workingDirectory = getWorkingDirectory().getOrNull(); | ||
if (workingDirectory != null && !workingDirectory.isEmpty() && !workingDirectory.isBlank()) { | ||
Path workingDirectoryPath = Paths.get(workingDirectory); | ||
helmClientBuilder.workingDirectory(workingDirectoryPath); | ||
} | ||
HelmClient helmClient = helmClientBuilder.build(); | ||
helmClient.dependencyUpdate(chartName); | ||
} catch (Exception e) { | ||
this.getProject() | ||
.getLogger() | ||
.error( | ||
"HelmDependencyUpdateTask.dependencyUpdate() An ERROR occurred while running the dependency update: ", | ||
e); | ||
throw e; | ||
} | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...plugin/src/test/java/com/hedera/fullstack/gradle/plugin/HelmDependencyUpdateTaskTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (C) 2023 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hedera.fullstack.gradle.plugin; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import com.hedera.fullstack.helm.client.HelmConfigurationException; | ||
import java.io.File; | ||
import org.gradle.api.Project; | ||
import org.gradle.testfixtures.ProjectBuilder; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class HelmDependencyUpdateTaskTest { | ||
private static final String CHART = "../charts/hedera-network"; | ||
private static Project project; | ||
|
||
@BeforeAll | ||
static void beforeAll() { | ||
project = ProjectBuilder.builder().build(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Test Helm Dependency Update Task") | ||
void testDependencyUpdate() { | ||
HelmDependencyUpdateTask helmDependencyUpdateTask = project.getTasks() | ||
.create("helmDependencyUpdateTask", HelmDependencyUpdateTask.class, task -> { | ||
task.getChartName().set(CHART); | ||
task.getWorkingDirectory().set(new File(".").toPath().toString()); | ||
}); | ||
assertThat(helmDependencyUpdateTask.getChartName().get()).isEqualTo(CHART); | ||
helmDependencyUpdateTask.dependencyUpdate(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Test Helm Dependency Update Task with no chart name") | ||
void testDependencyUpdateWithNoChartName() { | ||
HelmDependencyUpdateTask helmDependencyUpdateTask = project.getTasks() | ||
.create("helmDependencyUpdateNoChartTask", HelmDependencyUpdateTask.class, task -> {}); | ||
assertThat(helmDependencyUpdateTask.getChartName().getOrNull()).isNull(); | ||
NullPointerException e = assertThrows(NullPointerException.class, helmDependencyUpdateTask::dependencyUpdate); | ||
assertThat(e.getMessage()).contains("chartName must be set"); | ||
} | ||
|
||
@Test | ||
@DisplayName("Test Helm Dependency Update Task with no bad working directory") | ||
void testDependencyUpdateWithBadWorkingDirectory() { | ||
HelmDependencyUpdateTask helmDependencyUpdateTask = project.getTasks() | ||
.create("helmDependencyUpdateBadWorkingDirectoryTask", HelmDependencyUpdateTask.class, task -> { | ||
task.getChartName().set(CHART); | ||
task.getWorkingDirectory().set("xyz"); | ||
}); | ||
assertThat(helmDependencyUpdateTask.getChartName().get()).isEqualTo(CHART); | ||
HelmConfigurationException e = | ||
assertThrows(HelmConfigurationException.class, helmDependencyUpdateTask::dependencyUpdate); | ||
assertThat(e.getMessage()).contains("No such file or directory"); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to put "../charts/hedera-network" in a variable that can be used across the modules and its build.gradle.kts file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
putting it in a variable is easy enough. However, this is the only place in gradle that it is used currently. It sounds like with your full cluster chart that this may not even get used with the gradle build script. We also have another PR that is about to merge that makes both fullstack-examples and fullstack-gradle-plugin separate projects.