test
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
mol
2024-07-06 22:23:31 +08:00
parent 08173d8497
commit 263cb5ef03
1663 changed files with 526884 additions and 0 deletions

View File

@ -0,0 +1,66 @@
#!/bin/bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
if [[ "$*" = *--view* ]]; then
VIEW_ONLY=1
fi
: ${WORKFLOW:=npm-publish.yml}
: ${JOB:=publish-npm}
: ${BRANCH:=github-workflows}
: ${VERSION:="minor (x.y+1.0, new functionality)"}
WORKFLOW_FILE="$SCRIPT_DIR/../.github/workflows/$WORKFLOW_FILE"
function echo-var {
echo "$1=${!1}"
}
function upload-changes {
git diff --quiet "$WORKFLOW_FILE"
if [ $? -eq 1 ]; then
echo "Uploading changes"
git add "$WORKFLOW_FILE"
git commit -m "Update $WORKFLOW_FILE"
# git push origin "$BRANCH"
git push origin "$BRANCH" -f
fi
}
function run-workflow {
LAST_RUN_ID=$(gh run list --workflow="$WORKFLOW" --json number,databaseId --jq 'sort_by(.number) | .[-1] | .databaseId')
if [ -n "$WORKFLOW_ARGS" ]; then
WORKFLOW_ARGS=($WORKFLOW_ARGS)
else
if [ "$WORKFLOW" = "npm-publish.yml" ]; then
WORKFLOW_ARGS=(-f "version=$VERSION")
fi
fi
gh workflow run "$WORKFLOW" --ref "$BRANCH" "${WORKFLOW_ARGS[@]}"
RUN_ID="$LAST_RUN_ID"
}
function view-workflow {
while [ "$RUN_ID" = "$LAST_RUN_ID" ]; do
MOST_RECENT_RUN=$(gh run list --workflow="$WORKFLOW" --json number,databaseId,status --jq 'sort_by(.number) | .[-1] | "\(.databaseId);\(.status)"')
RUN_ID=${MOST_RECENT_RUN%;*}
RUN_STATUS=${MOST_RECENT_RUN#*;}
done
if [ "$RUN_STATUS" != "completed" ]; then
gh run watch $RUN_ID
fi
gh run view $RUN_ID --log | grep "$JOB" | grep -v '@v'
if [ $? -ne 0 ]; then
# xargs is only used for trimming
ANNOTATION=$(curl "https://github.com/aadsm/jschardet/actions/runs/$RUN_ID" 2>/dev/null | grep 'annotation-message.annotationContainer' -A 1 | tail -n 1 | xargs)
ANNOTATION=${ANNOTATION##<div>}
ANNOTATION=${ANNOTATION%%</div>}
echo "Annotation: $ANNOTATION"
fi
}
if [ -z $VIEW_ONLY ]; then
upload-changes
run-workflow
fi
view-workflow

View File

@ -0,0 +1,67 @@
#!/bin/bash
# https://stackoverflow.com/a/30520299
# Checks if stdout is not being redirected, and if not, colorizes the output.
if [[ -t 1 || -p /dev/stdout ]]; then
# ANSI colors
RED='\033[0;31m'
GREEN='\033[0;32m'
TC='\033[0m' # Terminal color
fi
function calc_perc {
# Calculate the percentage up to 2 decimal places and leading 0 when the
# percentage only has the decimal part. Only print percentages >= 0.01%.
bc <<EOF
scale=2;
define abs2(x) { if (x < 0) return -x; return x }
ratio=$1/$2;
if (ratio >= 0.01) {
if (ratio < 0) {
print "-"
} else {
print "+"
}
if (abs2(ratio) < 1) {
print "0"
}
print abs2(ratio)
print "% "
}
EOF
}
if [ -z "$BASE_PKG_VERSION" ]; then
BASE_PKG_VERSION="$(npm version --json | python3 -c 'import json; import sys; print(json.loads(sys.stdin.read()).get("jschardet"))')"
fi
BASE_PKG_VERSION_HASH="$(git rev-list -n 1 v$BASE_PKG_VERSION)"
echo "Bundle size changes since v$BASE_PKG_VERSION:"
eval "git diff-index "$BASE_PKG_VERSION_HASH" $@" | {
# vars: B=before / A=after
# mode: A=added / D=deleted
while read maskB maskA hashB zero mode path; do
if [ $mode = "A" ]; then
sizeB=0;
else
sizeB=$(git cat-file -s $hashB)
fi
if [ $mode = "D" ]; then
sizeA=0
else
# warning: -s is bsd only
eval $(stat -s "$path")
sizeA=$st_size
fi
size_diff=$(( $sizeA - $sizeB ))
if [ $size_diff -gt 0 ]; then
size_diff_signal="+"
size_diff_color=$RED
else
size_diff_color=$GREEN
fi
perc=$(calc_perc $size_diff $sizeB)
echo -e "* $path $size_diff_color$size_diff_signal$size_diff $perc$TC($sizeB -> $sizeA)"
done
}