Repository navigation
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·109 lines (92 loc) · 4.06 KB
/
Copy pathentrypoint.sh
File metadata and controls
executable file
·109 lines (92 loc) · 4.06 KB
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
#!/bin/bash -l
set -uo pipefail
# We use ‘set +e’ to prevent the script from exiting immediately if lychee fails.
# This ensures that:
# 1. Lychee exit code can be captured and passed to subsequent steps via `$GITHUB_OUTPUT`.
# 2. This step’s outcome (success/failure) can be controlled according to inputs
# by manually calling the ‘exit’ command.
set +e
# Enable optional debug output
if [ "${INPUT_DEBUG}" = true ]; then
echo "Debug output enabled"
set -x
fi
LYCHEE_TMP="$(mktemp)"
GITHUB_WORKFLOW_URL="https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}?check_suite_focus=true"
# If custom GitHub token is set, export it as environment variable
if [ -n "${INPUT_TOKEN:-}" ]; then
export GITHUB_TOKEN="${INPUT_TOKEN}"
fi
ARGS="${INPUT_ARGS}"
FORMAT=""
# Backwards compatibility:
# If `format` occurs in args, ignore the value from `INPUT_FORMAT`
[[ "$ARGS" =~ "--format " ]] || FORMAT="--format ${INPUT_FORMAT}"
# If `output` occurs in args and `INPUT_OUTPUT` is set, exit with an error
if [[ "$ARGS" =~ "--output " ]] && [ -n "${INPUT_OUTPUT:-}" ]; then
echo "Error: 'output' is set in args as well as in the action configuration. Please remove one of them."
exit 1
fi
# If `--mode` occurs in args and `INPUT_CHECKBOX` is set, exit with an error
# Use `--mode` instead of `--mode task` to ensure that the checkbox is not getting overwritten
if [[ "$ARGS" =~ "--mode" ]] && [ -n "${INPUT_CHECKBOX:-}" ]; then
echo "Error: '--mode' is set in args but 'checkbox' is set in the action configuration. Please remove one of them to avoid conflicts."
exit 1
fi
CHECKBOX=""
if [ "${INPUT_CHECKBOX}" = true ]; then
# Warn if the version is lower than 0.18.1
function version_lt() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" != "$1"; }
lychee_version="$(lychee --version | head -n1 | cut -d" " -f2)"
if version_lt "$lychee_version" "0.18.1"; then
echo "WARNING: 'checkbox' is not supported in lychee versions lower than 0.18.1 (current is $lychee_version). Continuing without 'checkbox'."
else
CHECKBOX="--mode task"
fi
fi
# Execute lychee
eval lychee ${CHECKBOX} ${FORMAT} --output ${LYCHEE_TMP} ${ARGS}
LYCHEE_EXIT_CODE=$?
# If no links were found and `failIfEmpty` is set to `true` (and it is by default),
# fail with an error later, but leave lychee exit code untouched.
should_fail_because_empty=false
if [ "${INPUT_FAILIFEMPTY}" = "true" ]; then
# This is a somewhat crude way to check the Markdown output of lychee
if grep -E 'Total\s+\|\s+0' "${LYCHEE_TMP}"; then
echo "No links were found. This usually indicates a configuration error." >> "${LYCHEE_TMP}"
echo "If this was expected, set 'failIfEmpty: false' in the args." >> "${LYCHEE_TMP}"
should_fail_because_empty=true
fi
fi
if [ ! -f "${LYCHEE_TMP}" ]; then
echo "No output. Check pipeline run to see if lychee panicked." > "${LYCHEE_TMP}"
else
# If we have any output, create a report in the designated directory
mkdir -p "$(dirname -- "${INPUT_OUTPUT}")"
cat "${LYCHEE_TMP}" > "${INPUT_OUTPUT}"
if [ "${INPUT_FORMAT}" == "markdown" ]; then
echo "[Full Github Actions output](${GITHUB_WORKFLOW_URL})" >> "${INPUT_OUTPUT}"
fi
fi
# Output to console
cat "${LYCHEE_TMP}"
echo
if [ "${INPUT_FORMAT}" == "markdown" ]; then
if [ "${INPUT_JOBSUMMARY}" = true ]; then
cat "${LYCHEE_TMP}" > "${GITHUB_STEP_SUMMARY}"
# Log a message with the URL to the Summary report
echo "::notice::Summary report available at: ${SUMMARY_URL}"
fi
fi
# Pass lychee exit code to subsequent steps
echo "exit_code=$LYCHEE_EXIT_CODE" >> "$GITHUB_OUTPUT"
# Determine the outcome of this step
# Exiting with a nonzero value will fail the pipeline, but the specific value
# does not matter. (GitHub does not share it with subsequent steps for composite actions.)
if [ "$should_fail_because_empty" = true ] ; then
# If we decided previously to fail because no links were found, fail
exit 1
elif [ "$INPUT_FAIL" = true ] ; then
# If `fail` is set to `true` (and it is by default), propagate lychee exit code
exit ${LYCHEE_EXIT_CODE}
fi