From b9329686539769a7ae88cf8b3029873c6b2af2f9 Mon Sep 17 00:00:00 2001 From: filipe Date: Mon, 4 Dec 2023 15:48:07 -0300 Subject: [PATCH] DAT-16380 (#20) * 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. --- README.md | 4 ++-- .../sdk/maven/plugins/InstallSnapshotCliMojo.java | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 91f12bd..e1e5c3c 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/src/main/java/liquibase/sdk/maven/plugins/InstallSnapshotCliMojo.java b/src/main/java/liquibase/sdk/maven/plugins/InstallSnapshotCliMojo.java index c00dfbe..c191883 100644 --- a/src/main/java/liquibase/sdk/maven/plugins/InstallSnapshotCliMojo.java +++ b/src/main/java/liquibase/sdk/maven/plugins/InstallSnapshotCliMojo.java @@ -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()) { @@ -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")) { @@ -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 -> { @@ -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");