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

Wait for Required Checks on Protected Branches #269

Open
wants to merge 4 commits into
base: releases/v5
Choose a base branch
from

Conversation

jasuno
Copy link

@jasuno jasuno commented Sep 4, 2024

Description

This PR adds functionality to wait for all required checks to pass before pushing changes when operating on a protected branch. This enhancement improves the reliability of our conventional changelog action, especially in environments with strict branch protection rules.

Changes

  • Added a new input is-protected-branch to indicate if the current branch is protected.
  • Implemented a waitForRequiredChecks function to poll the status of required checks.
  • Modified the main run function to incorporate the waiting logic when pushing to a protected branch.
  • Updated the README to document the new is-protected-branch input.

How to Use

To enable this feature, set the is-protected-branch input to true in your workflow:

Copy link
Owner

@TriPSs TriPSs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks!

Comment on lines +276 to +298
async function waitForRequiredChecks(branch) {
const octokit = github.getOctokit(core.getInput('github-token'))
const { owner, repo } = github.context.repo

while (true) {
const { data: checks } = await octokit.rest.checks.listForRef({
owner,
repo,
ref: branch,
})

const pendingChecks = checks.check_runs.filter(check => check.status !== 'completed')

if (pendingChecks.length === 0) {
core.info('All required checks have passed')
break
}

core.info(`Waiting for ${pendingChecks.length} checks to complete...`)
await new Promise(resolve => setTimeout(resolve, 30000)) // Wait for 30 seconds before checking again
}
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this into the helpers folder?

@bj00rn
Copy link
Contributor

bj00rn commented Nov 28, 2024

@jasuno @TriPSs this is a killer feature! Can we get this merged?

Looks like @actions/github dependency is missing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants