Skip to content

Decommission the old smilecdr stack #52

Decommission the old smilecdr stack

Decommission the old smilecdr stack #52

Workflow file for this run

name: PR Merged
on:
pull_request:
types: [closed]
branches:
- main
permissions:
contents: read
issues: write
pull-requests: write
actions: write
jobs:
# ============================================================================
# JOB: Update related issue after auto-generated PR is merged
# ============================================================================
post-merge-update:
name: Update Issue After PR Merge
runs-on: arc-runner-set
if: |
github.event.pull_request.merged == true &&
contains(github.event.pull_request.labels.*.name, 'auto-pr-created')
steps:
- name: Extract issue number from PR body
id: extract
uses: actions/github-script@v7
with:
script: |
const prBody = context.payload.pull_request.body || '';
// Extract issue number from "Related to #123" or "Issue #123"
const issueMatch = prBody.match(/#(\d+)/);
const issueNumber = issueMatch ? issueMatch[1] : null;
core.setOutput('issue_number', issueNumber);
- name: Check if deploy-immediately label is present
id: check_deploy
if: steps.extract.outputs.issue_number
run: |
HAS_DEPLOY_LABEL="${{ contains(github.event.pull_request.labels.*.name, 'deploy-immediately') }}"
echo "has_deploy_label=$HAS_DEPLOY_LABEL" >> $GITHUB_OUTPUT
- name: Extract target nodes from PR
id: extract_nodes
if: steps.extract.outputs.issue_number && steps.check_deploy.outputs.has_deploy_label == 'true'
uses: actions/github-script@v7
with:
script: |
const prBody = context.payload.pull_request.body || '';
const nodesMatch = prBody.match(/\*\*(?:Target|Requested) Nodes\*\*[:\s]+([^\n]+)/i);
let nodes = 'all';
if (nodesMatch) {
nodes = nodesMatch[1].trim().replace(/\*\*/g, '').replace(/`/g, '');
}
core.setOutput('nodes', nodes);
- name: Trigger deployment workflow
if: steps.extract.outputs.issue_number && steps.check_deploy.outputs.has_deploy_label == 'true'
uses: actions/github-script@v7
with:
script: |
const issueNumber = parseInt('${{ steps.extract.outputs.issue_number }}');
const nodes = '${{ steps.extract_nodes.outputs.nodes }}';
const prNumber = context.payload.pull_request.number;
console.log(`Triggering deployment for issue #${issueNumber} with nodes: ${nodes}`);
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'reload-ig-config.yml',
ref: 'main',
inputs: {
base_url: 'https://smile.sparked-fhir.com',
nodes: nodes,
package_source: 'config',
dry_run: 'false',
force_reinstall: 'false',
issue_number: issueNumber.toString()
}
});
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: `**Deployment Triggered**
PR #${prNumber} has been merged and your request for immediate deployment is being fulfilled.
**Deployment Details:**
- Target Nodes: \`${nodes}\`
- Package Source: Configuration files
You will receive another comment with deployment results shortly.
**Next Steps:**
1. Wait for deployment to complete (typically 2-5 minutes)
2. Verify the deployment meets your acceptance criteria
3. Comment with your verification results
4. A repo admin will mark the issue as complete
**Note**: Please do not close this issue manually. It will remain open for verification.`
});
- name: Post deployment options (no immediate deployment)
if: steps.extract.outputs.issue_number && steps.check_deploy.outputs.has_deploy_label != 'true'
uses: actions/github-script@v7
with:
script: |
const issueNumber = parseInt('${{ steps.extract.outputs.issue_number }}');
const prNumber = context.payload.pull_request.number;
const prTitle = context.payload.pull_request.title;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: `## PR #${prNumber} Merged Successfully
Your requested changes have been approved and merged into the main branch.
**What was merged:**
${prTitle}
**Deployment Options:**
### Option A: Immediate Deployment
A repo admin can trigger immediate deployment:
- **Time**: 2-5 minutes
- **Downtime**: None (rolling update)
- **Risk**: Low (can be rolled back)
To deploy immediately, a repo admin can run the "Reload IG Packages" workflow manually.
### Option B: Wait for Next Server Restart
Changes will be applied automatically on the next scheduled server restart:
- **Time**: Variable (hours to days)
- **Risk**: Zero (changes are already in configuration)
- **Effort**: None required
---
**A repo admin will decide when to deploy based on urgency and current server status.**
Once deployed, you'll be asked to verify the deployment meets your acceptance criteria.
**Note**: Please do not close this issue manually. It will remain open for verification.`
});
- name: Handle failure
if: failure() && steps.extract.outputs.issue_number
uses: actions/github-script@v7
with:
script: |
const issueNumber = parseInt('${{ steps.extract.outputs.issue_number }}');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: `**Post-Merge Automation Failed**
The automation encountered an error while processing the merged PR.
**Error details**: Check the [workflow run](${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}) for details.
**Next steps**:
- A maintainer will review and handle deployment manually
- You will be notified when deployment occurs
This issue has been labeled \`needs-manual-intervention\`.`
});
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels: ['needs-manual-intervention']
});