-
Notifications
You must be signed in to change notification settings - Fork 0
ci: create action to read all custom properties in all repos #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rbarker-dev
merged 48 commits into
main
from
1-create-an-action-to-read-all-custom-properties
Apr 22, 2025
Merged
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
7d7a103
ci: create action to read all custom properties in all repos
andrewb1269 ec89b4e
pull full list of repo names and output to text file
andrewb1269 45b7b9b
add org name processing
andrewb1269 888d3ae
switch to gh api
andrewb1269 9566a7a
add token
andrewb1269 edc82c2
add printout
andrewb1269 27d3fcf
send org name to a new file
andrewb1269 4abcac5
fix error with cat
andrewb1269 54926af
switch to only repo name instead of full name
andrewb1269 d984115
read props from all repos
andrewb1269 9967106
format the JSON output as YAML
andrewb1269 a5438e2
clean up the conversion step
andrewb1269 146af09
fix error
andrewb1269 1410cb8
add blank template as input
andrewb1269 086fc5d
cat the template file
andrewb1269 9611da2
switch how the template file is read in
andrewb1269 c638f58
add overwrite existing repo properties file input
andrewb1269 9767ba1
add default behavior
andrewb1269 7747909
add overwrite and commit steps
andrewb1269 d277a6e
remove add and commit step
andrewb1269 92be387
add the commit step
andrewb1269 0200174
remove the add and commit step
andrewb1269 40aa07d
add check to the input value
andrewb1269 fba7e13
add if-check
andrewb1269 15e8271
change the string deliminators for the input value
andrewb1269 97742ad
add the overwrite step
andrewb1269 f22f5ba
add commit step
andrewb1269 2c95a76
add push true
andrewb1269 1416295
remove boolean types from input
andrewb1269 3d10014
remove commit step
andrewb1269 a0122d5
add boolean types back in
andrewb1269 6a05930
add the commit step back in
andrewb1269 13bcdbe
switch to doing the commit manually
andrewb1269 be8c9e8
read the props to build up the template file
andrewb1269 299a9dc
add access to org name file
andrewb1269 fe1d4b7
remove the template field
andrewb1269 70e08bd
switch to dry-run-enabled flag
andrewb1269 b8cba98
cleanup script, no major changes
andrewb1269 da4d586
remove commented out sections
andrewb1269 0d96689
add GPG key signing to the action
andrewb1269 fefe1ed
add gpg key contents and passphrase
andrewb1269 c3c1e4b
change caps
andrewb1269 39f6064
rename inputs
andrewb1269 49e7a3c
fix the loopback issue
andrewb1269 69ff517
add signed off by line in commit message
andrewb1269 7521a6b
split the args apart
andrewb1269 153658e
add expansions
andrewb1269 1d8a1bb
shorten name, remove extra line
andrewb1269 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| name: 'Read Custom Properties' | ||
| description: 'Read all the custom properties and values of all repos in an organization' | ||
| author: 'Andrew Brandt <andrew.brandt@pandaswhocode.com>' | ||
| organization: 'PandasWhoCode' | ||
| branding: | ||
| icon: 'check-circle' | ||
| color: 'black' | ||
|
|
||
| inputs: | ||
| token: | ||
| description: 'Personal Access Token' | ||
| required: true | ||
| overwrite-existing-file: | ||
| description: 'Overwrite existing repo-properties.yaml with read values' | ||
| type: boolean | ||
| default: false | ||
| required: false | ||
| dry-run-enabled: | ||
| description: 'Dry run the script' | ||
| type: boolean | ||
| default: false | ||
| required: false | ||
| commit-author-name: | ||
| description: 'Author of commit name:' | ||
| required: true | ||
| commit-author-email: | ||
| description: 'Author of commit email address:' | ||
| required: true | ||
| commit-author-gpg-key-contents: | ||
| description: 'GPG Key Contents' | ||
| required: true | ||
| commit-author-gpg-key-passphrase: | ||
| description: 'GPG Key Passphrase' | ||
| required: true | ||
|
|
||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - name: Install yq (mikefarah's version) | ||
| shell: bash | ||
| run: | | ||
| sudo wget --quiet https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq | ||
| sudo chmod +x /usr/bin/yq | ||
| yq --version # confirm installed | ||
|
|
||
| - name: List all repos in org | ||
| shell: bash | ||
| env: | ||
| GH_TOKEN: ${{ inputs.token }} | ||
| run: | | ||
| ORG_NAME=$(echo "$GITHUB_REPOSITORY" | cut -d'/' -f1) | ||
| echo "Org name is: ${ORG_NAME}" | ||
| echo "${ORG_NAME}" > org-name.txt | ||
| echo "Fetching repos for organization: ${{ inputs.org }}" | ||
| gh api --paginate "orgs/$ORG_NAME/repos" --jq '.[].name' > repo-list.txt | ||
| echo "Repos written to repo-list.txt" | ||
|
|
||
| - name: Extract property names into a JSON file | ||
| shell: bash | ||
| env: | ||
| GH_TOKEN: ${{ inputs.token }} | ||
| run: | | ||
| ORG=$(cat org-name.txt) | ||
| echo "Fetching property schema for org: $ORG" | ||
| gh api --paginate "orgs/$ORG/properties/schema" | jq 'map(.property_name)' > property-names.json | ||
| echo "Property names written to property-names.json" | ||
|
|
||
| - name: Fetch custom properties for each repo | ||
| shell: bash | ||
| env: | ||
| GH_TOKEN: ${{ inputs.token }} | ||
| run: | | ||
| ORG_NAME="${GITHUB_REPOSITORY%%/*}" | ||
| echo "Fetching custom properties for repos in org: ${ORG_NAME}" | ||
|
|
||
| echo "{" > read-repo-properties.json | ||
| FIRST=1 | ||
| while IFS= read -r REPO_NAME; do | ||
| echo "Getting properties for ${REPO_NAME}..." | ||
| RESPONSE=$(gh api "repos/${ORG_NAME}/${REPO_NAME}/properties/values" || echo "{}") | ||
|
|
||
| # If not the first, prepend a comma to separate JSON entries | ||
| if [ "$FIRST" -eq 0 ]; then | ||
| echo "," >> read-repo-properties.json | ||
| fi | ||
| FIRST=0 | ||
|
|
||
| # Output as "repo-name": { ...props... } | ||
| echo "\"${REPO_NAME}\": $RESPONSE" >> read-repo-properties.json | ||
| done < repo-list.txt | ||
| echo "}" >> read-repo-properties.json | ||
|
|
||
| echo "Custom properties written to read-repo-properties.json" | ||
|
|
||
| - name: Convert repo properties to YAML using template | ||
| shell: bash | ||
| run: | | ||
| ORG_NAME=$(cat org-name.txt) | ||
|
|
||
| TEMPLATE=$(cat property-names.json) | ||
|
|
||
| { | ||
| echo "org: $ORG_NAME" | ||
| echo "repositories:" | ||
| jq -r --argjson fields "$TEMPLATE" ' | ||
| to_entries[] | | ||
| .key as $repoName | | ||
| .value as $props | | ||
| ( | ||
| " - name: \($repoName)\n" + | ||
| ( | ||
| $fields | ||
| | map( | ||
| . as $key | | ||
| ( | ||
| ($props | map({(.property_name): .value}) | add)[$key] // "" | ||
| | " \($key): \"\(.)\"" | ||
| ) | ||
| ) | ||
| | join("\n") | ||
| ) | ||
| ) | ||
| ' read-repo-properties.json | ||
| } > read-repo-properties.yaml | ||
|
|
||
| echo "YAML written to read-repo-properties.yaml" | ||
|
|
||
| - name: Print out the read-repo-properties.yaml | ||
| shell: bash | ||
| run: | | ||
| echo "" | ||
| echo "Full read-repo-properties.yaml file is:" | ||
| cat read-repo-properties.yaml | ||
| echo "" | ||
|
|
||
| - name: Overwrite existing file (if applicable) | ||
| if: ${{ inputs.overwrite-existing-file == 'true' }} | ||
| shell: bash | ||
| run: | | ||
| echo "Overwriting existing repo-properties.yaml" | ||
| mv read-repo-properties.yaml repo-properties.yaml | ||
| echo "Overwrite complete" | ||
|
|
||
| - name: Commit values to repo-properties.yaml | ||
| if: ${{ inputs.dry-run-enabled != 'true' }} | ||
| shell: bash | ||
| env: | ||
| GPG_PRIVATE_KEY: ${{ inputs.commit-author-gpg-key-contents }} | ||
| GPG_PASSPHRASE: ${{ inputs.commit-author-gpg-key-passphrase }} | ||
| run: | | ||
| # Import GPG key | ||
| echo "${GPG_PRIVATE_KEY}" | gpg --batch --import | ||
|
|
||
| # Get key ID | ||
| KEY_ID=$(gpg --list-secret-keys --with-colons | awk -F: '/^sec/{print $5}' | head -n1) | ||
|
|
||
| # Trust the key | ||
| echo -e "5\ny\n" | gpg --batch --yes --command-fd 0 --edit-key "$KEY_ID" trust | ||
|
|
||
| # Configure GPG for non-interactive use | ||
| mkdir -p ~/.gnupg | ||
| echo "use-agent" >> ~/.gnupg/gpg.conf | ||
| echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf | ||
| echo "allow-loopback-pinentry" >> ~/.gnupg/gpg-agent.conf | ||
| echo RELOADAGENT | gpg-connect-agent | ||
| export GPG_TTY=$(tty) | ||
|
|
||
| # Configure Git | ||
| git config --global user.name "${{ inputs.commit-author-name }}" | ||
| git config --global user.email "${{ inputs.commit-author-email }}" | ||
| git config --global commit.gpgsign true | ||
| git config --global user.signingkey "${KEY_ID}" | ||
| git config --global gpg.program gpg | ||
|
|
||
| # Set passphrase environment variable for Git GPG signing | ||
| export GIT_COMMITTER_NAME="${{ inputs.commit-author-name }}" | ||
| export GIT_COMMITTER_EMAIL="${{ inputs.commit-author-email }}" | ||
| export GPG_TTY=$(tty) | ||
|
|
||
| # Create the commit (sign with loopback) | ||
| echo "${GPG_PASSPHRASE}" | \ | ||
| gpg --batch --yes --passphrase-fd 0 --pinentry-mode loopback \ | ||
| --local-user "${KEY_ID}" \ | ||
| --output /dev/null --sign - 2>/dev/null | ||
|
|
||
| git add repo-properties.yaml | ||
| git commit -sS -m "chore: commit repo custom properties to properties file" || echo "Nothing to commit" | ||
| git push | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.