Initial commit #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Settings Sync | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
jobs: | |
get-template-repo: | |
name: Parent Template Repository | |
runs-on: ubuntu-latest | |
outputs: | |
template_repository: ${{ steps.org-grab.outputs.result }} | |
steps: | |
- name: Get Organization Data | |
id: org-grab | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.ORG_PAT }} | |
script: | | |
var request = await github.rest.repos.get({ | |
...context.repo | |
}); | |
if (request.status != 200) | |
throw new Exception('Bad API response: ' + request.status); | |
return request.data.template_repository; | |
check-diff: | |
needs: get-template-repo | |
if: ${{ needs.get-template-repo.outputs.template_repository != '' }} | |
runs-on: ubuntu-latest | |
outputs: | |
COMPLIANCE_CHANGED: ${{ steps.filter.outputs.compliance }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dorny/paths-filter@v3 | |
id: filter | |
with: | |
base: main | |
filters: | | |
compliance: | |
- '.github/workflows/organization-compliance.yml' | |
run-init: | |
name: Repository Settings Synchronization | |
needs: [ 'check-diff', 'get-template-repo' ] | |
if: ${{ needs.check-diff.outputs.COMPLIANCE_CHANGED == 'true' }} | |
runs-on: ubuntu-latest | |
env: | |
CUR_REPO: ${{ github.repository }} | |
steps: | |
- name: Copy On Rulesets | |
uses: RedEyeMods/[email protected] | |
with: | |
owner-token: ${{ secrets.ORG_PAT }} | |
source-repo: ${{ fromJson(needs.get-template-repo.outputs.template_repository).full_name }} | |
regex-filter: '✓+.*' | |
ruleset-enabled: true | |
overwrite: true | |
- name: Copy Off Rulesets | |
uses: RedEyeMods/[email protected] | |
with: | |
owner-token: ${{ secrets.ORG_PAT }} | |
source-repo: ${{ fromJson(needs.get-template-repo.outputs.template_repository).full_name }} | |
regex-filter: '✗+.*' | |
ruleset-enabled: false | |
overwrite: true | |
- name: Copy Labels | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.ORG_PAT }} | |
script: | | |
async function main() { | |
const [currentOwner, currentRepo] = process.env.CUR_REPO.split('/'); | |
const [targetOwner, targetRepo] = process.env.TARGET_REPO.split('/'); | |
const copyLabels = await github.rest.issues.listLabelsForRepo({ | |
owner: targetOwner, repo: targetRepo | |
}); | |
const currentLabels = await github.rest.issues.listLabelsForRepo({ | |
owner: currentOwner, repo: currentRepo | |
}); | |
for (const label of copyLabels.data) { | |
const curLabelIdx = currentLabels.data.findIndex(lbl => lbl.name == label.name); | |
if (curLabelIdx >= 0) { | |
await github.rest.issues.deleteLabel({ | |
owner: currentOwner, repo: currentRepo, name: currentLabels.data[curLabelIdx].name | |
}); | |
} | |
await github.rest.issues.createLabel({ | |
owner: currentOwner, repo: currentRepo, | |
name: label.name, | |
color: label.color, | |
description: label.description | |
}); | |
} | |
} | |
main().catch(error => { | |
console.error(error); | |
process.exit(1); | |
}); | |
- name: Copy Misc Settings | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.ORG_PAT }} | |
script: | | |
async function main() { | |
const [currentOwner, currentRepo] = process.env.CUR_REPO.split('/'); | |
const [targetOwner, targetRepo] = process.env.TARGET_REPO.split('/'); | |
const defProtRules = await github.rest.repos.get({ | |
owner: targetOwner, repo: targetRepo | |
}); | |
await github.rest.repos.update({ | |
owner: currentOwner, repo: currentRepo, | |
allow_squash_merge: defProtRules.data.allow_squash_merge, | |
allow_merge_commit: defProtRules.data.allow_merge_commit, | |
allow_rebase_merge: defProtRules.data.allow_rebase_merge, | |
allow_auto_merge: defProtRules.data.allow_auto_merge, | |
delete_branch_on_merge: defProtRules.data.delete_branch_on_merge, | |
allow_update_branch: defProtRules.data.allow_update_branch, | |
use_squash_pr_title_as_default: defProtRules.data.use_squash_pr_title_as_default, | |
squash_merge_commit_message: defProtRules.data.squash_merge_commit_message, | |
squash_merge_commit_title: defProtRules.data.squash_merge_commit_title, | |
merge_commit_message: defProtRules.data.merge_commit_message, | |
merge_commit_title: defProtRules.data.merge_commit_title | |
}) | |
} | |
main().catch(error => { | |
console.error(error); | |
process.exit(1); | |
}); |