Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
sh 135 lines 3.82 KB
Raw
1 #!/usr/bin/env bash
2
3 # Check the validity of all actions used in the workflows.
4 #
5 # Example output:
6 #
7 # ❯ .github/scripts/check-action-repos.sh
8 # Found 18 unique uses: entries
9 # WARN: unrecognized uses format: ---
10 # ERROR: ref not found (tag/branch/commit): peter-evans/create-pull-request@271a8d0340265f705b14b601f8cf3c8c27d2d6cf
11 # ERROR: ref not found (tag/branch/commit): slackapi/slack-github-action@b4590ed38561d3cb7512cbee19cef0e0a6064ff1
12
13 set -euo pipefail
14
15 fail=0
16
17 # Collect all `uses:` entries
18 mapfile -t USES < <(
19 yq -r '
20 .jobs[]?.steps[]? |
21 select(has("uses")) |
22 .uses
23 ' .github/workflows/*.yml .github/workflows/*.yaml 2>/dev/null \
24 | sed '/^null$/d' \
25 | sort -u
26 )
27
28 if [[ ${#USES[@]} -eq 0 ]]; then
29 echo "No uses: entries found."
30 exit 0
31 fi
32
33 echo "Found ${#USES[@]} unique uses: entries"
34
35 check_local() {
36 local p="$1"
37 if [[ ! -e "$p" ]]; then
38 echo "ERROR: local action path does not exist: $p"
39 return 1
40 fi
41 if [[ -d "$p" ]]; then
42 if [[ -f "$p/action.yml" || -f "$p/action.yaml" ]]; then
43 return 0
44 fi
45 echo "ERROR: local action dir missing action.yml/action.yaml: $p"
46 return 1
47 fi
48 # If a file is used directly (rare), just ensure it exists
49 return 0
50 }
51
52 # For remote actions, verify:
53 # - repo exists
54 # - ref exists (tag/branch/sha)
55 # - action.yml or action.yaml exists at path (or root) at that ref
56 check_remote() {
57 local spec="$1" # owner/repo/path@ref OR owner/repo@ref
58 local before_at="${spec%@*}"
59 local ref="${spec#*@}"
60
61 local owner_repo="${before_at%%/*}/${before_at#*/}"
62 owner_repo="${owner_repo%%/*}/${owner_repo#*/}" # keep first two segments
63
64 local owner="${before_at%%/*}"
65 local rest="${before_at#*/}"
66 local repo="${rest%%/*}"
67
68 local path=""
69 if [[ "$before_at" == */*/* ]]; then
70 path="${before_at#"$owner/$repo/"}"
71 fi
72
73 # 1) repo exists
74 if ! gh api -H "Accept: application/vnd.github+json" "/repos/$owner/$repo" >/dev/null 2>&1; then
75 echo "ERROR: repo not found or inaccessible: $owner/$repo (from $spec)"
76 return 1
77 fi
78
79 # 2) ref exists (try tag, branch, then commit)
80 if ! gh api -H "Accept: application/vnd.github+json" "/repos/$owner/$repo/git/ref/tags/$ref" >/dev/null 2>&1 \
81 && ! gh api -H "Accept: application/vnd.github+json" "/repos/$owner/$repo/git/ref/heads/$ref" >/dev/null 2>&1 \
82 && ! gh api -H "Accept: application/vnd.github+json" "/repos/$owner/$repo/commits/$ref" >/dev/null 2>&1
83 then
84 echo "ERROR: ref not found (tag/branch/commit): $spec"
85 return 1
86 fi
87
88 # 3) action metadata exists at path (or root)
89 local base_path="${path}"
90 if [[ -z "$base_path" ]]; then
91 base_path=""
92 fi
93
94 local try_paths=()
95 if [[ -z "$base_path" ]]; then
96 try_paths=("action.yml" "action.yaml")
97 else
98 try_paths=("$base_path/action.yml" "$base_path/action.yaml")
99 fi
100
101 for p in "${try_paths[@]}"; do
102 if gh api -H "Accept: application/vnd.github+json" \
103 "/repos/$owner/$repo/contents/$p?ref=$ref" >/dev/null 2>&1
104 then
105 return 0
106 fi
107 done
108
109 echo "ERROR: action metadata not found at ref: $spec (looked for action.yml/action.yaml under '${base_path:-repo root}')"
110 return 1
111 }
112
113 for u in "${USES[@]}"; do
114 # Ignore reusable workflows here: they also use `uses:` but are `./.github/workflows/x.yml` or `owner/repo/.github/workflows/x.yml@ref`
115 # If you want to validate those too, add logic similar to check_local/check_remote for workflow files.
116 if [[ "$u" == docker://* ]]; then
117 echo "SKIP (docker image): $u"
118 continue
119 fi
120
121 if [[ "$u" == ./* ]]; then
122 if ! check_local "$u"; then fail=1; fi
123 continue
124 fi
125
126 # Remote action or reusable workflow reference (both look like owner/repo/...@ref)
127 if [[ "$u" == *@* && "$u" == */* ]]; then
128 if ! check_remote "$u"; then fail=1; fi
129 continue
130 fi
131
132 echo "WARN: unrecognized uses format: $u"
133 done
134
135 exit $fail