From 03f8e4dcebf4ee055e470799a512556f0d0cb9f6 Mon Sep 17 00:00:00 2001 From: Nikolas Grottendieck Date: Sun, 28 Nov 2021 12:19:58 +0100 Subject: [PATCH] Add GitHub Actions with ShellCheck See https://github.com/mathiasbynens/dotfiles/pull/951 for details --- .editorconfig | 4 ++++ .github/dependabot.yaml | 9 +++++++++ .github/workflows/test.yaml | 10 ++++++++++ bootstrap.sh | 7 ++++--- brew.sh | 2 +- stow/shell/dot-aliases | 3 ++- stow/shell/dot-bash_prompt | 7 ++++--- stow/shell/dot-exports | 4 +++- stow/shell/dot-functions | 31 +++++++++++++++++-------------- 9 files changed, 54 insertions(+), 23 deletions(-) create mode 100644 .github/dependabot.yaml create mode 100644 .github/workflows/test.yaml diff --git a/.editorconfig b/.editorconfig index bec7553240a..afe5aab0583 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,3 +6,7 @@ indent_style = tab end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true + +[*.{yaml, yml}] +indent_style = space +tab_width = 2 diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml new file mode 100644 index 00000000000..eb9d059e7c8 --- /dev/null +++ b/.github/dependabot.yaml @@ -0,0 +1,9 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: "/" + schedule: + interval: daily + time: "03:00" + timezone: Europe/Berlin + open-pull-requests-limit: 99 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 00000000000..834dea56a93 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,10 @@ +name: Test + +on: [push, pull_request] + +jobs: + shellcheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2.3.4 + - uses: bewuethr/shellcheck-action@v2 diff --git a/bootstrap.sh b/bootstrap.sh index 171c2d9019b..61133814f4a 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -cd "$(dirname "${BASH_SOURCE}")"; +cd "$(dirname "${BASH_SOURCE[0]:-$0}")" || exit; git pull --autostash --rebase; @@ -15,13 +15,14 @@ function doIt() { stow --dotfiles -d "stow" "ssh" -t "${HOME}"; stow --dotfiles -d "stow" "vim" -t "${HOME}"; # load new config + # shellcheck disable=SC1090 source ~/.bash_profile; } -if [ "$1" == "--force" -o "$1" == "-f" ]; then +if [ "$1" == "--force" ] || [ "$1" == "-f" ]; then doIt; else - read -p "This may overwrite existing files in your home directory. Are you sure? (y/n) " -n 1; + read -rp "This may overwrite existing files in your home directory. Are you sure? (y/n) " -n 1; echo ""; if [[ $REPLY =~ ^[Yy]$ ]]; then doIt; diff --git a/brew.sh b/brew.sh index 3d21e09a23d..1302002ebc4 100755 --- a/brew.sh +++ b/brew.sh @@ -22,7 +22,7 @@ echo 'Be sure to add `$(brew --prefix gnu-sed)/libexec/gnubin` to `$PATH`.' echo 'If you would like to map vi so it opens the brew-installed vim: ln -s /usr/local/bin/vim /usr/local/bin/vi' # Switch to using brew-installed bash as default shell -if ! fgrep -q "${BREW_PREFIX}/bin/bash" /etc/shells; then +if ! grep -Fq "${BREW_PREFIX}/bin/bash" /etc/shells; then echo "${BREW_PREFIX}/bin/bash" | sudo tee -a /etc/shells; chsh -s "${BREW_PREFIX}/bin/bash"; fi; diff --git a/stow/shell/dot-aliases b/stow/shell/dot-aliases index 9b255cc42b5..cfb68e85e2b 100644 --- a/stow/shell/dot-aliases +++ b/stow/shell/dot-aliases @@ -1,4 +1,5 @@ #!/usr/bin/env bash +# shellcheck disable=SC2139 # Easier navigation: .., ..., ...., ....., ~ and - alias ..="cd .." @@ -123,7 +124,7 @@ alias map="xargs -n1" # One of @janmoesen’s ProTip™s for method in GET HEAD POST PUT DELETE TRACE OPTIONS; do - alias "${method}"="lwp-request -m '${method}'" + alias "${method}=lwp-request -m '${method}'" done # Stuff I never really use but cannot delete either because of http://xkcd.com/530/ diff --git a/stow/shell/dot-bash_prompt b/stow/shell/dot-bash_prompt index 4c09716b0bb..f2ed372be7d 100644 --- a/stow/shell/dot-bash_prompt +++ b/stow/shell/dot-bash_prompt @@ -1,4 +1,5 @@ #!/usr/bin/env bash +# shellcheck disable=SC2034 # Shell prompt based on the Solarized Dark theme. # Screenshot: http://i.imgur.com/EkEtphC.png @@ -35,11 +36,11 @@ prompt_git() { s+='*'; else # Check for uncommitted changes in the index. - if ! $(git diff --quiet --ignore-submodules --cached); then + if ! git diff --quiet --ignore-submodules --cached; then s+='+'; fi; # Check for unstaged changes. - if ! $(git diff-files --quiet --ignore-submodules --); then + if ! git diff-files --quiet --ignore-submodules --; then s+='!'; fi; # Check for untracked files. @@ -47,7 +48,7 @@ prompt_git() { s+='?'; fi; # Check for stashed files. - if $(git rev-parse --verify refs/stash &>/dev/null); then + if git rev-parse --verify refs/stash &>/dev/null; then s+='$'; fi; fi; diff --git a/stow/shell/dot-exports b/stow/shell/dot-exports index 831c36ba855..df30f2ddf87 100644 --- a/stow/shell/dot-exports +++ b/stow/shell/dot-exports @@ -1,4 +1,5 @@ #!/usr/bin/env bash +# shellcheck disable=SC2154 # Make vim the default editor. export EDITOR='vim'; @@ -31,7 +32,8 @@ export LESS_TERMCAP_md="${yellow}"; # Avoid issues with `gpg` as installed via Homebrew. # https://stackoverflow.com/a/42265848/96656 -export GPG_TTY=$(tty); +GPG_TTY=$(tty); +export GPG_TTY # Hide the “default interactive shell is now zsh” warning on macOS. export BASH_SILENCE_DEPRECATION_WARNING=1; diff --git a/stow/shell/dot-functions b/stow/shell/dot-functions index 1c587a3acab..1e5538a2376 100644 --- a/stow/shell/dot-functions +++ b/stow/shell/dot-functions @@ -2,17 +2,17 @@ # Create a new directory and enter it function mkd() { - mkdir -p "$@" && cd "$_"; + mkdir -p "$@" && cd "$_" || return; } # Change working directory to the top-most Finder window location function cdf() { # short for `cdfinder` - cd "$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')"; + cd "$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')" || return; } # Create a .tar.gz archive, using `zopfli`, `pigz` or `gzip` for compression function targz() { - local tmpFile="${@%/}.tar"; + local tmpFile="${*%/}.tar"; tar -cvf "${tmpFile}" --exclude=".DS_Store" "${@}" || return 1; size=$( @@ -51,7 +51,7 @@ function fs() { else local arg=-sh; fi - if [[ -n "$@" ]]; then + if [[ -n "$*" ]]; then du $arg -- "$@"; else du $arg .[^.]* ./*; @@ -59,8 +59,7 @@ function fs() { } # Use Git’s colored diff when available -hash git &>/dev/null; -if [ $? -eq 0 ]; then +if hash git &>/dev/null; then function diff() { git diff --no-index --color-words "$@"; } @@ -68,7 +67,8 @@ fi; # Create a data URL from a file function dataurl() { - local mimeType=$(file -b --mime-type "$1"); + local mimeType; + mimeType=$(file -b --mime-type "$1"); if [[ $mimeType == text/* ]]; then mimeType="${mimeType};charset=utf-8"; fi @@ -86,9 +86,10 @@ function server() { # Compare original and gzipped file size function gz() { - local origsize=$(wc -c < "$1"); - local gzipsize=$(gzip -c "$1" | wc -c); - local ratio=$(echo "$gzipsize * 100 / $origsize" | bc -l); + local origsize, gzipsize, ratio; + origsize=$(wc -c < "$1"); + gzipsize=$(gzip -c "$1" | wc -c); + ratio=$(echo "$gzipsize * 100 / $origsize" | bc -l); printf "orig: %d bytes\n" "$origsize"; printf "gzip: %d bytes (%2.2f%%)\n" "$gzipsize" "$ratio"; } @@ -106,15 +107,17 @@ function getcertnames() { return 1; fi; - local domain="${1}"; + local domain, tmp, certText; + + domain="${1}"; echo "Testing ${domain}…"; echo ""; # newline - local tmp=$(echo -e "GET / HTTP/1.0\nEOT" \ + tmp=$(echo -e "GET / HTTP/1.0\nEOT" \ | openssl s_client -connect "${domain}:443" -servername "${domain}" 2>&1); if [[ "${tmp}" = *"-----BEGIN CERTIFICATE-----"* ]]; then - local certText=$(echo "${tmp}" \ + certText=$(echo "${tmp}" \ | openssl x509 -text -certopt "no_aux, no_header, no_issuer, no_pubkey, \ no_serial, no_sigdump, no_signame, no_validity, no_version"); echo "Common Name:"; @@ -134,7 +137,7 @@ function getcertnames() { # Normalize `open` across Linux, macOS, and Windows. # This is needed to make the `o` function (see below) cross-platform. -if [ ! $(uname -s) = 'Darwin' ]; then +if [ ! "$(uname -s)" = 'Darwin' ]; then if grep -q Microsoft /proc/version; then # Ubuntu on Windows using the Linux subsystem alias open='explorer.exe';