From 8dcaa28a413ede12aa5407c493d616706b67ccca Mon Sep 17 00:00:00 2001 From: Niklas van Schrick Date: Fri, 17 Nov 2023 19:47:18 +0100 Subject: [PATCH] Prefix branches with a common prefix for this action --- lib/action/context.rb | 4 ++-- lib/action/step/clone_project.rb | 2 +- lib/action/step/prepare_context.rb | 3 ++- lib/action/step/push_branch_to_gitlab.rb | 2 +- lib/action/step/remove_branch_from_gitlab.rb | 2 +- lib/action/step/trigger_pipeline.rb | 2 +- test/await_healthy.sh | 10 ---------- test/healthcheck_and_setup.sh | 5 ----- 8 files changed, 8 insertions(+), 22 deletions(-) diff --git a/lib/action/context.rb b/lib/action/context.rb index 17bc666..9e34d64 100644 --- a/lib/action/context.rb +++ b/lib/action/context.rb @@ -2,9 +2,9 @@ module GitlabPipelineAction class Context - attr_accessor :gh_project, :gh_sha, :gh_ref, :gh_ref_name, :gh_server_url, + attr_accessor :gh_project, :gh_sha, :gh_ref, :gh_server_url, :gl_server_url, :gl_project_id, :gl_project_path, :gl_runner_token, - :gl_api_token, :gl_pipeline, + :gl_api_token, :gl_pipeline, :gl_branch_name, :git_repository, :git_path, :gitlab_client, :docker_runner_container diff --git a/lib/action/step/clone_project.rb b/lib/action/step/clone_project.rb index d8b4af2..94f8cde 100644 --- a/lib/action/step/clone_project.rb +++ b/lib/action/step/clone_project.rb @@ -11,7 +11,7 @@ def execute context.git_repository.fetch('origin', ref: context.gh_ref) context.git_repository.checkout(context.gh_sha) - context.git_repository.branch(context.gh_ref_name).checkout + context.git_repository.branch(context.gl_branch_name).checkout end end end diff --git a/lib/action/step/prepare_context.rb b/lib/action/step/prepare_context.rb index 3bce9b0..ee8307a 100644 --- a/lib/action/step/prepare_context.rb +++ b/lib/action/step/prepare_context.rb @@ -7,9 +7,10 @@ def execute context.gh_project = ENV.fetch('GITHUB_REPOSITORY', nil) context.gh_sha = ENV.fetch('GITHUB_SHA', nil) context.gh_ref = ENV.fetch('GITHUB_REF', nil) - context.gh_ref_name = ENV.fetch('GITHUB_REF_NAME', nil) context.gh_server_url = ENV.fetch('GITHUB_SERVER_URL', nil) + context.gl_branch_name = "glpa/#{ENV.fetch('GITHUB_REF_NAME', nil)}" + context.gl_server_url = ENV.fetch('INPUT_GL_SERVER_URL', nil) context.gl_project_id = ENV.fetch('INPUT_GL_PROJECT_ID', nil) context.gl_runner_token = ENV.fetch('INPUT_GL_RUNNER_TOKEN', nil) diff --git a/lib/action/step/push_branch_to_gitlab.rb b/lib/action/step/push_branch_to_gitlab.rb index f264335..4929501 100644 --- a/lib/action/step/push_branch_to_gitlab.rb +++ b/lib/action/step/push_branch_to_gitlab.rb @@ -5,7 +5,7 @@ module Step class PushBranchToGitlab < Base def execute context.git_repository.add_remote(GITLAB_REMOTE, gitlab_remote_url) - context.git_repository.push(GITLAB_REMOTE, context.gh_ref_name, push_option: ['ci.skip']) + context.git_repository.push(GITLAB_REMOTE, context.gl_branch_name, push_option: ['ci.skip']) end private diff --git a/lib/action/step/remove_branch_from_gitlab.rb b/lib/action/step/remove_branch_from_gitlab.rb index 22d9d57..cdf2811 100644 --- a/lib/action/step/remove_branch_from_gitlab.rb +++ b/lib/action/step/remove_branch_from_gitlab.rb @@ -4,7 +4,7 @@ module GitlabPipelineAction module Step class RemoveBranchFromGitlab < Base def execute - context.gitlab_client.delete_branch(context.gl_project_id, context.gh_ref_name) + context.gitlab_client.delete_branch(context.gl_project_id, context.gl_branch_name) end end end diff --git a/lib/action/step/trigger_pipeline.rb b/lib/action/step/trigger_pipeline.rb index 303e0ed..db9d52e 100644 --- a/lib/action/step/trigger_pipeline.rb +++ b/lib/action/step/trigger_pipeline.rb @@ -6,7 +6,7 @@ class TriggerPipeline < Base def execute context.gl_pipeline = context.gitlab_client.create_pipeline( context.gl_project_id, - context.gh_ref_name + context.gl_branch_name ) puts "Triggered: #{context.gl_pipeline.web_url}" diff --git a/test/await_healthy.sh b/test/await_healthy.sh index d0088dd..ab8bdcc 100755 --- a/test/await_healthy.sh +++ b/test/await_healthy.sh @@ -23,13 +23,3 @@ echo "GitLab is healthy at $GITLAB_BASE_URL" curl --silent --show-error --header "Private-Token: TEST1234567890123456" "$GITLAB_BASE_URL/api/v4/version" echo -printf 'Waiting for Test project to be imported' - -import_status="" -while [[ "$import_status" != "finished" ]]; do - printf '.' - import_status=$(curl --silent --show-error --header "Private-Token: TEST1234567890123456" "$GITLAB_BASE_URL/api/v4/projects/1000" | jq -r .import_status) - sleep 5 -done - -echo diff --git a/test/healthcheck_and_setup.sh b/test/healthcheck_and_setup.sh index e09d82f..4bae89f 100755 --- a/test/healthcheck_and_setup.sh +++ b/test/healthcheck_and_setup.sh @@ -57,11 +57,6 @@ test -f $done || { printf ').execute;' printf 'while project.reload.import_status != "finished"; sleep 5; end;' - printf 'Projects::UpdateService.new(' - printf 'project,' - printf 'Users::Internal.admin_bot,' - printf 'default_branch: "testing-project-default-branch"' - printf ').execute' ) | gitlab-rails console touch $done