33# Returns a list of all actions used in an organization using the SBOM API
44
55# Example usage:
6- # - ./get-actions-usage-in-repository.sh joshjohanning-org count-by-version
7- # - ./get-actions-usage-in-repository.sh joshjohanning-org count-by-action
6+ # - ./get-actions-usage-in-repository.sh joshjohanning-org count-by-version txt > output.txt
7+ # - ./get-actions-usage-in-repository.sh joshjohanning-org count-by-action md > output.md
88
99# count-by-version (default): returns a count of actions by version; actions/checkout@v2 would be counted separately from actions/checkout@v3
1010# count-by-action: returns a count of actions by action name; only care about actions/checkout usage, not the version
1313# - The count returned is the # of repositories that use the action - if a single repository uses the action 2x times, it will only be counted 1x
1414# - The script will take about 1 minute per 100 repositories
1515
16- if [ $# -lt 1 ] || [ $# -gt 2 ] ; then
17- echo " Usage: $0 <org> <count-by-version (default) | count-by-action>"
16+ if [ $# -lt 1 ] || [ $# -gt 3 ] ; then
17+ echo " Usage: $0 <org> <count-by-version (default) | count-by-action> | <report format: txt (default) | csv | md> "
1818 exit 1
1919fi
2020
2121org=$1
2222count_method=$2
23+ report_format=$3
2324
2425if [ -z " $count_method " ]; then
2526 count_method=" count-by-version"
2627fi
2728
29+ if [ -z " $report_format " ]; then
30+ report_format=" txt"
31+ fi
32+
2833repos=$( gh api graphql --paginate -F org=" $org " -f query=' query($org: String!$endCursor: String){
2934organization(login:$org) {
3035 repositories(first:100,after: $endCursor) {
@@ -42,6 +47,16 @@ organization(login:$org) {
4247 }
4348}' --template ' {{range .data.organization.repositories.nodes}}{{printf "%s/%s\n" .owner.login .name}}{{end}}' )
4449
50+ # if report_format = md
51+ if [ " $report_format " == " md" ]; then
52+ echo " ## 🚀 Actions Usage in Organization: $org "
53+ echo " "
54+ echo " | Count | Action |"
55+ echo " | --- | --- |"
56+ elif [ " $report_format " == " csv" ]; then
57+ echo " Count,Action"
58+ fi
59+
4560actions=()
4661
4762for repo in $repos ; do
@@ -57,4 +72,13 @@ if [ "$count_method" == "count-by-action" ]; then
5772 results=$( echo -e " ${results[@]} " | sed ' s/@.*//g' )
5873fi
5974
60- echo -e " $results " | sort | uniq -c | sort -nr | awk ' {print $1 " " $2}'
75+ results=$( echo -e " $results " | sort | uniq -c | sort -nr | awk ' {print $1 " " $2}' )
76+
77+ # if report_format = md
78+ if [ " $report_format " == " md" ]; then
79+ echo -e " ${results[@]} " | awk ' {print "| " $1 " | " $2 " |"}'
80+ elif [ " $report_format " == " csv" ]; then
81+ echo -e " ${results[@]} " | awk ' {print $1 "," $2}'
82+ else
83+ echo -e " ${results[@]} "
84+ fi
0 commit comments