Sync Repository Secrets #7
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: Propagate Repository Secrets | |
on: | |
workflow_dispatch: | |
jobs: | |
get-mappings: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- uses: actions/checkout@v4 | |
- id: set-matrix | |
run: | | |
MATRIX=$(jq -c '{ include: [ to_entries[] | { secret: .key, repos: .value } ] }' mapping.json) | |
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT | |
propagate: | |
needs: get-mappings | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: ${{fromJson(needs.get-mappings.outputs.matrix)}} | |
fail-fast: false | |
steps: | |
- uses: actions/github-script@v7 | |
with: | |
token: ${{ secrets.SECRETS_TOKEN }} | |
script: | | |
const secret = '${{ matrix.secret }}' | |
const secretValue = process.env[secret] | |
const repos = ${{ toJson(matrix.repos) }} | |
for (const repo of repos) { | |
console.log(`Setting ${secret} for repository ${repo}`) | |
await github.rest.actions.createOrUpdateRepoSecret({ | |
owner: context.repo.owner, | |
repo: repo, | |
secret_name: secret, | |
secret_value: secretValue | |
}) | |
} | |
env: | |
${{ matrix.secret }}: ${{ secrets[matrix.secret] }} |