Last active
March 26, 2025 17:07
-
-
Save MiroslavCsonka/73dc6e988a9883a5e7e357ec48daa00f to your computer and use it in GitHub Desktop.
Github Action with `gh signoff`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git add xyz.rb | |
git commit -m "A meaningful change" | |
# NOTE: The job has a 5-second waiting period since there's a delay between pushing and creating a new "signoff" GitHub check status. | |
git push && gh signoff |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jobs: | |
check-signoff: | |
runs-on: ubuntu-latest | |
outputs: | |
should-skip: ${{ steps.check.outputs.should-skip }} | |
steps: | |
- id: check | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
// Function to sleep for a given number of milliseconds | |
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); | |
// Function to check for signoff status | |
async function checkSignoff() { | |
// Get all check runs, including external ones | |
const { data: checksResponse } = await github.rest.checks.listForRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: context.sha, | |
filter: 'all' | |
}); | |
// Get all statuses | |
const { data: statusesResponse } = await github.rest.repos.listCommitStatusesForRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: context.sha | |
}); | |
// Look for signoff in both checks and statuses | |
const signoffCheck = checksResponse.check_runs.find(check => | |
check.name === 'signoff' && | |
check.status === 'completed' && | |
check.conclusion === 'success' | |
); | |
const signoffStatus = statusesResponse.find(status => | |
status.context === 'signoff' && | |
status.state === 'success' | |
); | |
return signoffCheck || signoffStatus; | |
} | |
// Try for 5 seconds, checking every second | |
let signoffResult = null; | |
for (let i = 0; i < 5; i++) { | |
console.log(`Attempt ${i + 1} to find successful signoff...`); | |
signoffResult = await checkSignoff(); | |
if (signoffResult) { | |
console.log('Found successful signoff:', JSON.stringify(signoffResult, null, 2)); | |
break; | |
} else { | |
if (i < 4) { | |
console.log('Successful signoff not found, waiting 1 second...'); | |
await sleep(1000); | |
} | |
} | |
} | |
const shouldSkip = !!signoffResult; | |
core.setOutput('should-skip', shouldSkip ? 'true' : 'false'); | |
skip-notification: | |
needs: check-signoff | |
if: needs.check-signoff.outputs.should-skip == 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- run: echo "All jobs skipped due to successful signoff" | |
rubocop: | |
needs: check-signoff | |
if: needs.check-signoff.outputs.should-skip != 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: ruby/setup-ruby@v1 | |
with: | |
bundler-cache: true | |
- run: bundle exec rubocop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment