2023-08-03 09:04:55 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
###### script header ######
|
|
|
|
|
|
|
|
lib=$(realpath @@BASE_LIB@@) || exit 1
|
|
|
|
stat "${lib}" >> /dev/null || exit 1
|
|
|
|
|
|
|
|
# shellcheck source=../sh/lib.bash
|
|
|
|
if ! source "${lib}"; then
|
|
|
|
echo "Error: could not find import"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
cd "${BUILD_WORKSPACE_DIRECTORY}"
|
|
|
|
|
|
|
|
###### script body ######
|
|
|
|
|
|
|
|
# Find all action YAMLs. This action check if there are files within
|
|
|
|
# .github/actions that are not used in any workflow or action YAML.
|
|
|
|
# We only want directory of that exact level and ignore subdirectories.
|
|
|
|
actionNames=$(
|
2023-08-03 09:05:04 -04:00
|
|
|
find .github/actions \
|
|
|
|
-maxdepth 2 \
|
|
|
|
-type d \
|
|
|
|
! -name actions
|
2023-08-03 09:04:55 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
actionYMLs=$(
|
2023-08-03 09:05:04 -04:00
|
|
|
find .github/actions \
|
|
|
|
! -name actions \
|
|
|
|
-type f \
|
|
|
|
-name '*.yml'
|
2023-08-03 09:04:55 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
workflowYMLs=$(
|
2023-08-03 09:05:04 -04:00
|
|
|
find .github/workflows \
|
|
|
|
-type f \
|
|
|
|
-name '*.yml'
|
2023-08-03 09:04:55 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
exitcode=0
|
|
|
|
|
|
|
|
for action in ${actionNames}; do
|
2023-08-03 09:05:04 -04:00
|
|
|
used=false
|
|
|
|
|
|
|
|
for yml in ${actionYMLs} ${workflowYMLs}; do
|
|
|
|
if grep -q "${action}" "${yml}"; then
|
|
|
|
used=true
|
|
|
|
break
|
2023-08-03 09:04:55 -04:00
|
|
|
fi
|
2023-08-03 09:05:04 -04:00
|
|
|
done
|
|
|
|
|
2023-12-29 05:02:37 -05:00
|
|
|
if [[ ${used} == "false" && ${action} != ".github/actions/artifact_download" ]]; then
|
2023-08-03 09:05:04 -04:00
|
|
|
echo "Action ${action} is unused"
|
|
|
|
exitcode=1
|
|
|
|
fi
|
2023-08-03 09:04:55 -04:00
|
|
|
done
|
|
|
|
|
|
|
|
exit "${exitcode}"
|