From 952ea0901017fa7074ce2222e95e78bafd840eaa Mon Sep 17 00:00:00 2001 From: fargito Date: Wed, 27 Nov 2024 16:53:51 +0100 Subject: [PATCH 1/2] fix(gitlab): use correct ref for tag pipelines --- src/run/ci_provider/gitlab_ci/provider.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/run/ci_provider/gitlab_ci/provider.rs b/src/run/ci_provider/gitlab_ci/provider.rs index 31f22a82..205e2a77 100644 --- a/src/run/ci_provider/gitlab_ci/provider.rs +++ b/src/run/ci_provider/gitlab_ci/provider.rs @@ -32,8 +32,15 @@ impl TryFrom<&Config> for GitLabCIProvider { let repository = get_env_variable("CI_PROJECT_NAME")?; let ci_pipeline_source = get_env_variable("CI_PIPELINE_SOURCE")?; + let branch_name = get_env_variable("CI_COMMIT_REF_NAME")?; - let branch_ref = format!("refs/heads/{branch_name}"); + + // compute the branch or tag ref which mimics GitHub behavior + // CI_COMMIT_TAG is only present in pipelines for tags. + // See https://docs.gitlab.com/ee/ci/variables/predefined_variables.html + let branch_or_tag_ref = get_env_variable("CI_COMMIT_TAG") + .map(|tag_name| format!("refs/tags/{tag_name}")) + .unwrap_or(format!("refs/heads/{branch_name}")); // https://docs.gitlab.com/ee/ci/jobs/job_rules.html#ci_pipeline_source-predefined-variable let (event, ref_, base_ref, head_ref) = match ci_pipeline_source.as_str() { @@ -72,15 +79,20 @@ impl TryFrom<&Config> for GitLabCIProvider { } // For pipelines triggered by a Git push event, including for branches and tags. - "push" => (RunEvent::Push, branch_ref, Some(branch_name), None), + "push" => (RunEvent::Push, branch_or_tag_ref, Some(branch_name), None), // For scheduled pipelines. - "schedule" => (RunEvent::Schedule, branch_ref, Some(branch_name), None), + "schedule" => ( + RunEvent::Schedule, + branch_or_tag_ref, + Some(branch_name), + None, + ), // For pipelines created by using a trigger token or created via the GitLab UI. "trigger" | "web" => ( RunEvent::WorkflowDispatch, - branch_ref, + branch_or_tag_ref, Some(branch_name), None, ), From 44e5470f725811352883aef6e1387f8be2824a43 Mon Sep 17 00:00:00 2001 From: fargito Date: Wed, 27 Nov 2024 17:46:01 +0100 Subject: [PATCH 2/2] feat(gitlab): add support for pipelines triggered through the api --- src/run/ci_provider/gitlab_ci/provider.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/run/ci_provider/gitlab_ci/provider.rs b/src/run/ci_provider/gitlab_ci/provider.rs index 205e2a77..0d09d98f 100644 --- a/src/run/ci_provider/gitlab_ci/provider.rs +++ b/src/run/ci_provider/gitlab_ci/provider.rs @@ -89,8 +89,8 @@ impl TryFrom<&Config> for GitLabCIProvider { None, ), - // For pipelines created by using a trigger token or created via the GitLab UI. - "trigger" | "web" => ( + // For pipelines created with the api, using a trigger token or via the GitLab UI. + "trigger" | "web" | "api" => ( RunEvent::WorkflowDispatch, branch_or_tag_ref, Some(branch_name),