3
3
# Returns a list of all actions used in an organization using the SBOM API
4
4
5
5
# 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
8
8
9
9
# count-by-version (default): returns a count of actions by version; actions/checkout@v2 would be counted separately from actions/checkout@v3
10
10
# count-by-action: returns a count of actions by action name; only care about actions/checkout usage, not the version
13
13
# - 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
14
14
# - The script will take about 1 minute per 100 repositories
15
15
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> "
18
18
exit 1
19
19
fi
20
20
21
21
org=$1
22
22
count_method=$2
23
+ report_format=$3
23
24
24
25
if [ -z " $count_method " ]; then
25
26
count_method=" count-by-version"
26
27
fi
27
28
29
+ if [ -z " $report_format " ]; then
30
+ report_format=" txt"
31
+ fi
32
+
28
33
repos=$( gh api graphql --paginate -F org=" $org " -f query=' query($org: String!$endCursor: String){
29
34
organization(login:$org) {
30
35
repositories(first:100,after: $endCursor) {
@@ -42,6 +47,16 @@ organization(login:$org) {
42
47
}
43
48
}' --template ' {{range .data.organization.repositories.nodes}}{{printf "%s/%s\n" .owner.login .name}}{{end}}' )
44
49
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
+
45
60
actions=()
46
61
47
62
for repo in $repos ; do
@@ -57,4 +72,13 @@ if [ "$count_method" == "count-by-action" ]; then
57
72
results=$( echo -e " ${results[@]} " | sed ' s/@.*//g' )
58
73
fi
59
74
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