Keeps every repo in the OpenShock org in the same state. GitHub only offers org-wide rulesets and policies on paid plans, so this does the same job from the outside: one config file describes the desired state, and a script compares every repo against it.
Nothing is cloned.
Everything goes through the GitHub API using the gh CLI's login, and file changes arrive as GitHub-signed commits.
pip install pyyaml # the only dependency, besides gh
python -m orgsync plan # read-only: show all drift
python -m orgsync plan --diff --only API # with file diffs, one repo
python -m orgsync plan --check rulesets # one check
python -m orgsync apply # one commit per repo on its default branch, plus settings and rulesets
python -m orgsync apply --check branches # delete orphaned branches
python -m orgsync apply --check renovate # only renovate.jsonplan exits with 1 when there is drift, so it can run on a schedule.
Branch deletions are always listed, but only count as drift when asked for with --check branches.
apply prints the plan first and asks before doing anything.
It refuses to run unless gh is logged in as the bot_account from org.toml, or holds a GitHub App token when bot_app = true.
A full plan costs about 230 of the 5,000 hourly REST requests and about 30 of the 5,000 hourly GraphQL points, and prints what it used.
A run does not start with less than 1,000 left of either.
Requests that change something are spaced one second apart.
When GitHub answers with a rate limit error the request is retried: after the hourly window resets if the budget is exhausted, otherwise after a minute, doubling on each repeat.
All of them are configured in org.toml.
| Check | Keeps even | How it is applied |
|---|---|---|
teams |
Teams keep at least the access org.toml gives them, so a team named in CODEOWNERS counts |
API |
files |
Managed files such as CODEOWNERS, filled in from templates/ |
Commit |
renovate |
An existing renovate.json is the one rendered from renovate/ |
Commit |
community |
Rules about community files: required, forbidden, must contain, must not contain; issue template security link | Notes, commit for a missing issue template config.yml |
actions |
An allowlist of actions, and banned actions | Notes, commit for a rewritten banned action |
msbuild |
Selected properties in Directory.Build.props |
Commit |
rulesets |
Repository rulesets, shared ones and per-repo ones | API |
settings |
Merge policy and security features | API |
branches |
Deletes orphaned feat/, fix/, chore/, ... branches |
API, only with --check branches |
All file changes for a repo arrive together as one commit on its default branch, with the message grouped by check. org-sync never opens a pull request and never creates a branch.
Lines starting with ! in the plan are notes: things the tool noticed but will not change on its own.
The security policy lives in the .github repo, and GitHub shows it for every repo that has no SECURITY.md of its own.
A repo-level SECURITY.md replaces the org policy entirely, so local copies are removed, like the other inherited community files.
API, Frontend and Firmware keep hand-written policies; the community check verifies those still contain the shared reporting block.
CODEOWNERS is not inherited, so every public repo gets its own copy.
The default owners are named users, so someone can own one repo without being given every repo.
They come from vars in org.toml, and a repo with more of them is listed under repo_vars.
/SECURITY.md and /.github/ belong to the maintainer team in every repo; the teams check gives that team write access everywhere, since GitHub ignores a team that cannot write.
Any one owner on the matching line can approve: listing more owners asks more people, it never needs more approvals.
Every renovate.json is written out in full by this tool, nothing is read from this repo while Renovate runs.
What a repo's file says is exactly what Renovate does there, top to bottom.
The file is put together from layers, in this order:
renovate/default.json: the only layer every repo gets. It holds how Renovate runs (schedule, release age, how it merges) and the GitHub Actions rules, nothing about any other kind of dependency.renovate/rules/<name>.json: one file per kind of dependency, such asnpm,nugetornode. A repo gets only the ones[renovate.uses]inorg.tomllists for it, in the order listed. Each carries its own grouping and its own automerge rule.renovate/repos/<Repo>.json: rules and settings only that repo needs. Most repos have none.
A repo that is not listed under [renovate.uses] gets the shared layer alone.
So a repo's file never contains a rule for something the repo does not have.
extends, customManagers and packageRules are joined in that order, so a later rule wins where two match the same package.
That is why node is listed after npm: it takes Node and pnpm out of the npm group and out of automerge.
Any other setting is taken from the last layer that has it.
Only Renovate's own presets, such as config:recommended, are still extended.
Renovate is never added to a repo: only an existing renovate.json is replaced.
A change is made here, never in the repo: the next sync replaces the file as a whole.
Nothing is lost silently, though.
Whatever the file in the repo decides that the rendered one does not, a rule, a setting or an extends entry, is named in the plan and in the commit message.
So run plan first, and move what was changed in a repo to renovate/repos/<Repo>.json if it should stay.
A change here reaches a repo on the next apply, which the sync workflow runs as soon as it lands on master.
Renovate opens a pull request for every update and merges minor, patch and digest updates itself once CI passes. Major updates always wait for a human.
Actions that are neither from an allowed owner nor individually allowed are reported, and so are banned ones.
softprops/action-gh-release is also rewritten into a gh release create step when the tool understands every input of the step, and left for a human otherwise.
The rewritten step is stricter than the action in two ways: it fails if the release already exists, and it fails if a file pattern matches nothing.
Action versions and SHA pins are not touched, see below.
rulesets/
shared/ used by many repos, assigned to repos in org.toml
repos/<Repo>/ for that one repo, picked up automatically
Rulesets are matched by the name field inside the file, the filename does not matter.
A ruleset in a repo's folder with the same name as a shared one replaces the shared one for that repo.
python -m orgsync import-rulesets copies rulesets that exist on GitHub but not here into rulesets/repos/, without changing anything on GitHub.
Rulesets on GitHub that have no file are deleted, or only reported when prune = false is set in org.toml.
A folder in rulesets/repos/ that names no active repo stops the run, so a renamed repo cannot lose its rulesets unnoticed.
| Shared ruleset | Repos | Effect |
|---|---|---|
main-branches |
all | No force-push and no deletion of master, main, develop, beta and the default branch |
squash-merges |
public | The default branch only takes squash merges, through a pull request |
pull-requests |
listed in org.toml |
Main branches need one code owner approval |
Merge methods can only be limited per target branch.
Only the default branch is limited to squash, so develop can still be merged into master with its history.
Private repos on the free plan cannot have rulesets and are reported.
A branch is a candidate only if its name starts with one of the configured prefixes and it is not protected.
| Situation | Result |
|---|---|
| Has an open PR | kept |
| Its PR was merged and nothing was pushed since | deleted |
| Has no commits that are missing from the default branch | deleted |
dependabot/* without an open PR |
deleted |
Unmerged work, older than stale_days |
reported, deleted only with delete_stale_unmerged = true |
| Unmerged work, recent | kept |
The plan prints the commit each branch pointed at, so a deleted branch can be recreated.
The sync workflow runs apply for every check except branches:
whenever org.toml, orgsync/, renovate/, rulesets/ or templates/ changes on master, once a day to undo changes made by hand in a repo, and on demand.
So file changes are committed to default branches, and rulesets, settings and team access are changed through the API.
Notes are left in the run's log, and the run fails when any change could not be applied.
Branch deletion stays manual, with --check branches.
It runs as a GitHub App, which needs:
| Where | What |
|---|---|
| The app | Repository permissions, installed on all repos: Contents, Pull requests, Workflows and Administration, all read and write. Organization permission: Members, read and write, for the teams check |
org-config variable ORG_SYNC_APP_CLIENT_ID |
The app's client ID |
org-config secret ORG_SYNC_APP_PRIVATE_KEY |
A private key of the app |
org.toml, direct_commit_app |
The app's numeric id, so the rulesets let it commit to default branches |
Workflows is needed for the actions check, which rewrites workflow files, Administration for rulesets and settings, and Members for team access.
Dependency updates belong to Renovate, which is installed on the org.
That covers package versions, GitHub Actions versions and their SHA pins, and Docker image tags.
org-sync does not generate dependabot.yml and does not bump or pin actions.
Its only part in this is writing the renovate.json Renovate reads.
Add a module in orgsync/checks/ with a check(repo, cfg) function returning a Result, and register it in orgsync/checks/__init__.py.
A Result holds file changes, API calls and notes; delivery is handled for you.
python -m unittest discover -s testsFound a security vulnerability? Please do not open a public issue. Report it privately as described in the OpenShock security policy.
You can support the OpenShock dev team here: Sponsor OpenShock