You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kompass/.github/workflows/check-deployment.yml

82 lines
2.9 KiB
YAML

name: Check Deployment Readiness
on:
pull_request:
types: [labeled]
jobs:
check-and-deploy:
runs-on: ubuntu-latest
if: github.event.label.name == 'awaiting-deployment'
permissions:
actions: write
pull-requests: read
contents: write
steps:
- name: Check build workflow status
id: check
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request.number;
const headSha = context.payload.pull_request.head.sha;
console.log(`Checking build status for PR #${prNumber}, commit ${headSha}`);
// Use Check Runs API to get the status of the build workflow
const { data: checkRuns } = await github.rest.checks.listForRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: headSha,
check_name: 'build'
});
console.log(`Found ${checkRuns.total_count} check runs for 'build'`);
if (checkRuns.total_count === 0) {
console.log('No build check found for this commit');
core.setOutput('should_deploy', 'false');
core.setOutput('reason', 'No build check found');
return;
}
const buildCheck = checkRuns.check_runs[0];
console.log(`Build check status: ${buildCheck.status}, conclusion: ${buildCheck.conclusion}`);
// Check if build is still running
if (buildCheck.status !== 'completed') {
console.log('Build check is still running');
core.setOutput('should_deploy', 'false');
core.setOutput('reason', 'Build check is still running');
return;
}
// Check if build failed
if (buildCheck.conclusion !== 'success') {
console.log(`Build check failed with conclusion: ${buildCheck.conclusion}`);
core.setOutput('should_deploy', 'false');
core.setOutput('reason', `Build check ${buildCheck.conclusion}`);
return;
}
// Build completed successfully
console.log('Build check completed successfully, ready to deploy');
core.setOutput('should_deploy', 'true');
- name: Trigger deployment
if: steps.check.outputs.should_deploy == 'true'
uses: actions/github-script@v7
with:
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'deploy-pr.yml',
ref: context.payload.pull_request.head.ref,
inputs: {
pr_number: context.payload.pull_request.number.toString()
}
});
console.log('Deployment workflow triggered');