Skip to content

Merge remote-tracking branch 'RedEyeMods/action-template/main' into u… #10

Merge remote-tracking branch 'RedEyeMods/action-template/main' into u…

Merge remote-tracking branch 'RedEyeMods/action-template/main' into u… #10

name: Settings Sync
on:
workflow_dispatch:
push:
branches:
- '**'
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: |
const fs = require('fs');
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 == undefined ? {} : request.data.template_repository;
run-init:
name: Repository Settings Synchronization
needs: get-template-repo
if: ${{ fromJson(needs.get-template-repo.outputs.template_repository).full_name != '' }}
runs-on: ubuntu-latest
env:
CUR_REPO: ${{ github.repository }}
SOURCE_REPO: ${{ fromJson(needs.get-template-repo.outputs.template_repository).full_name }}
steps:
- name: Copy On Rulesets
uses: RedEyeMods/[email protected]
with:
owner-token: ${{ secrets.ORG_PAT }}
source-repo: ${{ env.SOURCE_REPO }}
regex-filter: '✓+.*'
ruleset-enabled: true
overwrite: true
- name: Copy Off Rulesets
uses: RedEyeMods/[email protected]
with:
owner-token: ${{ secrets.ORG_PAT }}
source-repo: ${{ env.SOURCE_REPO }}
regex-filter: '✗+.*'
ruleset-enabled: false
overwrite: true
- name: Copy Labels
uses: RedEyeMods/[email protected]
with:
token: ${{ secrets.ORG_PAT }}
source-repo: ${{ env.SOURCE_REPO }}
- 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);
});
one-time:
name: Execute One Time
runs-on: ubuntu-latest
steps:
- name: Disable Workflow
run: |
gh workflow disable -R $GITHUB_REPOSITORY "${{ github.workflow }}"
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}