Skip to content

Commit

Permalink
Merge pull request #42 from lewagon/fix/improve-logging
Browse files Browse the repository at this point in the history
Fix/improve logging
  • Loading branch information
matiasalbarello authored Aug 23, 2021
2 parents b9561bb + 5953ba2 commit a0f99ce
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
21 changes: 13 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"
17 changes: 16 additions & 1 deletion app/services/github_checks_verifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions entrypoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a0f99ce

Please sign in to comment.