Skip to content

Initialize the orb shader animation-time variable #2

Initialize the orb shader animation-time variable

Initialize the orb shader animation-time variable #2

Workflow file for this run

name: Format Check
on:
pull_request:
paths: ['**.lua']
permissions:
contents: read
jobs:
stylua:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# Pull down only the PR's changed files and the formatter's own config files
filter: blob:none
# Cone mode cannot filter correctly for our repo, picks up asset files, etc.
sparse-checkout-cone-mode: false
sparse-checkout: |
/.stylua.toml
/.styluaignore
/.gitattributes
*.lua
- name: Install stylua
env:
# Pinned so previously passing PRs do not become flagged on upgrade.
STYLUA_VERSION: "2.5.2"
run: |
curl -fsSL -o stylua.zip \
"https://github.com/JohnnyMorganz/StyLua/releases/download/v${STYLUA_VERSION}/stylua-linux-x86_64.zip"
unzip -q stylua.zip stylua
chmod +x stylua
./stylua --version
- name: Check formatting of changed files
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: |
# The pull request checkout only holds the merge commit, so the base
# revision has to be fetched before anything can be diffed against it.
git fetch --no-tags --depth=1 origin "$BASE_SHA"
# Lua paths can contain spaces, so the list is NUL-separated.
git diff --name-only -z --diff-filter=ACMR "$BASE_SHA" HEAD -- '*.lua' > changed.txt
if [ ! -s changed.txt ]; then
echo "No Lua files changed."
exit 0
fi
echo "Checking:"
tr '\0' '\n' < changed.txt
# No human being fixes their formatting by reading a diff from a linter
# so we prevent the logging of any diff. The JSON check output reports
# formatting mismatches per file on stdout and parse errs on stderr, so
# we consume these and produce a concise file list into the output log,
# while making sure our ignore list is respected as well. It is a mess.
set +e
xargs -0r ./stylua --check --respect-ignores --output-format Json \
< changed.txt > mismatches.json 2> errors.json
stylua_status=$?
set -e
if ! jq -e -s 'type == "array"' mismatches.json > /dev/null 2>&1; then
echo "::error title=Formatting check is broken::stylua wrote an unreadable Json report (exit $stylua_status). This is a CI defect, not a problem with this PR; fix format_check.yml or its pinned stylua."
cat mismatches.json errors.json
exit 1
fi
jq -r '.file' mismatches.json | sort -u > misformatted.txt
# Swallow any parse errors from stylua and leave them to the emmylua ci.
# Nonzero exit status from stylua still needs a backstop against crashes.
parse_errors=0
: > errlines.txt
if [ -s errors.json ]; then
if jq -e . errors.json > /dev/null 2>&1; then
parse_errors=$(jq -r '
if type == "array" then .[] else . end
| select(.type == "parse_error")
| .filename // "stylua"
' errors.json | wc -l)
# Anything that is not a parse error means the check itself hit
# trouble, so it stays visible.
jq -r '
if type == "array" then .[] else . end
| select(.type != "parse_error")
| "\(.filename // "stylua")\(if .location then ":\(.location.start_line)" else "" end): \(.message)"
' errors.json > errlines.txt
else
# A report that is not JSON (a crash or etc) is kept raw.
cp errors.json errlines.txt
fi
fi
# Pass or fail is decided from reports, not status, to backstop a crash.
bad_files=$(wc -l < misformatted.txt)
if [ "$bad_files" -eq 0 ] && [ ! -s errlines.txt ]; then
if [ "$stylua_status" -ne 0 ] && [ "$parse_errors" -eq 0 ]; then
echo "::error title=Formatting check is broken::stylua exited $stylua_status without reporting anything. This is a CI defect, not a problem with this PR; fix format_check.yml or its pinned stylua."
exit 1
fi
echo "All changed files are formatted."
exit 0
fi
ver=$(./stylua --version)
if [ "$bad_files" -gt 0 ]; then
echo "$bad_files file(s) are not formatted with $ver:"
cat misformatted.txt
fi
if [ -s errlines.txt ]; then
echo "stylua reported errors:"
cat errlines.txt
fi
if [ "$bad_files" -gt 10 ]; then
while IFS= read -r file; do
folder=${file%/*}
[ "$folder" = "$file" ] && folder="(root)"
printf '%s\n' "$folder"
done < misformatted.txt | sort | uniq -c | sort -rn > folders.txt
bad_folders=$(wc -l < folders.txt)
fi
# Format mismatches render as github annotation bubbles on the first line.
# Leaving line=off annotates against the zeroth line, which does not exist.
# Stylua indexes from zero while github indexes from one, in this case.
# GH keeps up to 10 annotation bubbles and discards the rest (kept in logs)
# so these are sorted by the worst offenders, determined by total diff size.
jq -s -r --arg ver "$ver" '
def esc: gsub("%"; "%25") | gsub("\r"; "%0D") | gsub("\n"; "%0A");
def prop: esc | gsub(","; "%2C") | gsub(":"; "%3A");
map(
. as $f
| ([ .mismatches[]?.original_start_line ] | min) as $first
| (if $first == null or $first < 0 then 1 else $first + 1 end) as $line
| ([ .mismatches[]?
| ([ (.original_end_line - .original_start_line),
(.expected_end_line - .expected_start_line) ] | max) + 1
] | add // 1) as $lines
| { file: $f.file, line: $line, lines: $lines }
)
| sort_by(-.lines)
| .[0:10][]
| "::error file=\(.file | prop),line=\(.line),title=Not formatted::\(.lines) line(s) would change. Run \($ver) on this file and commit the result."
' mismatches.json
# GH annotation cap of 10 is per-category, so folder rollups use warnings.
if [ "$bad_files" -gt 10 ] && [ "$bad_folders" -le 10 ]; then
while read -r count folder; do
echo "::warning title=Not formatted::$folder: $count file(s)"
done < folders.txt
fi
# Notices are a third pool, which we use to notify of >10 in other pools.
if [ "$bad_files" -gt 10 ]; then
echo "::notice title=Formatting::$bad_files file(s) are not formatted; the 10 largest are annotated and the job summary lists them all."
elif [ "$bad_files" -gt 0 ]; then
echo "::notice title=Formatting::$bad_files file(s) are not formatted."
fi
# One last clever-ish trick: When the file count is >10, list by folder.
# When the folder count is >10, throw our hands up in the air, give up.
{
echo "### Formatting check failed"
echo
if [ "$bad_files" -gt 0 ]; then
echo "$bad_files changed file(s) are not formatted. Run $ver on them and commit the result."
echo
if [ "$bad_files" -le 10 ]; then
sed -e 's/^/- `/' -e 's/$/`/' misformatted.txt
elif [ "$bad_folders" -le 10 ]; then
while read -r count folder; do
echo "- \`$folder\`: $count file(s)"
done < folders.txt
else
echo "The files span $bad_folders folders; the workflow log lists every one."
fi
fi
if [ -s errlines.txt ]; then
echo
echo "stylua could not check every file:"
echo
sed 's/^/- /' errlines.txt
fi
} >> "$GITHUB_STEP_SUMMARY"
exit 1