From e352255f0590a689d29d619807b02e5afb43593c Mon Sep 17 00:00:00 2001 From: Zach Wolfenbarger Date: Wed, 11 May 2022 14:35:52 -0500 Subject: [PATCH 1/5] Run Github Actions via Lita --- handlers/deployment.rb | 35 ++++++++++++++++++++++++++++++++++- lib/zooniverse_github.rb | 8 ++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/handlers/deployment.rb b/handlers/deployment.rb index a4288d7..c21a2ea 100644 --- a/handlers/deployment.rb +++ b/handlers/deployment.rb @@ -34,9 +34,11 @@ class Deployment < Handler # and in use for all K8s deployed services route(/^(deploy)\s*(.*)/, :tag_deploy, command: true, help: {"deploy REPO" => "Updates the production-release tag on zooniverse/REPO"}) route(/^(migrate)\s*(.*)/, :tag_migrate, command: true, help: {"migrate REPO" => "Updates the production-migrate tag on zooniverse/REPO"}) - route(/^(status\s*all)/, :status_all, command: true, help: {'staus all' => 'Returns the deployment status for all previously deployed $REPO_NAMES.'}) + route(/^(status\s*all)/, :status_all, command: true, help: {'status all' => 'Returns the deployment status for all previously deployed $REPO_NAMES.'}) route(/^(status|version)\s+(?!all)(.+)/, :status, command: true, help: {'status REPO_NAME' => 'Returns the state of commits not deployed for the $REPO_NAME.'}) route(/^(history)\s(.+)/, :commit_history, command: true, help: {'history REPO_NAME' => 'Returns the last deployed commit history (max 10) .'}) + route(/^(static)\s(.+)/, :static, command: true, help: {'static ACTION' => 'Runs the specified static repo action'}) + route(/^(action)\s(.+)/, :action, command: true, help: {'action REPO FILE BRANCH' => 'Runs the specified repo action on the specified branch'}) def clear_static_cache(response) build_jenkins_job(response, "Clear static cache") @@ -92,6 +94,37 @@ def commit_history(response) response.reply(output) end + def static(response) + workflow_actions = { + nginx: 'deploy_nginx.yml', + ingress: 'apply_ingresses.yml' + } + workflow = response.matches[0][1] + begin + config.github.run_workflow('static', workflow_actions[workflow], 'master') + rescue Octokit::NotFound => e + response.reply ("Repo or workflow not found") + rescue Octokit::UnprocessableEntity + response.reply ("Branch not found") + else + response.reply("Static repo action '#{workflow}' successfully initiated.") + end + end + + def action(response) + repo, filename, branch = response.matches[0][1].split(' ') + + begin + config.github.run_workflow(repo, filename, 'master') + rescue Octokit::NotFound => e + response.reply ("Repo or workflow not found") + rescue Octokit::UnprocessableEntity + response.reply ("Branch not found") + else + response.reply("Action #{filename} on #{repo}/#{branch} successfully initiated.") + end + end + private # ensure no leading/trailing whitespaces etc in the name diff --git a/lib/zooniverse_github.rb b/lib/zooniverse_github.rb index addd825..84cb49f 100644 --- a/lib/zooniverse_github.rb +++ b/lib/zooniverse_github.rb @@ -120,6 +120,14 @@ def get_dependabot_issues(last_repo_listed) octokit_client.post '/graphql', { query: query }.to_json end + def run_workflow(repo_name, workflow, branch, inputs={}) + params = { + ref: 'refs/heads/#{branch}', + inputs: inputs + } + octokit_client.post("/repos/zooniverse/#{repo_name}/actions/workflows/#{workflow}/dispatches", params) + end + private def query_without_after From 50cb21119c8f9f083aa072834e247db84f99fa8f Mon Sep 17 00:00:00 2001 From: Zach Wolfenbarger Date: Thu, 19 May 2022 15:54:58 -0500 Subject: [PATCH 2/5] Remove generic action runner, rename ingress application route --- handlers/deployment.rb | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/handlers/deployment.rb b/handlers/deployment.rb index c21a2ea..24b3694 100644 --- a/handlers/deployment.rb +++ b/handlers/deployment.rb @@ -25,6 +25,7 @@ class Deployment < Handler command: true, help: { 'rebuild subject-set-search API' => 'Rebuild subject-set-search API with new data' } ) + route(/^(apply ingresses)\s(.+)/, :apply_ingresses, command: true, help: {'apply ingresses' => 'Runs the apply_ingresses action in the static repo'}) # New K8s deployment template # updates the production release tag on the supplied repo (\s*.(*)) @@ -37,8 +38,6 @@ class Deployment < Handler route(/^(status\s*all)/, :status_all, command: true, help: {'status all' => 'Returns the deployment status for all previously deployed $REPO_NAMES.'}) route(/^(status|version)\s+(?!all)(.+)/, :status, command: true, help: {'status REPO_NAME' => 'Returns the state of commits not deployed for the $REPO_NAME.'}) route(/^(history)\s(.+)/, :commit_history, command: true, help: {'history REPO_NAME' => 'Returns the last deployed commit history (max 10) .'}) - route(/^(static)\s(.+)/, :static, command: true, help: {'static ACTION' => 'Runs the specified static repo action'}) - route(/^(action)\s(.+)/, :action, command: true, help: {'action REPO FILE BRANCH' => 'Runs the specified repo action on the specified branch'}) def clear_static_cache(response) build_jenkins_job(response, "Clear static cache") @@ -94,34 +93,15 @@ def commit_history(response) response.reply(output) end - def static(response) - workflow_actions = { - nginx: 'deploy_nginx.yml', - ingress: 'apply_ingresses.yml' - } - workflow = response.matches[0][1] + def apply_ingresses(response) begin - config.github.run_workflow('static', workflow_actions[workflow], 'master') + config.github.run_workflow('static', 'apply_ingresses.yml', 'master') rescue Octokit::NotFound => e response.reply ("Repo or workflow not found") rescue Octokit::UnprocessableEntity response.reply ("Branch not found") else - response.reply("Static repo action '#{workflow}' successfully initiated.") - end - end - - def action(response) - repo, filename, branch = response.matches[0][1].split(' ') - - begin - config.github.run_workflow(repo, filename, 'master') - rescue Octokit::NotFound => e - response.reply ("Repo or workflow not found") - rescue Octokit::UnprocessableEntity - response.reply ("Branch not found") - else - response.reply("Action #{filename} on #{repo}/#{branch} successfully initiated.") + response.reply("Ingress application successfully initiated.") end end From afb35a6514c6da4c25b50c4e20d9a61613e77479 Mon Sep 17 00:00:00 2001 From: Zach Wolfenbarger Date: Wed, 1 Jun 2022 16:28:38 -0500 Subject: [PATCH 3/5] Apply tag with 'apply ingresses' command --- handlers/deployment.rb | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/handlers/deployment.rb b/handlers/deployment.rb index 24b3694..2b9b7eb 100644 --- a/handlers/deployment.rb +++ b/handlers/deployment.rb @@ -25,7 +25,7 @@ class Deployment < Handler command: true, help: { 'rebuild subject-set-search API' => 'Rebuild subject-set-search API with new data' } ) - route(/^(apply ingresses)\s(.+)/, :apply_ingresses, command: true, help: {'apply ingresses' => 'Runs the apply_ingresses action in the static repo'}) + route(/^apply ingresses/, :apply_ingresses, command: true, help: {"apply ingresses" => "Applies the ingress templates in the static repo"}) # New K8s deployment template # updates the production release tag on the supplied repo (\s*.(*)) @@ -70,6 +70,12 @@ def tag_migrate(response) response.reply("Deployment tag '#{tag}' was successfully updated for #{repo_name}.") end + def apply_ingresses(response) + deploy_ref = 'tags/production-ingresses' + update_tag('zooniverse/static', deploy_ref) + response.reply("Ingress tag was successfully updated for static.") + end + def status(response) repo_name = repo_name_without_whitespace(response.matches[0][1]) response.reply(status_response(repo_name)) @@ -93,18 +99,6 @@ def commit_history(response) response.reply(output) end - def apply_ingresses(response) - begin - config.github.run_workflow('static', 'apply_ingresses.yml', 'master') - rescue Octokit::NotFound => e - response.reply ("Repo or workflow not found") - rescue Octokit::UnprocessableEntity - response.reply ("Branch not found") - else - response.reply("Ingress application successfully initiated.") - end - end - private # ensure no leading/trailing whitespaces etc in the name From 76807dbdfc543ba588c2533e533ef91fe6d0c350 Mon Sep 17 00:00:00 2001 From: Zach Wolfenbarger Date: Wed, 1 Jun 2022 17:12:24 -0500 Subject: [PATCH 4/5] Small refactor --- handlers/deployment.rb | 3 +-- lib/zooniverse_github.rb | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/handlers/deployment.rb b/handlers/deployment.rb index 2b9b7eb..ee543aa 100644 --- a/handlers/deployment.rb +++ b/handlers/deployment.rb @@ -71,8 +71,7 @@ def tag_migrate(response) end def apply_ingresses(response) - deploy_ref = 'tags/production-ingresses' - update_tag('zooniverse/static', deploy_ref) + config.github.update_production_ingresses_tag response.reply("Ingress tag was successfully updated for static.") end diff --git a/lib/zooniverse_github.rb b/lib/zooniverse_github.rb index 84cb49f..d117edb 100644 --- a/lib/zooniverse_github.rb +++ b/lib/zooniverse_github.rb @@ -114,6 +114,10 @@ def update_production_migrate_tag(repo_name) update_tag(full_repo_name, deploy_ref) end + def update_production_ingresses_tag + update_tag('zooniverse/static', 'tags/production-ingresses') + end + def get_dependabot_issues(last_repo_listed) query = last_repo_listed ? query_with_after(last_repo_listed) : query_without_after From 3a1eb716aab3f8e24a60b6ff2842f30068c28aeb Mon Sep 17 00:00:00 2001 From: Zach Wolfenbarger Date: Thu, 2 Jun 2022 14:38:05 -0500 Subject: [PATCH 5/5] No workflow running from lita after all --- lib/zooniverse_github.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/zooniverse_github.rb b/lib/zooniverse_github.rb index d117edb..db918d7 100644 --- a/lib/zooniverse_github.rb +++ b/lib/zooniverse_github.rb @@ -124,14 +124,6 @@ def get_dependabot_issues(last_repo_listed) octokit_client.post '/graphql', { query: query }.to_json end - def run_workflow(repo_name, workflow, branch, inputs={}) - params = { - ref: 'refs/heads/#{branch}', - inputs: inputs - } - octokit_client.post("/repos/zooniverse/#{repo_name}/actions/workflows/#{workflow}/dispatches", params) - end - private def query_without_after