From 8199f4ff7ad5df5522f17cba78405ccfb2e6b4df Mon Sep 17 00:00:00 2001 From: Igor Rodionov Date: Thu, 20 Jul 2023 13:51:55 +0300 Subject: [PATCH] Get rid of max timeout input --- .../workflows/test-increased-wait-time.yml | 1 - README.md | 1 - action.yml | 4 ---- docs/github-action.md | 1 - index.js | 20 ++++++------------- 5 files changed, 6 insertions(+), 21 deletions(-) diff --git a/.github/workflows/test-increased-wait-time.yml b/.github/workflows/test-increased-wait-time.yml index 2126d19..933faae 100644 --- a/.github/workflows/test-increased-wait-time.yml +++ b/.github/workflows/test-increased-wait-time.yml @@ -58,7 +58,6 @@ jobs: status: continuous-delivery/${{ needs.setup.outputs.environment }}.test-app expected_state: "success" token: ${{ github.token }} - check-timeout: 120 check-retry-count: 5 check-retry-interval: 20 diff --git a/README.md b/README.md index 036a342..d70163b 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,6 @@ Checks GitHub API for a given commit and look the commit status. |------|-------------|---------|----------| | check-retry-count | Check retry count | 5 | false | | check-retry-interval | Check retry interval (in seconds) | 10 | false | -| check-timeout | Timeout check (in seconds) | 600 | false | | expected\_state | Commit status state wait for. Valid values 'success', 'error', 'failure', 'pending' | success | false | | repository | Repository | N/A | true | | sha | Commit SHA | N/A | true | diff --git a/action.yml b/action.yml index 65a4fa3..34757de 100644 --- a/action.yml +++ b/action.yml @@ -5,10 +5,6 @@ branding: icon: 'clock' color: 'white' inputs: - check-timeout: - description: 'Timeout check (in seconds)' - required: false - default: "600" check-retry-count: description: 'Check retry count' required: false diff --git a/docs/github-action.md b/docs/github-action.md index a5960e3..76a8b42 100644 --- a/docs/github-action.md +++ b/docs/github-action.md @@ -6,7 +6,6 @@ |------|-------------|---------|----------| | check-retry-count | Check retry count | 5 | false | | check-retry-interval | Check retry interval (in seconds) | 10 | false | -| check-timeout | Timeout check (in seconds) | 600 | false | | expected\_state | Commit status state wait for. Valid values 'success', 'error', 'failure', 'pending' | success | false | | repository | Repository | N/A | true | | sha | Commit SHA | N/A | true | diff --git a/index.js b/index.js index 28d8511..1ee9d87 100644 --- a/index.js +++ b/index.js @@ -3,10 +3,12 @@ const github = require('@actions/github'); const repoToken = core.getInput('token'); const client = github.getOctokit(repoToken); +const check_retry_count = core.getInput('check-retry-count'); +const check_retry_interval = core.getInput('check-retry-interval'); + // Function to wait for a specific commit status to become a success -async function waitForCommitStatusSuccess(owner, repo, commitSha, statusContext, lookup, options = {}) { - const { timeout = 300000, retryCount = 10, retryInterval = 5000 } = options; - const startTime = Date.now(); +async function waitForCommitStatus(owner, repo, commitSha, statusContext, lookup, options = {}) { + const { retryCount = 10, retryInterval = 5000 } = options; let attemptCount = 0; @@ -29,12 +31,6 @@ async function waitForCommitStatusSuccess(owner, repo, commitSha, statusContext, attemptCount++; - const elapsedTime = Date.now() - startTime; - if (elapsedTime >= timeout) { - console.log(`Timeout reached. Exiting...`); - return false; - } - console.log(`Waiting for commit status "${statusContext}" to become a success...`); await new Promise((resolve) => setTimeout(resolve, retryInterval)); @@ -49,12 +45,8 @@ const main = async function() { const sha = core.getInput('sha'); const status = core.getInput('status'); const expected_state = core.getInput('expected_state'); - const check_timeout = core.getInput('check-timeout'); - const check_retry_count = core.getInput('check-retry-count'); - const check_retry_interval = core.getInput('check-retry-interval'); const options = { - timeout: 1000 * check_timeout, // Convert from seconds to milliseconds retryCount: check_retry_count, // Retry 5 times before giving up retryInterval: 1000 * check_retry_interval // Convert from seconds to milliseconds }; @@ -62,7 +54,7 @@ const main = async function() { owner = repository.split("/")[0] repo = repository.split("/")[1] - const test = await waitForCommitStatusSuccess(owner, repo, sha, status, expected_state, options) + const test = await waitForCommitStatus(owner, repo, sha, status, expected_state, options) .then((result) => { console.log("Done waiting."); if (result) {