Add shell linting and tidying and update all shell scripts
This commit is contained in:
parent
c464bd9469
commit
9b467e6799
@ -1,3 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
set -x
|
set -x
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
@ -12,4 +14,4 @@ if [ -z "$VERSION" ]; then
|
|||||||
VERSION=$(echo "$JSON" | jq -r ".tag_name")
|
VERSION=$(echo "$JSON" | jq -r ".tag_name")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "cross-version=$VERSION" >> $GITHUB_OUTPUT
|
echo "cross-version=$VERSION" >>"$GITHUB_OUTPUT"
|
||||||
|
|||||||
@ -1,32 +1,37 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
|
set -x
|
||||||
|
|
||||||
function run() {
|
function run() {
|
||||||
echo $1
|
echo "$1"
|
||||||
eval $1
|
eval "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
function install_tools() {
|
function install_tools() {
|
||||||
curl --silent --location \
|
curl --silent --location \
|
||||||
https://raw.githubusercontent.com/houseabsolute/ubi/master/bootstrap/bootstrap-ubi.sh |
|
https://raw.githubusercontent.com/houseabsolute/ubi/master/bootstrap/bootstrap-ubi.sh |
|
||||||
sh
|
sh
|
||||||
run "ubi --project houseabsolute/precious --in ~/bin"
|
run "ubi --project houseabsolute/precious --in $HOME/bin"
|
||||||
run "ubi --project houseabsolute/omegasort --in ~/bin"
|
run "ubi --project houseabsolute/omegasort --in $HOME/bin"
|
||||||
|
run "ubi --project koalaman/shellcheck --in $HOME/bin"
|
||||||
|
run "ubi --project mvdan/sh --in $HOME/bin --exe shfmt"
|
||||||
|
run "ubi --project crate-ci/typos --in $HOME/bin"
|
||||||
run "npm install prettier"
|
run "npm install prettier"
|
||||||
run "curl -L https://cpanmin.us/ -o ~/bin/cpanm"
|
run "curl -L https://cpanmin.us/ -o $HOME/bin/cpanm"
|
||||||
run "chmod 0755 ~/bin/cpanm"
|
run "chmod 0755 $HOME/bin/cpanm"
|
||||||
run "~/bin/cpanm --sudo --notest Perl::Tidy"
|
run "$HOME/bin/cpanm --sudo --notest Perl::Tidy"
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "$1" == "-v" ]; then
|
if [ "$1" == "-v" ]; then
|
||||||
set -x
|
set -x
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p $HOME/bin
|
mkdir -p "$HOME"/bin
|
||||||
|
|
||||||
set +e
|
set +e
|
||||||
echo ":$PATH:" | grep --extended-regexp ":$HOME/bin:" >&/dev/null
|
echo ":$PATH:" | grep --extended-regexp ":$HOME/bin:" >&/dev/null
|
||||||
|
# shellcheck disable=SC2181
|
||||||
if [ "$?" -eq "0" ]; then
|
if [ "$?" -eq "0" ]; then
|
||||||
path_has_home_bin=1
|
path_has_home_bin=1
|
||||||
fi
|
fi
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
declare -i status
|
||||||
status=0
|
status=0
|
||||||
|
|
||||||
PRECIOUS=$(which precious)
|
PRECIOUS=$(which precious)
|
||||||
@ -7,8 +8,7 @@ if [[ -z $PRECIOUS ]]; then
|
|||||||
PRECIOUS=./bin/precious
|
PRECIOUS=./bin/precious
|
||||||
fi
|
fi
|
||||||
|
|
||||||
"$PRECIOUS" lint -s
|
if ! "$PRECIOUS" lint -s; then
|
||||||
if (( $? != 0 )); then
|
|
||||||
status+=1
|
status+=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ VERSION="$2"
|
|||||||
|
|
||||||
cd "$CROSS_DIR"
|
cd "$CROSS_DIR"
|
||||||
|
|
||||||
if [[ -n "$VERSION" ]] && ! [[ "$VERSION" =~ ^v ]]; then
|
if [[ -n $VERSION ]] && ! [[ $VERSION =~ ^v ]]; then
|
||||||
cargo install cross --git https://github.com/cross-rs/cross --rev "$VERSION"
|
cargo install cross --git https://github.com/cross-rs/cross --rev "$VERSION"
|
||||||
mv "$HOME/.cargo/bin/cross" .
|
mv "$HOME/.cargo/bin/cross" .
|
||||||
exit 0
|
exit 0
|
||||||
@ -24,4 +24,5 @@ export TARGET=.
|
|||||||
curl --silent --location \
|
curl --silent --location \
|
||||||
https://raw.githubusercontent.com/houseabsolute/ubi/master/bootstrap/bootstrap-ubi.sh |
|
https://raw.githubusercontent.com/houseabsolute/ubi/master/bootstrap/bootstrap-ubi.sh |
|
||||||
sh
|
sh
|
||||||
|
# shellcheck disable=SC2086
|
||||||
./ubi --project cross-rs/cross --matching musl --in . $VERSION_ARGS
|
./ubi --project cross-rs/cross --matching musl --in . $VERSION_ARGS
|
||||||
|
|||||||
@ -45,3 +45,19 @@ ignore_stderr = [
|
|||||||
"The .+ file is not sorted",
|
"The .+ file is not sorted",
|
||||||
"The .+ file is not unique",
|
"The .+ file is not unique",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[commands.shellcheck]
|
||||||
|
type = "lint"
|
||||||
|
include = "**/*.sh"
|
||||||
|
cmd = "shellcheck"
|
||||||
|
ok_exit_codes = 0
|
||||||
|
lint_failure_exit_codes = 1
|
||||||
|
|
||||||
|
[commands.shfmt]
|
||||||
|
type = "both"
|
||||||
|
include = "**/*.sh"
|
||||||
|
cmd = ["shfmt", "--simplify", "--indent", "4"]
|
||||||
|
lint_flags = "--diff"
|
||||||
|
tidy_flags = "--write"
|
||||||
|
ok_exit_codes = 0
|
||||||
|
lint_failure_exit_codes = 1
|
||||||
|
|||||||
@ -1,9 +1,12 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
set -x
|
set -x
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
CROSS_DIR="$1"
|
CROSS_DIR="$1"
|
||||||
if [ -f "$CROSS_DIR/cross" ]; then
|
if [ -f "$CROSS_DIR/cross" ]; then
|
||||||
echo "build-command=$CROSS_DIR/cross" >> $GITHUB_OUTPUT
|
echo "build-command=$CROSS_DIR/cross" >>"$GITHUB_OUTPUT"
|
||||||
else
|
else
|
||||||
echo "build-command=cargo" >> $GITHUB_OUTPUT
|
echo "build-command=cargo" >>"$GITHUB_OUTPUT"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@ -1,12 +1,15 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
set -x
|
set -x
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
TARGET="$1"
|
TARGET="$1"
|
||||||
|
|
||||||
# On macOS and Windows, we can cross-compile to all possible targets without
|
# On macOS and Windows, we can cross-compile to all possible targets without
|
||||||
# using cross.
|
# using cross.
|
||||||
if uname -a | grep --quiet --extended-regexp -i "darwin|msys|windows"; then
|
if uname -a | grep --quiet --extended-regexp -i "darwin|msys|windows"; then
|
||||||
echo "needs-cross=false" >> $GITHUB_OUTPUT
|
echo "needs-cross=false" >>"$GITHUB_OUTPUT"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -15,8 +18,8 @@ fi
|
|||||||
# feature. This feature makes it compile openssl itself, which fails without
|
# feature. This feature makes it compile openssl itself, which fails without
|
||||||
# cross.
|
# cross.
|
||||||
if echo "$TARGET" | grep --quiet --extended-regexp -i 'x86_64.+linux-(gnu|musl)'; then
|
if echo "$TARGET" | grep --quiet --extended-regexp -i 'x86_64.+linux-(gnu|musl)'; then
|
||||||
echo "needs-cross=false" >> $GITHUB_OUTPUT
|
echo "needs-cross=false" >>"$GITHUB_OUTPUT"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "needs-cross=true" >> $GITHUB_OUTPUT
|
echo "needs-cross=true" >>"$GITHUB_OUTPUT"
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
set -x
|
set -x
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
echo "cross-dir=$RUNNER_TEMP" >> $GITHUB_OUTPUT
|
echo "cross-dir=$RUNNER_TEMP" >>"$GITHUB_OUTPUT"
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
set -x
|
set -x
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
TARGET=$1
|
TARGET=$1
|
||||||
did_strip=""
|
did_strip=""
|
||||||
@ -7,14 +10,14 @@ did_strip=""
|
|||||||
strip_binary() {
|
strip_binary() {
|
||||||
if [[ $(uname -s) =~ "Darwin" ]]; then
|
if [[ $(uname -s) =~ "Darwin" ]]; then
|
||||||
stripped=$(
|
stripped=$(
|
||||||
find "$1" -maxdepth 1 -type f -perm +111 | while read exe; do
|
find "$1" -maxdepth 1 -type f -perm +111 | while read -r exe; do
|
||||||
strip "$exe"
|
strip "$exe"
|
||||||
echo "stripped $exe"
|
echo "stripped $exe"
|
||||||
done
|
done
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
stripped=$(
|
stripped=$(
|
||||||
find "$1" -maxdepth 1 -type f -executable | while read exe; do
|
find "$1" -maxdepth 1 -type f -executable | while read -r exe; do
|
||||||
strip "$exe"
|
strip "$exe"
|
||||||
echo "stripped $exe"
|
echo "stripped $exe"
|
||||||
done
|
done
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user