blob: 5d939550f325407bb9b234983f173a6caa41212f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#!/usr/bin/env bash
# kenku --- crawl and reproduce github actions
# Copyright © 2026 bdunahu <bdunahu@operationnull.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
#
# Takes a file with a repository identifier per line, like this:
#
# actions/deploy-pages v4
# actions/upload-pages-artifact v4
# astral-sh/setup-uv v7
# actions/setup-python v2
# actions/checkout v2
#
# And writes an equivalent file with what it's using. 'using' in this case can
# be one of the standard action types in the github actions lingo: 'node',
# 'docker', or 'composite'.
# The `actions.yaml` or `actions.yml` file does a pretty good job explaining
# what is used or not.
function curl_action {
curl -s \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${TOKEN}" \
"https://api.github.com/repos/$1?ref=$2"
}
function find_action {
owner=$(echo "$1" | awk -F'/' '{print $(1)}')
repo=$(echo "$1" | awk -F'/' '{print $(2)}')
fname=$(echo "$1" | cut -d'/' -f3-)
sha="$2"
path="$owner/$repo/contents/$fname"
if [[ "$path" =~ \.(yml|yaml)$ ]]; then
action=$(curl_action "$path" "$sha")
exists=true
else
for c in action.yml action.yaml; do
p="$path/$c"
action=$(curl_action "$p" "$sha")
# endpoint doesn't exist
exists=$(echo "$action" | jq -e 'has("message") | not')
[[ "$exists" == true ]] && break
done
fi
using=$("$exists" && {
echo "$action" \
| jq -r '.content' \
| base64 -d \
| grep -E '^\s*"?using"?:' \
| sed -E 's/.*"?using"?:[[:space:]]*//'
} || echo "NO_FILE"
)
[[ -z "$using" ]] && using="NO_USING"
echo "$1 $sha $using"
}
while read -r action sha; do
find_action "$action" "$sha"
done
|