Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/test-increased-wait-time.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
4 changes: 0 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion docs/github-action.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
20 changes: 6 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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));
Expand All @@ -49,20 +45,16 @@ 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
};

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) {
Expand Down