-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
184 lines (174 loc) · 6.5 KB
/
action.yml
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
name: none-shall-pass
description: Run validations against hyperlinks in all markdown files (including Wiki pages)
inputs:
debug:
description: Debug flag
required: false
default: "false"
owner:
description: Owner/Organization of the repository
required: false
default: ${{ github.repository_owner }}
repo:
description: Name of the repository
required: false
default: ${{ github.event.repository.name }}
excludeHostnames:
description: Hostnames for which the failure should be ignored
required: false
default: ""
failOnError:
description: Fail the action if any hyperlinks are broken
required: false
default: "false"
outputs: { }
runs:
using: composite
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect OS and Architecture
run: |
# NOTE: `uname -m` is more accurate and universal than `arch`
# See https://en.wikipedia.org/wiki/Uname
unamem="$(uname -m)"
case $unamem in
*aarch64*|arm64)
architecture="arm64";;
*64*)
architecture="amd64";;
*86*)
architecture="386";;
*armv5*)
architecture="armv5";;
*armv6*)
architecture="armv6";;
*armv7*)
architecture="armv7";;
*)
echo "::error title=Architecture::Aborted, unsupported or unknown architecture: $unamem"
exit 1
;;
esac
binary="none-shall-pass"
extension=".tar.gz"
unameu="$(tr '[:lower:]' '[:upper:]' <<<$(uname))"
if [[ $unameu == *DARWIN* ]]; then
os_name="darwin"
elif [[ $unameu == *LINUX* ]]; then
os_name="linux"
elif [[ $unameu == *FREEBSD* ]]; then
os_name="freebsd"
elif [[ $unameu == *NETBSD* ]]; then
os_name="netbsd"
elif [[ $unameu == *OPENBSD* ]]; then
os_name="openbsd"
elif [[ $unameu == *WIN* || $unameu == MSYS* ]]; then
# Should catch cygwin
os_name="windows"
binary+=".exe"
extension=".zip"
else
echo "::error title=Operating System::Aborted, unsupported or unknown OS: $(uname)"
exit 1
fi
echo "binary=$binary" >> $GITHUB_ENV
echo "extension=$extension" >> $GITHUB_ENV
echo "architecture=$architecture" >> $GITHUB_ENV
echo "os_name=$os_name" >> $GITHUB_ENV
echo "::notice title=Runner Platform::$os_name-$architecture"
shell: bash
- name: Detect Downloader
run: |
if type -p curl >/dev/null 2>&1; then
echo "net_getter=curl -fsSL" >> $GITHUB_ENV
elif type -p wget >/dev/null 2>&1; then
echo "net_getter=wget -qO-" >> $GITHUB_ENV
else
echo "::error title=Downloader404::Aborted, could not find curl or wget"
exit 1
fi
shell: bash
- name: Install Requirements
if: env.os_name == 'windows'
run: |
if [[ ! $(command -v jq) ]]; then
winget install jqlang.jq
fi
shell: bash
- name: Download Asset
run: |
nsp_dir="none-shall-pass-${{ env.os_name }}-${{ env.architecture }}"
nsp_file="$nsp_dir${{ env.extension }}"
response=$(${{ env.net_getter }} "https://api.github.com/repos/thevickypedia/none-shall-pass-rustic/releases/tags/v0.2.3")
release_id=$(echo "$response" | jq -r '.id')
if [ -z "$release_id" ]; then
echo "::error title=Release ID::Failed to get the release id for '$nsp_file'"
exit 1
fi
echo "Latest Release ID: $release_id"
tag_name=$(echo "$response" | jq -r '.tag_name')
published_at=$(echo "$response" | jq -r '.published_at')
echo "'none-shall-pass-rustic' $tag_name published at $published_at"
asset_id=$(echo "$response" | jq -r --arg nsp_file "$nsp_file" '.assets[] | select(.name == $nsp_file) | .id')
if [ -z "$asset_id" ]; then
echo "::error title=Artifact ID::Failed to get the artifact id for '$nsp_file'"
exit 1
fi
asset_name=$(echo "$response" | jq -r --arg nsp_file "$nsp_file" '.assets[] | select(.name == $nsp_file) | .name')
download_url=$(echo "$response" | jq -r --arg nsp_file "$nsp_file" '.assets[] | select(.name == $nsp_file) | .browser_download_url')
echo "::notice title=Artifact Name::$asset_name [$asset_id]"
echo "::notice title=Download URL::$download_url"
${{ env.net_getter }} -H "Accept: application/octet-stream" "$download_url" > $nsp_file
case "$nsp_file" in
*.zip) unzip -o "$nsp_file" ;;
*.tar.gz) tar -xzf "$nsp_file" ;;
esac
mv "$nsp_dir/${{ env.binary }}" . && rm -rf $nsp_dir $nsp_file
chmod +x ${{ env.binary }}
shell: bash
- name: Set Debug Flag
run: |
if [ "${{ inputs.debug }}" == "true" ] || [ "${{ env.RUNNER_DEBUG }}" == "1" ]; then
echo "debug=true" >> $GITHUB_ENV
else
echo "debug=false" >> $GITHUB_ENV
fi
shell: bash
- name: Run Asset
run: |
./${{ env.binary }} --debug ${{ env.debug }} --owner ${{ inputs.owner }} --repo ${{ inputs.repo }} --exclude "${{ inputs.excludeHostnames }}"
shell: bash
- name: Summary
run: |
if [ ! -f "gh_actions_summary.json" ]; then
echo "::notice title=Successful Run::No broken hyperlinks found."
exit 0
fi
echo "::error title=Failed Hyperlinks::Check the summary for detailed report."
echo "## none-shall-pass scan result" >> $GITHUB_STEP_SUMMARY
jq -c '.[]' gh_actions_summary.json | while read -r obj; do
filename=$(echo "$obj" | jq -r '.filename')
filepath=$(echo "$obj" | jq -r '.filepath')
text=$(echo "$obj" | jq -r '.text')
url=$(echo "$obj" | jq -r '.url')
if [[ $filename == *".md" ]]; then
hyperlink="${{ github.server_url }}/${{ github.repository }}/blob/${{ github.ref_name }}/$filepath"
else
hyperlink="${{ github.server_url }}/${{ github.repository }}/$filepath"
fi
echo "- '$text' => $url in [$filename]($hyperlink)" >> $GITHUB_STEP_SUMMARY
done
shell: bash
- name: Graceful Exit
if: inputs.failOnError == 'true'
run: |
if [ -f "gh_actions_summary.json" ]; then
exit 1
fi
shell: bash
branding:
icon: check-square
color: gray-dark