diff --git a/README.md b/README.md index 19ccd65..d9fdce4 100644 --- a/README.md +++ b/README.md @@ -299,6 +299,28 @@ jobs: running-workflow-name: wait-for-check-regexp check-regexp: .?-task ``` + ### Ignore-checks + To selectively filter checks and ignore specific ones, you can specify the ignore-checks option with a list of comma-separated check names to be ignored. + Example of use: + ```yaml + name: Wait using check-regexp + on: + push: + + jobs: + wait-for-check-regexp: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Wait on tests + uses: ./ + with: + ref: ${{ github.sha }} + repo-token: ${{ secrets.GITHUB_TOKEN }} + running-workflow-name: wait-for-check-regexp + ignore-checks: label1,label2 + ``` ### Wait interval (optional, default: 10) As it could be seen in many examples, there's a parameter `wait-interval`, and sets a time in seconds to be waited between requests to the GitHub API. The default time is 10 seconds. diff --git a/action.yml b/action.yml index 5a79c79..a15d491 100644 --- a/action.yml +++ b/action.yml @@ -7,6 +7,10 @@ inputs: description: "Array of allowed conclusions" required: false default: success,skipped + ignore-checks: + description: "Array of ignore checks" + required: false + default: "" check-name: description: "A name of a check that has to pass" required: false @@ -65,6 +69,7 @@ runs: shell: bash env: ALLOWED_CONCLUSIONS: ${{ inputs.allowed-conclusions }} + IGNORE_CHECKS: ${{ inputs.ignore-checks }} CHECK_NAME: ${{ inputs.check-name }} CHECK_REGEXP: ${{ inputs.check-regexp }} REF: ${{ inputs.ref }} diff --git a/app/services/github_checks_verifier.rb b/app/services/github_checks_verifier.rb index 1156fd1..66a6d61 100644 --- a/app/services/github_checks_verifier.rb +++ b/app/services/github_checks_verifier.rb @@ -15,6 +15,7 @@ class GithubChecksVerifier < ApplicationService config_accessor(:check_regexp) { "" } config_accessor(:allowed_conclusions) { ["success", "skipped"] } config_accessor(:verbose) { true } + config_accessor(:ignore_checks){[]} def call wait_for_checks @@ -47,6 +48,8 @@ def log_checks(checks, msg) def apply_filters(checks) checks.reject! { |check| check.name == workflow_name } + checks.reject! { |check| ignore_checks.include?(check.name) } + log_checks(checks, "Checks after ignore checks filter:") checks.select! { |check| check.name == check_name } if check_name.present? log_checks(checks, "Checks after check_name filter:") apply_regexp_filter(checks) diff --git a/app/spec/services/github_checks_verifier_spec.rb b/app/spec/services/github_checks_verifier_spec.rb index 5037b31..5d648ec 100644 --- a/app/spec/services/github_checks_verifier_spec.rb +++ b/app/spec/services/github_checks_verifier_spec.rb @@ -139,6 +139,18 @@ service.send(:apply_filters, checks) expect(checks.map(&:name)).to all(eq "check_name") end + + it "filters out only ignore_checks" do + checks = [ + OpenStruct.new(name: "check_name1", status: "queued"), + OpenStruct.new(name: "check_name2", status: "queued"), + OpenStruct.new(name: "other_check", status: "queued") + ] + + service.config.ignore_checks = ["check_name1,check_name2"] + service.send(:apply_filters, checks) + expect(checks.map(&:name)).to all(eq "other_check") + end it "does not filter by check_name if it's empty" do checks = [ @@ -163,7 +175,18 @@ expect(checks.map(&:name)).not_to include("workflow_name") end - + + it "does not filter if ignore checks are empty" do + checks = [ + OpenStruct.new(name: "test1", status: "completed", conclusion: "success"), + OpenStruct.new(name: "test2", status: "completed", conclusion: "skipped") + ] + service.config.ignore_checks = [] + service.send(:apply_filters, checks) + + expect(checks.size).to eq 2 + end + it "apply the regexp filter" do checks = [ OpenStruct.new(name: "test", status: "pending"), diff --git a/entrypoint.rb b/entrypoint.rb index 1793097..43c8529 100755 --- a/entrypoint.rb +++ b/entrypoint.rb @@ -11,9 +11,12 @@ wait = ENV["WAIT_INTERVAL"] workflow_name = ENV["RUNNING_WORKFLOW_NAME"] api_endpoint = ENV.fetch("API_ENDPOINT", "") +ignore_checks = ENV["IGNORE_CHECKS"] + GithubChecksVerifier.configure do |config| config.allowed_conclusions = allowed_conclusions.split(",").map(&:strip) + config.ignore_checks = ignore_checks.split(",").map(&:strip) config.check_name = check_name config.check_regexp = check_regexp config.client = Octokit::Client.new(auto_paginate: true)