diff --git a/action.yml b/action.yml index 813261b..28c592a 100644 --- a/action.yml +++ b/action.yml @@ -3,9 +3,10 @@ name: "Wait on check" author: "progapandist" description: "Wait on a certain check to pass for commit" inputs: - ref: - description: "A git ref to be checked: branch/tag/commit sha" - required: true + allowed-conclusions: + description: "Array of allowed conclusions" + required: false + default: success,skipped check-name: description: "A name of a check that has to pass" required: false @@ -14,6 +15,9 @@ inputs: description: "Filter checks to wait using Regexp" required: false default: "" + ref: + description: "A git ref to be checked: branch/tag/commit sha" + required: true repo-token: description: "A GitHub token for the repo" required: false @@ -26,22 +30,23 @@ inputs: description: "Name of the workflow to be ignored (the one who is waiting for the rest)" required: false default: "" - allowed-conclusions: - description: "Array of allowed conclusions" + verbose: + description: "Print logs if true" required: false - default: success,skipped + default: true runs: using: "docker" image: "Dockerfile" args: - - ${{ inputs.ref }} + - ${{ inputs.allowed-conclusions }} - ${{ inputs.check-name }} - ${{ inputs.check-regexp }} + - ${{ inputs.ref }} - ${{ inputs.repo-token }} + - ${{ inputs.verbose }} - ${{ inputs.wait-interval }} - ${{ inputs.running-workflow-name }} - - ${{ inputs.allowed-conclusions }} branding: icon: "check-circle" color: "green" diff --git a/app/services/github_checks_verifier.rb b/app/services/github_checks_verifier.rb index f617678..10ba0dc 100644 --- a/app/services/github_checks_verifier.rb +++ b/app/services/github_checks_verifier.rb @@ -14,6 +14,7 @@ class GithubChecksVerifier < ApplicationService config_accessor(:wait) { 30 } # set a default config_accessor(:check_regexp) { "" } config_accessor(:allowed_conclusions) { ["success", "skipped"] } + config_accessor(:verbose) { true } def call wait_for_checks @@ -26,14 +27,28 @@ def call def query_check_status checks = client.check_runs_for_ref(repo, ref, {accept: "application/vnd.github.antiope-preview+json"}).check_runs - p checks # DEBUG + log_checks(checks, "Checks running on ref:") + apply_filters(checks) end + def log_checks(checks, msg) + return unless verbose + + puts msg + statuses = checks.map(&:status).uniq + statuses.each do |status| + print "Checks #{status}: " + puts checks.select { |check| check.status == status }.map(&:name).join(", ") + end + end + def apply_filters(checks) checks.reject! { |check| check.name == workflow_name } checks.select! { |check| check.name == check_name } if check_name.present? + log_checks(checks, "Checks after check_name filter:") apply_regexp_filter(checks) + log_checks(checks, "Checks after Regexp filter:") checks end diff --git a/entrypoint.rb b/entrypoint.rb index 7b57ea3..60b1cf5 100755 --- a/entrypoint.rb +++ b/entrypoint.rb @@ -2,17 +2,18 @@ require_relative "./app/services/github_checks_verifier.rb" require "octokit" -ref, check_name, check_regexp, token, wait, workflow_name, allowed_conclusions = ARGV +allowed_conclusions, check_name, check_regexp, ref, token, verbose, wait, workflow_name = ARGV GithubChecksVerifier.configure do |config| + config.allowed_conclusions = allowed_conclusions.split(',').map(&:strip) config.check_name = check_name config.check_regexp = check_regexp config.client = Octokit::Client.new(access_token: token) config.ref = ref config.repo = ENV["GITHUB_REPOSITORY"] + config.verbose = verbose config.wait = wait.to_i config.workflow_name = workflow_name - config.allowed_conclusions = allowed_conclusions.split(',').map(&:strip) end GithubChecksVerifier.call