diff --git a/gitea/download-previous-artifacts/action.yaml b/gitea/download-previous-artifacts/action.yaml index f3d1877..d5127f4 100644 --- a/gitea/download-previous-artifacts/action.yaml +++ b/gitea/download-previous-artifacts/action.yaml @@ -25,10 +25,10 @@ inputs: description: "Pattern of the artifacts to match. Supports wildcard or RegEx. Default: *" required: true default: "*" - artifactName: - description: "Name of the artifact when it is downloaded. If not specified, the artifact will be named what the artifact is named." + branchPattern: + description: "Branch of the workflow to match. Supports wildcard or RegEx. Default: ${{ github.ref }}" required: false - default: "" + default: "${{ github.ref }}" unzipDir: description: "Directory to unzip the artifacts into. If not specified, the artifacts will not be unzipped." required: false diff --git a/gitea/download-previous-artifacts/download-previous-artifacts.cs b/gitea/download-previous-artifacts/download-previous-artifacts.cs index 3dd91bd..ae359f9 100644 --- a/gitea/download-previous-artifacts/download-previous-artifacts.cs +++ b/gitea/download-previous-artifacts/download-previous-artifacts.cs @@ -45,9 +45,12 @@ if (repoParts.Length != 2) string repoOwner = repoParts[0]; string repoName = repoParts[1]; -string workflowPattern = configuration["workflowPattern"] ?? string.Empty; +string workflowPattern = configuration["workflowPattern"] ?? "*"; Regex workflowRegex = WildcardToRegex(workflowPattern); +string branchPattern = configuration["branchPattern"] ?? "*"; +Regex branchRegex = WildcardToRegex(branchPattern); + string artifactPattern = configuration["artifactPattern"] ?? "*"; Regex artifactRegex = WildcardToRegex(artifactPattern); @@ -101,7 +104,16 @@ if (!getWorkflowRunsApiResponse.TryOk(out ActionWorkflowRunsResponse workflowRun return 1; } -ActionWorkflowRun? actionWorkflowRun = workflowRunResponse.WorkflowRuns.FirstOrDefault(w => workflowRegex.IsMatch(w.Path.Split('@')[0])); +bool WorkflowMatchesBranch(ActionWorkflowRun workflowRun) +{ + string[] pathParts = workflowRun.Path.Split('@'); + if (pathParts.Length < 2) return false; + string workflowName = pathParts[0]; + string branch = pathParts[1]; + return workflowRegex.IsMatch(workflowName) && branchRegex.IsMatch(branch); +} + +ActionWorkflowRun? actionWorkflowRun = workflowRunResponse.WorkflowRuns.FirstOrDefault(WorkflowMatchesBranch); if (actionWorkflowRun is null) { Console.WriteLine("No matching workflow run found.");