Skip to content

Create Deploy Review #4

Create Deploy Review

Create Deploy Review #4

name: Create Deploy Review
on:
workflow_run:
types: [completed]
workflows:
- Build and deploy ASP.Net Core app to Azure Web App - jobflow-api-staging
permissions:
contents: read
issues: write
pull-requests: read
jobs:
create-review-issue:
name: Create Deploy Review Issue
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const run = context.payload.workflow_run;
const sha = run.head_sha;
const branch = run.head_branch || 'master';
// Gather PR and commit info
let prTitle = '';
let prNumber = '';
let prUrl = '';
let commitMessages = [];
const prs = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner, repo,
commit_sha: sha
});
if (prs.data.length > 0) {
const pr = prs.data[0];
prTitle = pr.title;
prNumber = pr.number;
prUrl = pr.html_url;
const prCommits = await github.rest.pulls.listCommits({
owner, repo,
pull_number: pr.number
});
commitMessages = prCommits.data
.map(c => c.commit.message.split('\n')[0])
.filter(m => m);
}
// Close existing open deploy-review issues
const existing = await github.rest.issues.listForRepo({
owner, repo,
labels: 'deploy-review',
state: 'open'
});
for (const issue of existing.data) {
await github.rest.issues.update({
owner, repo,
issue_number: issue.number,
state: 'closed',
state_reason: 'not_planned'
});
}
// Build issue body
const commitLink = `[${sha.slice(0, 7)}](https://github.com/${owner}/${repo}/commit/${sha})`;
const prRef = prNumber ? `([#${prNumber}](${prUrl}))` : '';
const headerLine = `${commitLink}: ${prTitle} ${prRef}`.trim();
const bullets = commitMessages.length > 0
? commitMessages.map(m => `- ${m}`).join('\n')
: '- No commit details available';
const body = [
'### Staging deployed successfully — approve to deploy to production',
'',
`**Staging SHA:** ${commitLink}`,
`**Branch:** \`${branch}\``,
'',
headerLine,
'',
bullets,
'',
'---',
'',
'Comment **`approve`**, **`LGTM`**, or **`ship it`** to deploy the most recent `release-*` tag to production.',
'Comment **`deny`** or **`needs changes`** to reject.',
'',
'---',
`<!-- staging_sha:${sha} -->`
].join('\n');
// Ensure label exists
try {
await github.rest.issues.createLabel({
owner, repo,
name: 'deploy-review',
color: '0E8A16',
description: 'Production deployment review'
});
} catch (e) {
// Label already exists
}
await github.rest.issues.create({
owner, repo,
title: `✅ Staging deployed — approve ${sha.slice(0, 7)} for production`,
body,
labels: ['deploy-review']
});