Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default polling mode and first waiting time #596

Merged
merged 2 commits into from
Oct 2, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/itself.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ jobs:
retry-method: 'equal_intervals'
min-interval-seconds: 10
attempt-limits: 60
default_logic:
needs: [equal_intervals]
runs-on: ubuntu-latest
if: ${{ github.actor != 'dependabot[bot]' && github.actor != 'renovate[bot]' }}
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: ./
wait-list:
runs-on: ubuntu-latest
if: ${{ github.actor != 'dependabot[bot]' && github.actor != 'renovate[bot]' }}
Expand Down
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ I mainly use this action for below use-case when they should run after multiple
- [Auto approve and merge dependabot PRs without PAT(Personal Access Token)](https://github.com/kachick/ruby-ulid/blob/ad4c6090d7835d80ff02a1a5f57d6e9ae11a85d3/.github/workflows/merge-bot-pr.yml#L21-L26)
- [Auto approve and merge renovatebot PRs without `platformAutomerge` feature](https://github.com/kachick/ruby-ulid/blob/ad4c6090d7835d80ff02a1a5f57d6e9ae11a85d3/.github/workflows/merge-bot-pr.yml#L46-L50)

### Success pattern with default inputs, it behaves as `Exponential Backoff And Jitter`.
### Success pattern with `Exponential Backoff And Jitter`.

<img src="./assets/log-v1.2.0-exponential_backoff.png?raw=true" alt="Example of actual log - success in default" width=900>

### Error pattern with specified `equal_intervals` and `attempt-limits`.
### Error pattern with `equal_intervals` and `attempt-limits`.

<img src="./assets/log-v1.2.0-equal_intervals_and_attempt-limits.png?raw=true" alt="Example of actual log - error in equal_intervals_and_attempt-limits" width=900>

Expand All @@ -44,8 +44,9 @@ You can change the token, polling interval, allow/deny list and turns early-exit
```yaml
with:
github-token: "${{ secrets.YOUR_PAT }}"
wait-seconds-before-first-polling: '30' # default '10'
min-interval-seconds: '300' # default '30'
retry-method: 'equal_intervals' # default 'exponential_backoff'
retry-method: 'exponential_backoff' # default 'equal_intervals'
early-exit: 'false' # default 'true'
# lists should be given with JSON formatted array, do not specify both wait-list and skip-list
# Each items should have "workflowFile" field and they can optinaly have "jobName" field
Expand All @@ -70,16 +71,17 @@ with:

Full list of the changeable parameters

| NAME | DESCRIPTION | TYPE | REQUIRED | DEFAULT | OPTIONS |
| ---------------------- | ------------------------------------------------------------------------------- | -------- | -------- | --------------------- | ---------------------------------------- |
| `github-token` | The GITHUB_TOKEN secret. You can use PAT if you want. | `string` | `true` | `${{ github.token }}` | |
| `min-interval-seconds` | Wait this interval or the multiplied value (and jitter) for next polling | `number` | `false` | `30` | |
| `retry-method` | How to wait for next polling | `string` | `false` | `exponential_backoff` | `exponential_backoff`, `equal_intervals` |
| `early-exit` | Stop rest pollings if faced at least 1 bad condition | `bool` | `false` | `true` | |
| `attempt-limits` | Stop rest pollings after this attempts even if other jobs are not yet completed | `number` | `false` | `1000` | |
| `wait-list` | This action will not wait for items other than this list | `string` | `false` | `[]` | |
| `skip-list` | This action will not wait for items on this list | `string` | `false` | `[]` | |
| `dry-run` | Avoid requests for tests | `bool` | `false` | `false` | |
| NAME | DESCRIPTION | TYPE | REQUIRED | DEFAULT | OPTIONS |
| ----------------------------------- | ------------------------------------------------------------------------------- | -------- | -------- | --------------------- | ---------------------------------------- |
| `github-token` | The GITHUB_TOKEN secret. You can use PAT if you want. | `string` | `true` | `${{ github.token }}` | |
| `wait-seconds-before-first-polling` | Wait this interval before first polling | `number` | `false` | `10` | |
| `min-interval-seconds` | Wait this interval or the multiplied value (and jitter) for next polling | `number` | `false` | `30` | |
| `retry-method` | How to wait for next polling | `string` | `false` | `equal_intervals` | `exponential_backoff`, `equal_intervals` |
| `early-exit` | Stop rest pollings if faced at least 1 bad condition | `bool` | `false` | `true` | |
| `attempt-limits` | Stop rest pollings after this attempts even if other jobs are not yet completed | `number` | `false` | `1000` | |
| `wait-list` | This action will not wait for items other than this list | `string` | `false` | `[]` | |
| `skip-list` | This action will not wait for items on this list | `string` | `false` | `[]` | |
| `dry-run` | Avoid requests for tests | `bool` | `false` | `false` | |

Below is a typical usecase. Assume test jobs defined in another workflow.

Expand Down
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ inputs:
description: 'The GITHUB_TOKEN secret'
required: true
default: ${{ github.token }}
wait-seconds-before-first-polling:
description: 'Wait this seconds before first polling'
required: false
default: '10'
min-interval-seconds:
description: 'Wait this interval or the multiplied value (and jitter) for next polling'
required: false
Expand All @@ -20,7 +24,7 @@ inputs:
retry-method:
description: 'How to wait for next polling'
required: false
default: 'exponential_backoff'
default: 'equal_intervals'
attempt-limits:
description: 'Stop rest pollings after this limits even if other jobs are not yet completed'
required: false
Expand Down
17 changes: 14 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12961,6 +12961,10 @@ async function run() {
owner,
repo
};
const waitSecondsBeforeFirstPolling = parseInt(
(0, import_core2.getInput)("wait-seconds-before-first-polling", { required: true, trimWhitespace: true }),
10
);
const minIntervalSeconds = parseInt(
(0, import_core2.getInput)("min-interval-seconds", { required: true, trimWhitespace: true }),
10
Expand Down Expand Up @@ -12989,6 +12993,7 @@ async function run() {
triggeredCommitSha: commitSha,
runId,
repositoryInfo,
waitSecondsBeforeFirstPolling,
minIntervalSeconds,
retryMethod,
attemptLimits,
Expand All @@ -13015,9 +13020,15 @@ async function run() {
(0, import_core2.setFailed)(errorMessage(`reached to given attempt limits "${attemptLimits}"`));
break;
}
const msec = getIdleMilliseconds(retryMethod, minIntervalSeconds, attempts);
(0, import_core2.info)(`Wait ${readableDuration(msec)} before next polling to reduce API calls.`);
await wait(msec);
if (attempts === 1) {
const initialMsec = waitSecondsBeforeFirstPolling * 1e3;
(0, import_core2.info)(`Wait ${readableDuration(initialMsec)} before first polling.`);
await wait(initialMsec);
} else {
const msec = getIdleMilliseconds(retryMethod, minIntervalSeconds, attempts);
(0, import_core2.info)(`Wait ${readableDuration(msec)} before next polling to reduce API calls.`);
await wait(msec);
}
(0, import_core2.startGroup)(`Polling ${attempts}: ${(/* @__PURE__ */ new Date()).toISOString()}`);
const report = await fetchOtherRunStatus(
githubToken,
Expand Down
19 changes: 16 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ async function run(): Promise<void> {
repo,
} as const;

const waitSecondsBeforeFirstPolling = parseInt(
getInput('wait-seconds-before-first-polling', { required: true, trimWhitespace: true }),
10,
);
const minIntervalSeconds = parseInt(
getInput('min-interval-seconds', { required: true, trimWhitespace: true }),
10,
Expand Down Expand Up @@ -77,6 +81,7 @@ async function run(): Promise<void> {
triggeredCommitSha: commitSha,
runId,
repositoryInfo,
waitSecondsBeforeFirstPolling,
minIntervalSeconds,
retryMethod,
attemptLimits,
Expand Down Expand Up @@ -109,9 +114,17 @@ async function run(): Promise<void> {
setFailed(errorMessage(`reached to given attempt limits "${attemptLimits}"`));
break;
}
const msec = getIdleMilliseconds(retryMethod, minIntervalSeconds, attempts);
info(`Wait ${readableDuration(msec)} before next polling to reduce API calls.`);
await wait(msec);

if (attempts === 1) {
const initialMsec = waitSecondsBeforeFirstPolling * 1000;
info(`Wait ${readableDuration(initialMsec)} before first polling.`);
await wait(initialMsec);
} else {
const msec = getIdleMilliseconds(retryMethod, minIntervalSeconds, attempts);
info(`Wait ${readableDuration(msec)} before next polling to reduce API calls.`);
await wait(msec);
}

startGroup(`Polling ${attempts}: ${(new Date()).toISOString()}`);

const report = await fetchOtherRunStatus(
Expand Down