Skip to content

Merge pull request #30 from mikejamescalvert/feature/trading-intellig… #20

Merge pull request #30 from mikejamescalvert/feature/trading-intellig…

Merge pull request #30 from mikejamescalvert/feature/trading-intellig… #20

name: Setup Repository Rulesets

Check failure on line 1 in .github/workflows/setup-rulesets.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/setup-rulesets.yml

Invalid workflow file

(Line: 7, Col: 3): Unexpected value 'administration'
on:
workflow_dispatch:
permissions:
administration: write
contents: read
jobs:
rulesets:
name: Configure repository rulesets
runs-on: ubuntu-latest
steps:
- name: Create main branch ruleset
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
run: |
# Check if ruleset already exists
EXISTING=$(gh api "repos/${REPO}/rulesets" -q '.[].name' 2>/dev/null || echo "")
if echo "$EXISTING" | grep -q "main-protection"; then
echo "Ruleset 'main-protection' already exists. Skipping creation."
echo "Delete the existing ruleset first if you want to recreate it."
exit 0
fi
gh api \
--method POST \
"repos/${REPO}/rulesets" \
--input - <<'EOF'
{
"name": "main-protection",
"target": "branch",
"enforcement": "active",
"conditions": {
"ref_name": {
"include": ["refs/heads/main"],
"exclude": []
}
},
"rules": [
{
"type": "deletion"
},
{
"type": "non_fast_forward"
},
{
"type": "required_linear_history"
},
{
"type": "pull_request",
"parameters": {
"required_approving_review_count": 1,
"dismiss_stale_reviews_on_push": true,
"require_code_owner_review": true,
"require_last_push_approval": false,
"required_review_thread_resolution": true
}
},
{
"type": "required_status_checks",
"parameters": {
"strict_required_status_checks_policy": true,
"required_status_checks": [
{ "context": "Lint & Type Check" },
{ "context": "Tests" },
{ "context": "Security Scan" }
]
}
}
],
"bypass_actors": []
}
EOF
- name: Create release branch ruleset
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
run: |
EXISTING=$(gh api "repos/${REPO}/rulesets" -q '.[].name' 2>/dev/null || echo "")
if echo "$EXISTING" | grep -q "release-protection"; then
echo "Ruleset 'release-protection' already exists. Skipping."
exit 0
fi
gh api \
--method POST \
"repos/${REPO}/rulesets" \
--input - <<'EOF'
{
"name": "release-protection",
"target": "branch",
"enforcement": "active",
"conditions": {
"ref_name": {
"include": ["refs/heads/release/*"],
"exclude": []
}
},
"rules": [
{
"type": "deletion"
},
{
"type": "non_fast_forward"
},
{
"type": "pull_request",
"parameters": {
"required_approving_review_count": 1,
"dismiss_stale_reviews_on_push": true,
"require_code_owner_review": true,
"require_last_push_approval": false,
"required_review_thread_resolution": true
}
},
{
"type": "required_status_checks",
"parameters": {
"strict_required_status_checks_policy": true,
"required_status_checks": [
{ "context": "Lint & Type Check" },
{ "context": "Tests" }
]
}
}
],
"bypass_actors": []
}
EOF
- name: Post summary
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
run: |
echo "## Repository Rulesets Configured" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### main-protection" >> $GITHUB_STEP_SUMMARY
echo "| Rule | Setting |" >> $GITHUB_STEP_SUMMARY
echo "|------|---------|" >> $GITHUB_STEP_SUMMARY
echo "| Require PRs | 1 approval, dismiss stale, CODEOWNERS |" >> $GITHUB_STEP_SUMMARY
echo "| Required status checks | Lint & Type Check, Tests, Security Scan |" >> $GITHUB_STEP_SUMMARY
echo "| Require up-to-date branch | Yes |" >> $GITHUB_STEP_SUMMARY
echo "| Linear history | Yes |" >> $GITHUB_STEP_SUMMARY
echo "| Block force push | Yes |" >> $GITHUB_STEP_SUMMARY
echo "| Block deletion | Yes |" >> $GITHUB_STEP_SUMMARY
echo "| Require conversation resolution | Yes |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### release-protection" >> $GITHUB_STEP_SUMMARY
echo "Applies to \`release/*\` branches with PR reviews and status checks." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
RULESETS=$(gh api "repos/${REPO}/rulesets" -q '.[] | "- **\(.name)**: \(.enforcement)"' 2>/dev/null || echo "Could not verify")
echo "### Active rulesets:" >> $GITHUB_STEP_SUMMARY
echo "$RULESETS" >> $GITHUB_STEP_SUMMARY