Skip to content

Update SSH installer documentation for post-quantum KEX hardening #5

Update SSH installer documentation for post-quantum KEX hardening

Update SSH installer documentation for post-quantum KEX hardening #5

name: Auto Delete Merged Branches
# This workflow automatically deletes branches after their PRs are merged
on:
pull_request:
types: [closed]
workflow_dispatch:
inputs:
branch_name:
description: 'Branch name to delete'
required: true
type: string
permissions:
contents: write
jobs:
delete-branch:
name: Delete Merged Branch
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
steps:
- name: Delete branch
uses: actions/github-script@v8
env:
BRANCH_NAME: ${{ github.event.inputs.branch_name }}
with:
script: |
let branchName;
if (context.payload.pull_request) {
// Get branch name from PR
branchName = context.payload.pull_request.head.ref;
const prNumber = context.payload.pull_request.number;
const merged = context.payload.pull_request.merged;
console.log(`PR #${prNumber} was closed`);
console.log(`Branch: ${branchName}`);
console.log(`Merged: ${merged}`);
if (!merged) {
console.log('PR was closed without merging, skipping branch deletion');
return;
}
} else {
// Get branch name from workflow input
branchName = process.env.BRANCH_NAME;
console.log(`Manual branch deletion requested for: ${branchName}`);
}
// Don't delete protected branches
const protectedBranches = ['main', 'master', 'development', 'staging', 'production'];
if (protectedBranches.includes(branchName)) {
console.log(`Branch ${branchName} is protected, skipping deletion`);
return;
}
// Check if it's a head branch from a fork
const isFork = context.payload.pull_request?.head.repo?.full_name !== context.payload.repository?.full_name;
if (isFork) {
console.log('Branch is from a fork, cannot delete from this repository');
return;
}
try {
// Delete the branch
await github.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `heads/${branchName}`
});
console.log(`✅ Successfully deleted branch: ${branchName}`);
// Add comment to the PR if available
if (context.payload.pull_request) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: `🗑️ Branch \`${branchName}\` has been automatically deleted after merge.`
});
}
} catch (error) {
console.error(`Error deleting branch: ${error.message}`);
// Don't fail the workflow if branch doesn't exist or is already deleted
if (error.status === 404) {
console.log('Branch does not exist or was already deleted');
} else if (error.status === 422) {
console.log('Branch cannot be deleted (may be default branch)');
} else {
throw error;
}
}