diff --git a/.github/workflows/delete-release.yml b/.github/workflows/delete-release.yml new file mode 100644 index 0000000..2a35bdf --- /dev/null +++ b/.github/workflows/delete-release.yml @@ -0,0 +1,17 @@ +name: Delete Release +on: + workflow_dispatch: # manually run + inputs: + release_version: + description: 'Set the version of the tag/release to be removed' + required: true +jobs: + delete-release: + runs-on: ubuntu-latest + steps: + - uses: dev-drprasad/delete-tag-and-release@v0.2.0 + with: + delete_release: true # default: false + tag_name: ${{ github.event.inputs.release_version }} # tag name to delete + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 8340405..50314c7 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -16,13 +16,21 @@ jobs: steps: - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1.81.0 + with: + ruby-version: 2.7 # Not needed with a .ruby-version file - - uses: actions/setup-ruby@v1 + - name: Cache Ruby Gems + uses: actions/cache@v2 with: - ruby-version: '2.7' + path: vendor/bundle + key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }} + restore-keys: ${{ runner.os }}-gems- - - name: Install dependencies - run: bundle install + - name: Bundle Install + run: | + bundle config path vendor/bundle + bundle install --jobs 4 --retry 3 - name: Run tests run: cd app && bundle exec rspec diff --git a/.github/workflows/wait-for-check-without-token.yml b/.github/workflows/wait-for-check-without-token.yml new file mode 100644 index 0000000..9db3e9a --- /dev/null +++ b/.github/workflows/wait-for-check-without-token.yml @@ -0,0 +1,20 @@ +name: Wait for check name +on: + push: + workflow_dispatch: + +jobs: + wait-without-token: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Wait without token + uses: ./ + with: + ref: ${{ github.sha }} + wait-interval: 10 # seconds + running-workflow-name: wait-without-token + check-name: wait-on-me + + - name: Success + run: echo 'Success!' diff --git a/Gemfile b/Gemfile index a64699f..848e99f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } -gem "octokit", "~> 4.20" +gem "octokit", "~> 4.25" gem "activesupport", "~> 6.1.1" group :test, :development do diff --git a/Gemfile.lock b/Gemfile.lock index 9a717a2..6303398 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -13,22 +13,20 @@ GEM byebug (11.1.3) concurrent-ruby (1.1.7) diff-lcs (1.4.4) - faraday (1.3.0) - faraday-net_http (~> 1.0) - multipart-post (>= 1.2, < 3) - ruby2_keywords - faraday-net_http (1.0.1) + faraday (2.3.0) + faraday-net_http (~> 2.0) + ruby2_keywords (>= 0.0.4) + faraday-net_http (2.0.3) i18n (1.8.7) concurrent-ruby (~> 1.0) minitest (5.14.3) - multipart-post (2.1.1) - octokit (4.20.0) - faraday (>= 0.9) - sawyer (~> 0.8.0, >= 0.5.3) + octokit (4.25.0) + faraday (>= 1, < 3) + sawyer (~> 0.9) parallel (1.20.1) parser (3.0.2.0) ast (~> 2.4.1) - public_suffix (4.0.6) + public_suffix (4.0.7) rainbow (3.0.0) regexp_parser (2.1.1) rexml (3.2.5) @@ -60,10 +58,10 @@ GEM rubocop (>= 1.7.0, < 2.0) rubocop-ast (>= 0.4.0) ruby-progressbar (1.11.0) - ruby2_keywords (0.0.2) - sawyer (0.8.2) + ruby2_keywords (0.0.5) + sawyer (0.9.2) addressable (>= 2.3.5) - faraday (> 0.8, < 2.0) + faraday (>= 0.17.3, < 3) standard (1.1.7) rubocop (= 1.18.4) rubocop-performance (= 1.11.4) @@ -79,7 +77,7 @@ PLATFORMS DEPENDENCIES activesupport (~> 6.1.1) byebug - octokit (~> 4.20) + octokit (~> 4.25) rspec standard diff --git a/README.md b/README.md index bc58b79..460481a 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Wait for tests to succeed - uses: lewagon/wait-on-check-action@v0.2 + uses: lewagon/wait-on-check-action@v1.0.0 with: ref: ${{ github.ref }} check-name: 'Run tests' @@ -101,10 +101,10 @@ jobs: name: Deploy a new image runs-on: ubuntu-latest steps: - - uses: actions/checkout@master + - uses: actions/checkout@v2 - name: Wait for tests to succeed - uses: lewagon/wait-on-check-action@v0.2 + uses: lewagon/wait-on-check-action@v1.0.0 with: ref: master check-name: test @@ -188,7 +188,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Wait for other checks to succeed - uses: lewagon/wait-on-check-action@v0.2 + uses: lewagon/wait-on-check-action@v1.0.0 with: ref: ${{ github.ref }} running-workflow-name: 'Publish the package' @@ -212,7 +212,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Wait for tests to succeed - uses: lewagon/wait-on-check-action@v0.2 + uses: lewagon/wait-on-check-action@v1.0.0 with: ref: ${{ github.ref }} check-name: 'Run tests' @@ -221,6 +221,41 @@ jobs: allowed-conclusions: success,skipped,cancelled ... ``` + ### Using check-regexp + Similar to the `check-name` parameter, this filters the checks to be waited but using a Regular Expression (aka regexp) to match the check name (jobs..name) + + 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 + check-regexp: .?-task + ``` + + ### 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. + + ### Verbose (optional, default: true) + If true, it prints some logs to help understanding the process (checks found, filtered, conclussions, etc.) + +## Auto-pagination + +Since we are using Octokit for using GitHub API, we are subject to their limitations. One of them is the pagination max size: if we have more than 100 workflows running, the auto-pagination won't help. +More about Octokit auto-pagination can be found [here](https://octokit.github.io/octokit.rb/file.README.html#Pagination:~:text=get.data-,Auto%20Pagination,-For%20smallish%20resource) +The solution would be to fetch all pages to gather all running workflows if they're more than 100, but it's still no implemented. ## Tests diff --git a/action.yml b/action.yml index 28c592a..b5333e2 100644 --- a/action.yml +++ b/action.yml @@ -36,17 +36,38 @@ inputs: default: true runs: - using: "docker" - image: "Dockerfile" - args: - - ${{ inputs.allowed-conclusions }} - - ${{ inputs.check-name }} - - ${{ inputs.check-regexp }} - - ${{ inputs.ref }} - - ${{ inputs.repo-token }} - - ${{ inputs.verbose }} - - ${{ inputs.wait-interval }} - - ${{ inputs.running-workflow-name }} + using: "composite" + steps: + - uses: ruby/setup-ruby@v1.81.0 + with: + ruby-version: 2.7 # Not needed with a .ruby-version file + + - name: Cache Ruby Gems + uses: actions/cache@v2 + with: + path: ${{ github.action_path }} + key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }} + restore-keys: ${{ runner.os }}-gems- + + - name: Bundle Install + run: | + bundle install --jobs 4 --retry 3 + working-directory: ${{ github.action_path }} + shell: bash + + - run: | + ruby entrypoint.rb + working-directory: ${{ github.action_path }} + shell: bash + env: + ALLOWED_CONCLUSIONS: ${{ inputs.allowed-conclusions }} + CHECK_NAME: ${{ inputs.check-name }} + CHECK_REGEXP: ${{ inputs.check-regexp }} + REF: ${{ inputs.ref }} + REPO_TOKEN: ${{ inputs.repo-token }} + VERBOSE: ${{ inputs.verbose }} + WAIT_INTERVAL: ${{ inputs.wait-interval }} + RUNNING_WORKFLOW_NAME: ${{ inputs.running-workflow-name }} branding: icon: "check-circle" color: "green" diff --git a/app/services/github_checks_verifier.rb b/app/services/github_checks_verifier.rb index 10ba0dc..56f69a2 100644 --- a/app/services/github_checks_verifier.rb +++ b/app/services/github_checks_verifier.rb @@ -26,7 +26,9 @@ def call private def query_check_status - checks = client.check_runs_for_ref(repo, ref, {accept: "application/vnd.github.antiope-preview+json"}).check_runs + checks = client.check_runs_for_ref( + repo, ref, {accept: "application/vnd.github.antiope-preview+json"} + ).check_runs log_checks(checks, "Checks running on ref:") apply_filters(checks) diff --git a/entrypoint.rb b/entrypoint.rb index 080a5e8..fb28b2f 100755 --- a/entrypoint.rb +++ b/entrypoint.rb @@ -2,13 +2,21 @@ require_relative "./app/services/github_checks_verifier" require "octokit" -allowed_conclusions, check_name, check_regexp, ref, token, verbose, wait, workflow_name = ARGV +allowed_conclusions = ENV["ALLOWED_CONCLUSIONS"] +check_name = ENV["CHECK_NAME"] +check_regexp = ENV["CHECK_REGEXP"] +ref = ENV["REF"] +token = ENV["REPO_TOKEN"] +verbose = ENV["VERBOSE"] +wait = ENV["WAIT_INTERVAL"] +workflow_name = ENV["RUNNING_WORKFLOW_NAME"] 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.client = Octokit::Client.new(auto_paginate: true) + config.client.access_token = token unless token.empty? config.ref = ref config.repo = ENV["GITHUB_REPOSITORY"] config.verbose = verbose