Skip to content

Sync Labels Across Organization Repositories #9

Sync Labels Across Organization Repositories

Sync Labels Across Organization Repositories #9

Workflow file for this run

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
steps:
# - name: Check that gh authentication worked
# run: gh api user
# env:
# GH_TOKEN: ${{ secrets.PROJECTS_TOKEN }}
- name: Diagnose GH_TOKEN
run: |
if [ -z "$GH_TOKEN" ]; then
echo "❌ GH_TOKEN is EMPTY or UNSET"
exit 1
else
echo "✅ GH_TOKEN is set"
echo "Token length: ${#GH_TOKEN}"
fi
env:
GH_TOKEN: ${{ secrets.PROJECTS_TOKEN }}
- name: Fetch labels from source repository
run: |
gh label list \
--repo "${{ inputs.source_repo }}" \
--json name,color,description \
--limit 1000 > 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
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 }}