mirror of
https://github.com/taiki-e/install-action.git
synced 2026-05-09 22:30:28 +00:00
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,5 +1,6 @@
|
|||||||
target
|
target
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
|
.venv
|
||||||
tmp
|
tmp
|
||||||
|
|
||||||
# For platform and editor specific settings, it is recommended to add to
|
# For platform and editor specific settings, it is recommended to add to
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ trap 's=$?; echo >&2 "$0: error on line "${LINENO}": ${BASH_COMMAND}"; exit ${s}
|
|||||||
# - shfmt
|
# - shfmt
|
||||||
# - shellcheck
|
# - shellcheck
|
||||||
# - npm
|
# - npm
|
||||||
# - jq and yq
|
# - jq
|
||||||
|
# - python
|
||||||
# - rustup (if Rust code exists)
|
# - rustup (if Rust code exists)
|
||||||
# - clang-format (if C/C++ code exists)
|
# - clang-format (if C/C++ code exists)
|
||||||
#
|
#
|
||||||
@@ -204,32 +205,46 @@ if [[ -n "$(git ls-files '*.yml' '*.js' '*.json')" ]]; then
|
|||||||
# Check GitHub workflows.
|
# Check GitHub workflows.
|
||||||
if [[ -d .github/workflows ]]; then
|
if [[ -d .github/workflows ]]; then
|
||||||
info "checking GitHub workflows"
|
info "checking GitHub workflows"
|
||||||
if type -P jq &>/dev/null && type -P yq &>/dev/null; then
|
if type -P jq &>/dev/null; then
|
||||||
for workflow in .github/workflows/*.yml; do
|
if type -P python3 &>/dev/null || type -P python &>/dev/null; then
|
||||||
# The top-level permissions must be weak as they are referenced by all jobs.
|
py_prefix=''
|
||||||
permissions=$(yq -c '.permissions' "${workflow}")
|
if type -P python3 &>/dev/null; then
|
||||||
case "${permissions}" in
|
py_prefix='3'
|
||||||
'{"contents":"read"}' | '{"contents":"none"}') ;;
|
|
||||||
null) error "${workflow}: top level permissions not found; it must be 'contents: read' or weaker permissions" ;;
|
|
||||||
*) error "${workflow}: only 'contents: read' and weaker permissions are allowed at top level; if you want to use stronger permissions, please set job-level permissions" ;;
|
|
||||||
esac
|
|
||||||
# Make sure the 'needs' section is not out of date.
|
|
||||||
if grep -q '# tidy:needs' "${workflow}" && ! grep -Eq '# *needs: \[' "${workflow}"; then
|
|
||||||
# shellcheck disable=SC2207
|
|
||||||
jobs_actual=($(yq '.jobs' "${workflow}" | jq -r 'keys_unsorted[]'))
|
|
||||||
unset 'jobs_actual[${#jobs_actual[@]}-1]'
|
|
||||||
# shellcheck disable=SC2207
|
|
||||||
jobs_expected=($(yq -r '.jobs."ci-success".needs[]' "${workflow}"))
|
|
||||||
if [[ "${jobs_actual[*]}" != "${jobs_expected[*]+"${jobs_expected[*]}"}" ]]; then
|
|
||||||
printf -v jobs '%s, ' "${jobs_actual[@]}"
|
|
||||||
sed -i "s/needs: \[.*\] # tidy:needs/needs: [${jobs%, }] # tidy:needs/" "${workflow}"
|
|
||||||
check_diff "${workflow}"
|
|
||||||
error "${workflow}: please update 'needs' section in 'ci-success' job"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
done
|
if [[ ! -d .venv ]]; then
|
||||||
|
python"${py_prefix}" -m venv .venv
|
||||||
|
fi
|
||||||
|
if [[ ! -e .venv/bin/yq ]]; then
|
||||||
|
.venv/bin/pip"${py_prefix}" install yq
|
||||||
|
fi
|
||||||
|
for workflow in .github/workflows/*.yml; do
|
||||||
|
# The top-level permissions must be weak as they are referenced by all jobs.
|
||||||
|
permissions=$(.venv/bin/yq -c '.permissions' "${workflow}")
|
||||||
|
case "${permissions}" in
|
||||||
|
'{"contents":"read"}' | '{"contents":"none"}') ;;
|
||||||
|
null) error "${workflow}: top level permissions not found; it must be 'contents: read' or weaker permissions" ;;
|
||||||
|
*) error "${workflow}: only 'contents: read' and weaker permissions are allowed at top level; if you want to use stronger permissions, please set job-level permissions" ;;
|
||||||
|
esac
|
||||||
|
# Make sure the 'needs' section is not out of date.
|
||||||
|
if grep -q '# tidy:needs' "${workflow}" && ! grep -Eq '# *needs: \[' "${workflow}"; then
|
||||||
|
# shellcheck disable=SC2207
|
||||||
|
jobs_actual=($(.venv/bin/yq '.jobs' "${workflow}" | jq -r 'keys_unsorted[]'))
|
||||||
|
unset 'jobs_actual[${#jobs_actual[@]}-1]'
|
||||||
|
# shellcheck disable=SC2207
|
||||||
|
jobs_expected=($(.venv/bin/yq -r '.jobs."ci-success".needs[]' "${workflow}"))
|
||||||
|
if [[ "${jobs_actual[*]}" != "${jobs_expected[*]+"${jobs_expected[*]}"}" ]]; then
|
||||||
|
printf -v jobs '%s, ' "${jobs_actual[@]}"
|
||||||
|
sed -i "s/needs: \[.*\] # tidy:needs/needs: [${jobs%, }] # tidy:needs/" "${workflow}"
|
||||||
|
check_diff "${workflow}"
|
||||||
|
error "${workflow}: please update 'needs' section in 'ci-success' job"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
else
|
||||||
|
warn "'python3' is not installed; skipped GitHub workflow check"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
warn "'jq' or 'yq' is not installed; skipped GitHub workflow check"
|
warn "'jq' is not installed; skipped GitHub workflow check"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user