Skip to content

Commit

Permalink
Add "code" (shell) linter and format checker (#32)
Browse files Browse the repository at this point in the history
* Add "code" (shell) linter and format checker

This uses:

- shellcheck
- shfmt

behind the scenes

* Relax validations

* ShellCheck all shell scripts

* shfmt all shell scripts

* Check .exs format (in scripts)

* Update CI names

* Act on self-review
  • Loading branch information
paulo-ferraz-oliveira authored Nov 13, 2024
1 parent dab2931 commit 14c4eb4
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 66 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
"on":
push:
branches:
- main
pull_request:
branches:
- "*"
workflow_dispatch: {}

name: Checks

jobs:
checks:
name: Checks

runs-on: ubuntu-24.04

steps:
- uses: actions/[email protected]

- name: shell scripts check
uses: luizm/[email protected]
env:
SHFMT_OPTS: -i 2 -d

- uses: erlef/[email protected]
with:
otp-version: 27
elixir-version: 1.17

- name: exs format check
run: |
mix format --check-formatted scripts/*.exs
41 changes: 22 additions & 19 deletions scripts/build_otp_macos.bash
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ EOF
local ref_name=$1

case "${ref_name}" in
OTP-25* | OTP-26.0* | OTP-26.1)
WXWIDGETS_VERSION=disabled
;;
*)
;;
OTP-25* | OTP-26.0* | OTP-26.1)
WXWIDGETS_VERSION=disabled
;;
*) ;;
esac

: "${BUILD_DIR:=${PWD}/tmp/otp_builds}"
Expand Down Expand Up @@ -52,7 +51,7 @@ build_openssl() {
return
fi

if [[ $version == 3* ]]; then
if [[ "$version" == 3* ]]; then
local ref_name="openssl-${version}"
else
local ref_name="OpenSSL_${version//./_}"
Expand All @@ -66,6 +65,7 @@ build_openssl() {
(
cd "${src_dir}"
git clean -dfx
# shellcheck disable=SC2086
./config no-shared --prefix="${rel_dir}" ${CFLAGS}
make
make install_sw
Expand Down Expand Up @@ -118,7 +118,7 @@ test_otp() {
{ok, _} = application:ensure_all_started(crypto), io:format("crypto ok~n"),
halt().'

if dyld_info ${OTP_DIR}/lib/crypto-*/priv/lib/crypto.so | tail -n +2 | grep -q openssl; then
if dyld_info "${OTP_DIR}/lib/crypto-*/priv/lib/crypto.so" | tail -n +2 | grep -q openssl; then
echo "error: openssl dynamically linked"
exit 1
fi
Expand All @@ -128,7 +128,7 @@ test_otp() {
wx:new(), io:format("wx ok~n"),
halt().'

if dyld_info ${OTP_DIR}/lib/wx-*/priv/wxe_driver.so | tail -n +2 | grep -q wxwidgets; then
if dyld_info "${OTP_DIR}/lib/wx-*/priv/wxe_driver.so" | tail -n +2 | grep -q wxwidgets; then
echo "error: wx dynamically linked"
exit 1
fi
Expand Down Expand Up @@ -188,24 +188,25 @@ build_otp() {
fi

if [[ "${WXWIDGETS_VERSION}" = disabled ]]; then
wxwidgets_flags=--without-{wx,observer,debugger,et}
wxwidgets_flags="--without-{wx,observer,debugger,et}"
else
wxwidgets_flags=""
fi

case "${arch}" in
x86_64)
target="x86_64-apple-darwin"
;;
arm64)
target="aarch64-apple-darwin"
;;
*)
echo "Unknown architecture: ${arch}"
exit 1
;;
x86_64)
target="x86_64-apple-darwin"
;;
arm64)
target="aarch64-apple-darwin"
;;
*)
echo "Unknown architecture: ${arch}"
exit 1
;;
esac

# shellcheck disable=SC2086
./otp_build configure \
--build="${target}" \
--host="${target}" \
Expand All @@ -224,6 +225,7 @@ build_otp() {

export PATH="${rel_dir}/bin:${PATH}"

# shellcheck disable=SC2310
if ! test_otp; then
rm -rf "${rel_dir}"
fi
Expand All @@ -236,4 +238,5 @@ build_tgz() {
tar czf "${OTP_TGZ}" --cd "${OTP_DIR}" .
}

# shellcheck disable=SC2068
main $@
52 changes: 26 additions & 26 deletions scripts/elixir-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ main() {

for arg in "$@"; do
case "$arg" in
elixir@*)
elixir_version="${arg#elixir@}"
;;
otp@*)
otp_version="${arg#otp@}"
;;
*)
echo "error: invalid argument $arg" >&2
exit 1
;;
elixir@*)
elixir_version="${arg#elixir@}"
;;
otp@*)
otp_version="${arg#otp@}"
;;
*)
echo "error: invalid argument $arg" >&2
exit 1
;;
esac
done

Expand All @@ -27,9 +27,9 @@ main() {

otp_release="${otp_version%%.*}"

if [ "${otp_version}" = "master" ] || \
[ "${otp_version}" = "latest" ] || \
echo "${otp_version}" | grep -q '^maint'; then
if [ "${otp_version}" = "master" ] ||
[ "${otp_version}" = "latest" ] ||
echo "${otp_version}" | grep -q '^maint'; then
elixir_otp_release=27
else
elixir_otp_release=$otp_release
Expand Down Expand Up @@ -63,23 +63,23 @@ main() {
install_otp() {
os=$(uname -s)
case "$os" in
Darwin) os=darwin ;;
Linux) os=linux ;;
MINGW64*) os=windows ;;
*) echo "error: unsupported OS: $os." && exit 1 ;;
Darwin) os=darwin ;;
Linux) os=linux ;;
MINGW64*) os=windows ;;
*) echo "error: unsupported OS: $os." && exit 1 ;;
esac

arch=$(uname -m)
case "$arch" in
x86_64)
macos_target=x86_64-apple-darwin
linux_target=amd64
;;
aarch64|arm64)
macos_target=aarch64-apple-darwin
linux_target=arm64
;;
*) echo "error: unsupported architecture: $arch." && exit 1 ;;
x86_64)
macos_target=x86_64-apple-darwin
linux_target=amd64
;;
aarch64 | arm64)
macos_target=aarch64-apple-darwin
linux_target=arm64
;;
*) echo "error: unsupported architecture: $arch." && exit 1 ;;
esac

if [ ! -d "$otp_dir/bin" ]; then
Expand Down
11 changes: 6 additions & 5 deletions scripts/update_builds.bash
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,22 @@ push() {
git checkout "${target_branch}"
git reset --hard "origin/${target_branch}"
git pull origin "${target_branch}"
build_sha256=$(shasum -a 256 $TGZ | cut -d ' ' -f 1)
build_sha256=$(shasum -a 256 "$TGZ" | cut -d ' ' -f 1)
date=$(date -u '+%Y-%m-%dT%H:%M:%SZ')
mkdir -p builds/
touch "${BUILDS_CSV}"
sed -i.bak "/^${OTP_REF_NAME},/d" "${BUILDS_CSV}"
rm "${BUILDS_CSV}.bak"
echo -ne "${OTP_REF_NAME},${OTP_REF},${date},${build_sha256},openssl-${OPENSSL_VERSION},wxwidgets-${WXWIDGETS_VERSION}\n$(cat ${BUILDS_CSV})" > "${BUILDS_CSV}"
echo -ne "${OTP_REF_NAME},${OTP_REF},${date},${build_sha256},openssl-${OPENSSL_VERSION},wxwidgets-${WXWIDGETS_VERSION}\n$(cat "${BUILDS_CSV}")" >"${BUILDS_CSV}"
sort --reverse --unique -k1,1 -o "${BUILDS_CSV}" "${BUILDS_CSV}"
git add builds/
GIT_AUTHOR_NAME="${GITHUB_ACTOR}" \
GIT_AUTHOR_EMAIL="${GITHUB_ACTOR}@users.noreply.github.com" \
GIT_COMMITTER_NAME="github-actions[bot]" \
GIT_COMMITTER_EMAIL="github-actions[bot]@users.noreply.github.com" \
GIT_AUTHOR_EMAIL="${GITHUB_ACTOR}@users.noreply.github.com" \
GIT_COMMITTER_NAME="github-actions[bot]" \
GIT_COMMITTER_EMAIL="github-actions[bot]@users.noreply.github.com" \
git commit -m "${BUILDS_CSV}: Add ${OTP_REF_NAME}"
git push origin "${target_branch}"
}

# shellcheck disable=SC2068
main $@
34 changes: 18 additions & 16 deletions scripts/upload.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -euo pipefail

usage() {
cat<<EOF
cat <<EOF
ref_name=OTP-27.1.2; \
OTP_REF_NAME="${ref_name}" \
OPENSSL_VERSION=3.1.6 \
Expand All @@ -19,7 +19,7 @@ main() {
: "${ATTESTATION:=}"

if [[ -z "${OTP_REF+x}" ]]; then
OTP_REF=$(gh api repos/erlang/otp/commits/${OTP_REF_NAME} --jq .sha)
OTP_REF=$(gh api "repos/erlang/otp/commits/${OTP_REF_NAME}" --jq .sha)
fi

if [[ "${OTP_REF_NAME}" = master ]] || echo "${OTP_REF_NAME}" | grep -q "^maint"; then
Expand All @@ -38,8 +38,8 @@ main() {
else
if ! echo "${ref_name}" | grep -qE 'maint|master'; then
if [[ -f builds/aarch64-apple-darwin.csv ]]; then
latest_version=`cat builds/aarch64-apple-darwin.csv | cut -d"," -f1 | grep OTP- | sed 's/OTP-//' | sort --reverse -V | head -1`
version=$(echo "$ref_name" | sed 's/OTP-//')
latest_version=$(cut -d"," -f1 <builds/aarch64-apple-darwin.csv | grep OTP- | sed 's/OTP-//' | sort --reverse -V | head -1)
version=${ref_name/OTP-/}

if [[ $(printf "%s\n%s" "$latest_version" "$version" | sort --reverse -V | head -1) != "$latest_version" ]]; then
extra_flags="--latest"
Expand All @@ -51,6 +51,7 @@ main() {
# Initial commit
target=b5893a3c3a8d0ab54be5d04de450b24d9e5aa149

# shellcheck disable=SC2086
gh release create \
--repo "${GITHUB_REPOSITORY}" \
--title "${ref_name}" \
Expand All @@ -62,18 +63,18 @@ main() {

arch=$(uname -m)
case "${arch}" in
x86_64)
target="x86_64-apple-darwin"
legacy_target="macos-amd64"
;;
arm64)
target="aarch64-apple-darwin"
legacy_target="macos-arm64"
;;
*)
echo "Unknown architecture: ${arch}"
exit 1
;;
x86_64)
target="x86_64-apple-darwin"
legacy_target="macos-amd64"
;;
arm64)
target="aarch64-apple-darwin"
legacy_target="macos-arm64"
;;
*)
echo "Unknown architecture: ${arch}"
exit 1
;;
esac

mkdir -p /tmp/otp_builds
Expand Down Expand Up @@ -107,4 +108,5 @@ main() {
--field target="${target}"
}

# shellcheck disable=SC2068
main $@

0 comments on commit 14c4eb4

Please sign in to comment.