gh-secrets-sync
v0.1.5
Published
CLI tool to batch sync GitHub Actions secrets across multiple repositories.
Downloads
124
Readme
GitHub Secrets Sync
A CLI tool to batch sync GitHub Actions secrets across multiple repositories. Sync secrets from a central repository to target repositories using GitHub CI.
Why?
Managing GitHub Actions secrets across multiple repositories can be tedious:
- Manual repetition: You need to manually add the same secret to each repository
- Error-prone: Easy to forget to update a secret in one of the repositories
This tool automates the process, allowing you to sync secrets across multiple repositories with a single command.
Usage
Create a configuration file (secrets.config.yaml) in your central repository or local directory:
repos:
- owner/vscode-*
envs:
- VSCE_PAT
- OVSX_PAT[!NOTE] Both
reposandenvssupport*wildcards. Forrepos, the tool lists all repositories accessible by your token and filters by the pattern (e.g.,owner/vscode-*). Forenvs, wildcards are expanded by listing secrets from the central repository and matching by name. The central repository is auto-detected in GitHub Actions (from the checked-out repo); for local runs, pass--repo <owner/repo>.
Local usage
If GitHub CI feels too complex, you can simply run it locally:
# Set your token and secret values in env
export GH_PAT=...
export VSCE_PAT=...
export OVSX_PAT=...
npx gh-secrets-syncGitHub CI usage
Set up GitHub CI in your central repository:
# .github/workflows/sync-secrets.yml
name: Sync Secrets
permissions:
contents: write
on:
push:
branches: [main]
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set node
uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Sync Secrets
# if regex patterns are used in `repos` or `secrets` must set `--yes` in GitHub Actions
run: npx gh-secrets-sync --yes
env:
GH_PAT: ${{secrets.GH_PAT}}
VSCE_PAT: ${{secrets.VSCE_PAT}}
OVSX_PAT: ${{secrets.OVSX_PAT}}Configure secrets in your central repository:
- Go to your central repository Settings > Secrets and variables > Actions
- Add
GH_PATas a repository secret (this is your GitHub Personal Access Token) - Add
VSCE_PATandOVSX_PATas repository secrets
How to Get Your GitHub Token
- Go to GitHub Personal Access Tokens
- Click "Generate new token"
- Give it a descriptive name like "Secrets Sync Tool"
- Select the required scopes:
- Repository permissions > Secrets: Read and write
- Repository permissions > Actions: Read and write
- Metadata
- Click "Generate token"
- Add the token as a repository secret named
GH_PATin your central repository
License
MIT License © jinghaihan
