You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: major enhancements to actions usage scripts (#112)
* feat: enhance Action usage in organization script
- fixing formatting (@3.%2A.%2A to @V3)
- warning message for repos that don't have Dependency graph enabled
- add --resolve-shas capability for count-by-version
- add --dedupe-by-repo for count-by-action
- added informational notes to help interpret results
* feat: enhance Action usage in repository script
- fixing formatting (@3.%2A.%2A to @V3)
- warning message for repos that don't have Dependency graph enabled
- add --resolve-shas capability for count-by-version
* docs: update usage instructions and examples for action usage scripts
* fix: only show warning for non-csv
* fix: suppress errors when fetching tags for actions
* docs: update README with examples/notes
* feat: add caching for SHA to tag resolution in actions usage scripts
Or (`count-by-action` option to count by action as opposed to action@version):
646
+
Example output (count-by-action) (with `--dedupe-by-repo`):
614
647
615
648
```csv
616
-
130 actions/checkout
617
-
35 actions/upload-artifact
618
-
27 actions/github-script
619
-
21 actions/setup-node
649
+
Count,Action
650
+
3,actions/checkout
651
+
2,actions/upload-artifact
652
+
2,actions/setup-node
653
+
1,actions/dependency-review-action
620
654
```
621
655
656
+
> [!TIP]
657
+
> If outputting to `txt` or `md`, you'll see a warning message for each repository that returned an error (because Dependency Graph is disabled). You will also see an informational message providing context around what the count is returning. `csv` returns clean data.
658
+
622
659
> [!NOTE]
623
-
> The count returned is the # of repositories that use the action - if single a repository uses the action 2x times, it will only be counted 1x
660
+
> The count returned is the # of repositories that use the `action@version` combination - if a single repository uses the `action@version` combination 2x times, it will only be counted 1x (unless using `count-by-action` in combination with `--dedupe-by-repo`, which counts unique repositories per action). Conversely, if different `action@version` combinations are being used, they will be counted separately (for example, if the same action appears twice in a repository but one uses `@v2` and one uses `@v3`, by default they will be counted separately unless using `count-by-action` in combination with `--dedupe-by-repo`).
661
+
662
+
> [!NOTE]
663
+
> Using `--resolve-shas` will add additional API calls, but we attempt to cache tag lookups to improve performance. The cache is stored in temporary files and automatically cleaned up when the script exits.
624
664
625
665
### get-actions-usage-in-repository.sh
626
666
627
667
Returns a list of all actions used in a repository using the SBOM API
actions+=$(gh api repos/$repo/dependency-graph/sbom --jq '.sbom.packages[].externalRefs.[0].referenceLocator'2>&1| grep "pkg:githubactions"| sed 's/pkg:githubactions\///')||true
64
-
actions+="\n"
160
+
# Try to get SBOM data - if it fails, dependency graph is likely disabled
161
+
sbom_data=$(gh api repos/$repo/dependency-graph/sbom --jq '.sbom.packages[].externalRefs.[0].referenceLocator'2>&1)
162
+
163
+
# Also check if the API call returned an HTTP error code
164
+
ifecho"$sbom_data"| grep -q "HTTP ";then
165
+
repos_without_dependency_graph+=("$repo")
166
+
continue
167
+
fi
168
+
169
+
repo_actions=$(echo "$sbom_data"| grep "pkg:githubactions"| sed 's/pkg:githubactions\///'| sed 's/%2A/*/g'2>/dev/null || true)
170
+
if [ "$dedupe_by_repo"=="true" ];then
171
+
# For dedupe mode, prefix each action with the repo name so we can track repo usage
172
+
# Use awk to avoid sed delimiter issues with special characters
# Add explanatory note for count-by-action mode (but not for CSV)
244
+
if [ "$count_method"=="count-by-action" ] && [ "$report_format"!="csv" ];then
245
+
if [ "$dedupe_by_repo"=="true" ];then
246
+
note_text="Count represents the number of repositories using each action (deduplicated per repository)."
247
+
else
248
+
note_text="Count represents unique action@version combinations (versions stripped). Each repository using different versions of the same action contributes multiple counts."
249
+
fi
250
+
echo""
251
+
if [ "$report_format"=="md" ];then
252
+
echo"📝 **Note**: $note_text"
253
+
elif [ "$report_format"=="txt" ];then
254
+
echo"📝 Note: $note_text"
255
+
fi
256
+
fi
257
+
258
+
# Add explanatory note for count-by-version mode (but not for CSV)
259
+
if [ "$count_method"=="count-by-version" ] && [ "$report_format"!="csv" ];then
260
+
note_text="Count represents unique action@version combinations (with each unique action@version combination only showing up once per repository)."
261
+
echo""
262
+
if [ "$report_format"=="md" ];then
263
+
echo"📝 **Note**: $note_text"
264
+
elif [ "$report_format"=="txt" ];then
265
+
echo"📝 Note: $note_text"
266
+
fi
267
+
fi
268
+
269
+
# Show warning about repos that couldn't be analyzed (but not for CSV)
270
+
if [ ${#repos_without_dependency_graph[@]}-gt 0 ] && [ "$report_format"!="csv" ];then
271
+
echo"">&2
272
+
echo"⚠️ Warning: The following repositories could not be analyzed (likely due to disabled Dependency Graph or permissions):">&2
0 commit comments