Skip to content

Commit

Permalink
added feature to ignore checks fixed #38 (#80)
Browse files Browse the repository at this point in the history
Co-authored-by: Sébastien Saunier <seb@saunier.me>
  • Loading branch information
Omkar Khatavkar and ssaunier authored Dec 21, 2023
1 parent 4bdd45d commit 9924042
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }}
Expand Down
4 changes: 3 additions & 1 deletion app/services/github_checks_verifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -46,7 +47,8 @@ def log_checks(checks, msg)
end

def apply_filters(checks)
checks.reject! { |check| check.name == workflow_name }
checks.reject! { |check| [ignore_checks, workflow_name].flatten.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)
Expand Down
31 changes: 27 additions & 4 deletions app/spec/services/github_checks_verifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,21 @@
OpenStruct.new(name: "other_check", status: "queued")
]

service.config.check_name = "check_name"
service.config.ignore_checks = ["check_name"]
service.send(:apply_filters, checks)
expect(checks.map(&:name)).to all(eq "check_name")
expect(checks.map(&:name)).to all(eq "other_check")
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
Expand All @@ -146,7 +158,7 @@
OpenStruct.new(name: "other_check", status: "queued")
]

service.config.check_name = ""
service.config.ignore_checks = []
allow(service).to receive(:apply_regexp_filter).with(checks).and_return(checks)
service.send(:apply_filters, checks)

Expand All @@ -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"),
Expand Down
3 changes: 3 additions & 0 deletions entrypoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9924042

Please sign in to comment.