Skip to content

Commit

Permalink
DAT-16380 (#20)
Browse files Browse the repository at this point in the history
* Fix docs.

* Implement specific workflowId for downloading artifacts

Added a parameter for workflowId in the downloadArtifact method. Previously, the method was using the global workflowId for both the main workflow and the Pro workflow, which would cause issues if these workflows had different IDs. Now, the Pro workflow uses its own specific workflowId to download artifacts, ensuring the correct artifact is downloaded for each respective workflow.
  • Loading branch information
filipelautert authored Dec 4, 2023
1 parent d4c7d9a commit b932968
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ By default, it expects it to be an upgrade, unless `allowInstall` / `liquibase.s
The branch to use is set via the liquibase.sdk.branchSearch setting. To install a branch from a fork, reference it as `owner:branch-name`

Examples:
- `mvn org.liquibase.ext:liquibase-sdk-maven-plugin:0.9:install-cli "-Dliquibase.sdk.branchSearch=local-branch,master"` to install the code from `liquibase/liquibase:local-branch` and if that branch doesn't exist fall back to `master`
- `mvn org.liquibase.ext:liquibase-sdk-maven-plugin:0.9:install-cli "-Dliquibase.sdk.branchSearch=fork-owner:their-branch"` to install the code from `fork-owner/liquibase:their-branch`
- `mvn org.liquibase.ext:liquibase-sdk-maven-plugin:0.9:install-snapshot-cli "-Dliquibase.sdk.branchSearch=local-branch,master"` to install the code from `liquibase/liquibase:local-branch` and if that branch doesn't exist fall back to `master`
- `mvn org.liquibase.ext:liquibase-sdk-maven-plugin:0.9:install-snapshot-cli "-Dliquibase.sdk.branchSearch=fork-owner:their-branch"` to install the code from `fork-owner/liquibase:their-branch`

All available arguments:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public class InstallSnapshotCliMojo extends AbstractGitHubMojo {
@Parameter(property = "liquibase.sdk.workflowId")
protected String workflowId;

@Parameter(property = "liquibase.sdk.proWorkflowId")
protected String proWorkflowId;

public void execute() throws MojoExecutionException, MojoFailureException {
File liquibaseHomeDir = new File(liquibaseHome);
if (liquibaseHomeDir.exists()) {
Expand Down Expand Up @@ -70,7 +73,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
//replace everything in the CLI except liquibase-commercial.jar
String headBranchFilename = matchingLabel.replaceFirst(".*:", "").replaceAll("[^a-zA-Z0-9\\-_.]", "_");

File file = downloadArtifact(github, repo, matchingLabel, "liquibase-zip-" + headBranchFilename);
File file = downloadArtifact(github, repo, matchingLabel, "liquibase-zip-" + headBranchFilename, workflowId);

ArchiveUtil.unzipCli(file, liquibaseHomeDir, log, path -> {
if (path.getName().equals("internal/lib/liquibase-commercial.jar")) {
Expand All @@ -81,7 +84,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
} else {
//upgrading an extension
if (repo.equals("liquibase/liquibase-pro")) {
File file = downloadArtifact(github, repo, matchingLabel, "liquibase-commercial-modules");
File file = downloadArtifact(github, repo, matchingLabel, "liquibase-commercial-modules", proWorkflowId);
ArchiveUtil.unzipCli(file, liquibaseHomeDir, log,
path -> path.getName().endsWith("liquibase-commercial-0-SNAPSHOT.jar"),
path -> {
Expand All @@ -103,8 +106,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
}

private File downloadArtifact(GitHubClient github, String repo, String matchingLabel, String artifactName) throws IOException, MojoFailureException {
File file = github.downloadArtifact(repo, matchingLabel, artifactName, GitHubClient.getWorkflowId(repo, workflowId), skipFailedBuilds);
private File downloadArtifact(GitHubClient github, String repo, String matchingLabel, String artifactName, String currentWorkflowId) throws IOException, MojoFailureException {
File file = github.downloadArtifact(repo, matchingLabel, artifactName, GitHubClient.getWorkflowId(repo, currentWorkflowId), skipFailedBuilds);

if (file == null) {
throw new MojoFailureException("Cannot find " + artifactName + ".zip");
Expand Down

0 comments on commit b932968

Please sign in to comment.