Sync Labels Across Organization Repositories #14
This file contains hidden or 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: Sync Labels Across Organization Repositories | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| source_repo: | |
| description: "Source repository (owner/repo) used as label reference" | |
| required: true | |
| org: | |
| description: "GitHub organization to sync labels into" | |
| required: true | |
| permissions: | |
| contents: read | |
| issues: write | |
| jobs: | |
| sync-labels: | |
| runs-on: ubuntu-latest | |
| environment: podaac projects | |
| steps: | |
| - name: Fetch labels from source repository | |
| run: | | |
| gh label list \ | |
| --repo "${{ inputs.source_repo }}" \ | |
| --json name,color,description \ | |
| --limit 1000 > labels.json | |
| cat labels.json | |
| env: | |
| GH_TOKEN: ${{ secrets.PROJECTS_TOKEN }} | |
| - name: List repositories in organization | |
| run: | | |
| gh repo list "${{ inputs.org }}" \ | |
| --limit 1000 \ | |
| --json name,owner \ | |
| -q '.[] | .owner.login + "/" + .name' \ | |
| > repos.txt | |
| cat repos.txt | |
| env: | |
| GH_TOKEN: ${{ secrets.PROJECTS_TOKEN }} | |
| - name: Add labels to all repositories in organization | |
| run: | | |
| while read repo; do | |
| echo "Syncing labels to $repo" | |
| jq -c '.[]' labels.json | while read label; do | |
| name=$(echo "$label" | jq -r '.name') | |
| color=$(echo "$label" | jq -r '.color') | |
| desc=$(echo "$label" | jq -r '.description // ""') | |
| # Create label only if it does not already exist | |
| gh label create "$name" \ | |
| --repo "$repo" \ | |
| --color "$color" \ | |
| --description "$desc" \ | |
| || true | |
| done | |
| done < repos.txt | |
| env: | |
| GH_TOKEN: ${{ secrets.PROJECTS_TOKEN }} |