Skip to content

GitHub Repo Management Resources

This page might be better off as a blog...

Setting Up

The following items can be helpful when managing multiple GitHub repos:

  • A .json repo inventory file
  • Variables or an .env file
  • An inventory array, sourced from the .json repo inventory file

Repo Inventory File

In this case, we are using a .json file to keep track of the GitHub repos that will be managed. Here are the contents of the repo-list.json file:

{
    "repo": [
        "actions",
        "test-actions",
        "rwaight.github.io"
    ]
}

Variables

Set variables and "reset" the secrets inventory list:

  1. Set the repoOwner variable to yourusername
    repoOwner=yourusername
    

Inventory array

We will first create an array of repos from the ./repo-list.json file

1. Verify inventory output from jq

  1. Run the following jq command to test the format of the JSON file:

    jq --raw-output '.repo | to_entries | map("[\(.key)]=\(.value)")' ./repo-list.json
    

  2. Review the output from the command to make sure the repos output the proper format:

    [
        "[0]=actions",
        "[1]=test-actions",
        "[2]=rwaight.github.io"
    ]
    

2. Create the inventory array

Create the array using either bash or zsh

Create the inventory array using bash
# Create the variable that contains the array:
arrayAsString=$(jq --raw-output '.repo | to_entries | map("[\(.key)]=\(.value)") | reduce .[] as $item ("myRepos=("; . + $item + " ") + ")"' ./repo-list.json)
# Declare the array:
declare -A "$arrayAsString"
Create the inventory array using zsh
# Declare the array:
typeset -A myRepos
# Create the variable that contains the array:
arrayAssignments=$(jq -r '.repo | to_entries[] | "myRepos[\(.key)]=\(.value)"' ./repo-list.json)

3. Test the inventory array

Test the array using either bash or zsh:

Test the inventory array using bash
for str in "${myRepos[@]}"; do echo "the repo is ${str} "; done
Test the inventory array using zsh
for str in "${myRepos[@]}"; do echo "the repo is '${repoOwner}/$myRepos[$str]' "; done