55 branches :
66 - main
77 paths :
8- - .github/labels.yml # Only trigger if the label configuration changes
8+ - .github/labels.yml
99
1010jobs :
1111 update-labels :
@@ -22,42 +22,35 @@ jobs:
2222 - name : Install dependencies
2323 run : |
2424 python -m pip install --upgrade pip
25- pip install requests yq
25+ pip install requests yq && sudo snap install yq
2626
2727 - name : Get all repos in the organization
28+ env :
29+ LABELS_PAT : ${{ secrets.LABELS_PAT }}
2830 id : get_repos
2931 run : |
3032 ORGANIZATION="queens-autodrive"
3133 RESPONSE=$(curl -s \
3234 -H "Authorization: token $LABELS_PAT" \
3335 "https://api.github.com/orgs/$ORGANIZATION/repos?per_page=100")
34- echo "API Response: $RESPONSE"
3536 REPOS=$(echo "$RESPONSE" | jq -r '.[].name')
3637 echo "REPOS=$REPOS" >> $GITHUB_ENV
3738 - name : Update Labels for All Repos
3839 env :
39- LABELS_PAT : ${{ secrets.LABELS_PAT }} # GitHub token for authentication
40+ LABELS_PAT : ${{ secrets.LABELS_PAT }}
4041 run : |
41- LABELS=$(cat .github/labels.yml) # Path to your labels configuration file
42-
43- # Loop through the repositories listed in the environment variable
44- for REPO in $REPOS; do
42+ LABELS=$(cat .github/labels.yml)
43+ echo $REPOS
44+ echo "$REPOS" | while IFS= read -r REPO; do
4545 echo "Updating labels in $REPO"
46-
47- # Loop through the labels and update them
48- for LABEL in $(echo "$LABELS" | yq e '.labels[]' -); do
49- # Extract label name and color from the YAML file
50- LABEL_NAME=$(echo "$LABEL" | yq e '.name' -)
51- LABEL_COLOR=$(echo "$LABEL" | yq e '.color' -)
52- LABEL_DESCRIPTION=$(echo "$LABEL" | yq e '.description' -)
53-
54- echo "Label: $LABEL_NAME, Color: $LABEL_COLOR, Description: $LABEL_DESCRIPTION" # Print label info
55-
56- # Make the API request to update the label
57- curl -X PUT \
58- -H "Authorization: token $SELF_RUNNER_PAC" \
59- -H "Accept: application/vnd.github.v3+json" \
60- -d '{"name": "'"$LABEL_NAME"'", "color": "'"$LABEL_COLOR"'"}' \
61- "https://api.github.com/repos/$ORGANIZATION/$REPO/labels/$LABEL_NAME"
46+ echo "$LABELS" | yq e 'to_entries | .[] | "\(.key): color: \(.value.color), description: \(.value.description)"' - | while IFS= read -r label; do
47+ LABEL_NAME=$(echo "$label" | awk -F": color" '{print $1}' | xargs | tr -d '\n')
48+ LABEL_COLOR=$(echo "$label" | awk -F"color: " '{print $2}' | awk -F", description" '{print $1}' | xargs | tr -d '\n')
49+ LABEL_DESCRIPTION=$(echo "$label" | awk -F"description: " '{print $2}' | xargs | tr -d '\n')
50+ curl -X POST \
51+ -H "Authorization: token $LABELS_PAT" \
52+ -H "Accept: application/vnd.github.v3+json" \
53+ -d '{"name": "'"$LABEL_NAME"'", "color": "'"$LABEL_COLOR"'", "description": "'"$LABEL_DESCRIPTION"'"}' \
54+ "https://api.github.com/repos/$ORGANIZATION/$REPO/labels"
6255 done
6356 done
0 commit comments