From f8003fd108b58e2d9771c7b78d62ad34ed533d95 Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Mon, 8 May 2023 13:12:04 -0700 Subject: [PATCH] ci: Use new reusable workflows --- .editorconfig | 13 ++ .github/workflows/lint.yml | 16 +++ .github/workflows/site.yml | 53 -------- .github/workflows/test.yml | 150 ++------------------- .github/workflows/website.yml | 16 +++ .hooks/.hookah/lib.sh | 246 ---------------------------------- .hooks/pre-commit | 8 -- .lefthook.yaml | 6 + .shellcheckrc | 2 + Bakefile.sh | 4 + 10 files changed, 65 insertions(+), 449 deletions(-) create mode 100644 .editorconfig create mode 100644 .github/workflows/lint.yml delete mode 100644 .github/workflows/site.yml create mode 100644 .github/workflows/website.yml delete mode 100644 .hooks/.hookah/lib.sh delete mode 100755 .hooks/pre-commit create mode 100644 .lefthook.yaml create mode 100644 .shellcheckrc diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..a865ae0 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +root = true + +[*] +indent_style = tab +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.{yaml,yml,md}] +indent_style = space +indent_size = 2 +quote_type = single diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..45e822a --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,16 @@ +name: 'Lint' + +on: + push: + branches-ignore: ['*-no-ci'] + tags-ignore: ['*'] + +permissions: + contents: 'read' + pages: 'write' + id-token: 'write' + +jobs: + bash: + name: 'Bash' + uses: 'fox-land/hyperupcall-action/.github/workflows/bash-lint.yml@main' diff --git a/.github/workflows/site.yml b/.github/workflows/site.yml deleted file mode 100644 index dea9fb7..0000000 --- a/.github/workflows/site.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: 'Build and Deploy Site' -on: - push: - branches-ignore: ['*-no-ci'] - pull_request: - branches-ignore: ['*-no-ci'] - -permissions: - contents: 'read' - pages: 'write' - id-token: 'write' - -defaults: - run: - shell: 'bash' - - # TODO - # concurrency: - # group: '${{ github.ref }}' - # cancel-in-progress: true - -jobs: - build: - runs-on: 'ubuntu-latest' - steps: - - uses: 'actions/checkout@v3' - - run: | - cat > mkdocs.yml </dev/null 2>&1; then - DEBIAN_FRONTEND=noninteractive apt-get update -y - DEBIAN_FRONTEND=noninteractive apt-get install -y curl git - elif command -v dnf >/dev/null 2>&1; then - dnf update -y - dnf install -y curl git - elif command -v zypper >/dev/null 2>&1; then - zypper update -y - zypper install -y tar curl git bash - elif command -v pacman >/dev/null 2>&1; then - pacman -Syu --noconfirm curl git - fi - - name: 'Install Basalt' - run: | - git clone https://github.com/hyperupcall/basalt "${XDG_DATA_HOME:-$HOME/.local/share}/basalt/source" - PATH="${XDG_DATA_HOME:-$HOME/.local/share}/basalt/source/pkg/bin:$PATH" - - mkdir -p /basalt - printf '%s\n' "${{ github.token }}" > /basalt/token - - eval "$(basalt global init bash)" - ( - cd "${XDG_DATA_HOME:-$HOME/.local/share}/basalt/source" - basalt install - ) - - printf '%s\n' "${XDG_DATA_HOME:-$HOME/.local/share}/basalt/source/pkg/bin" >> "$GITHUB_PATH" - - name: 'Install Bats' - run: | - subdir="$HOME/.tools" - bats_version='1.4.1' - - mkdir -p "$subdir" - curl -LsSo "$subdir/bats-core.tar.gz" --create-dirs \ - https://github.com/bats-core/bats-core/archive/v$bats_version.tar.gz - tar --extract --transform "s,bats-core-$bats_version,bats-core," -C "$subdir" -f "$subdir/bats-core.tar.gz" - ls -al "$subdir/bats-core/bin" - echo i am pwd: "$PWD" - printf '%s\n' "$subdir/bats-core/bin" >> "$GITHUB_PATH" - - uses: 'actions/checkout@v3' - - name: 'Run Test' - run: | - git config --global user.email "user@example.com" - git config --global user.name "User Name" - - bash --version - eval "$(basalt global init bash)" - basalt install - sleep 10 - touch .basalt/generated/done.sh - time bats --tap tests - # test-bats: - # name: 'Test Bash versions' - # runs-on: 'ubuntu-latest' - # strategy: - # fail-fast: false - # matrix: - # bash-version: ['4.3', '4.4', '5.0', '5.1', 'latest'] - # steps: - # - run: echo 'thing' - -# test-mac: -# name: 'MacOS Test' -# strategy: -# fail-fast: false -# matrix: -# os: ['macos-latest'] -# runs-on: '${{ matrix.os }}' - -# steps: -# - uses: 'actions/checkout@v2' -# with: -# submodules: true -# path: 'source' - -# - name: Install Prerequisites -# run: | -# # gnu-tar is only for the 'Install Bats' step -# brew install bash coreutils curl gnu-tar - -# - name: Install Bats -# run: | -# subdir='.workflow-data' -# bats_version='1.4.1' - -# cd source - -# curl -LsSo "$subdir/bats-core.tar.gz" --create-dirs \ -# https://github.com/bats-core/bats-core/archive/v$bats_version.tar.gz -# gtar --extract --transform "s,bats-core-$bats_version,bats-core," -C "$subdir" -f "$subdir/bats-core.tar.gz" - -# - name: Run tests -# run: | -# subdir='.workflow-data' - -# cd source - -# bash --version -# git config --global user.email "user@example.com" -# git config --global user.name "User Name" -# printf "%s\n" "---" - -# time "./$subdir/bats-core/bin/bats" --tap tests + bash: + name: 'Bash' + uses: 'fox-land/hyperupcall-action/.github/workflows/bash-test.yml@main' diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml new file mode 100644 index 0000000..d189b24 --- /dev/null +++ b/.github/workflows/website.yml @@ -0,0 +1,16 @@ +name: 'Website' + +on: + push: + branches-ignore: ['*-no-ci'] + tags-ignore: ['*'] + +permissions: + contents: 'read' + pages: 'write' + id-token: 'write' + +jobs: + build-and-deploy: + name: 'Build And Deploy' + uses: 'fox-land/hyperupcall-action/.github/workflows/website.yml@main' diff --git a/.hooks/.hookah/lib.sh b/.hooks/.hookah/lib.sh deleted file mode 100644 index 9ed074b..0000000 --- a/.hooks/.hookah/lib.sh +++ /dev/null @@ -1,246 +0,0 @@ -# shellcheck shell=bash -# Version: 0.1.2 - -# @name Hookah lib.sh -# @brief Hookah: An elegantly minimal solution for Git hooks -# @description Hookah streamlines the process of managing Git hooks. This file is a -# library of functions that can easily be used by hooks written in Bash. Use it by -# prepending your hook script with the following -# -# ```bash -# #!/usr/bin/env bash -# -# source "${0%/*}/.hookah/lib.sh" -# hookah.init -# ``` -# -# Learn more about it [on GitHub](https://github.com/hyperupcall/hookah) - -if [ -z "$BASH_VERSION" ]; then - printf '%s\n' "Error: lib.sh: This script is only compatible with Bash. Exiting" >&2 - exit 1 -fi - -# @description Initiates the environment, sets up stacktrace printing on the 'ERR' trap, -# and sets the directory to the root of the Git repository -# @noargs -hookah.init() { - set -Eeo pipefail - shopt -s dotglob extglob globasciiranges globstar lastpipe shift_verbose - export LANG='C' LC_CTYPE='C' LC_NUMERIC='C' LC_TIME='C' LC_COLLATE='C' \ - LC_MONETARY='C' LC_MESSAGES='C' LC_PAPER='C' LC_NAME='C' LC_ADDRESS='C' \ - LC_TELEPHONE='C' LC_MEASUREMENT='C' LC_IDENTIFICATION='C' LC_ALL='C' - trap '__hookah_trap_err' 'ERR' - - while [ ! -d '.git' ] && [ "$PWD" != / ]; do - if ! cd ..; then - __hookah_internal_die "Failed to cd to nearest Git repository" - fi - done - if [ "$PWD" = / ]; then - __hookah_internal_die "Failed to cd to nearest Git repository" - fi - - # Prevent any possibilities of 'stdin in is not a tty' - if ! exec &2 - -# @internal -__hookah_internal_warn() { - local str="${2:-"Hookah (internal)"}" - - if __hookah_is_color; then - printf "\033[1;33m\033[1m$str \033[1m[warn]:\033[0m %s\n" "$1" - else - printf "$str [warn]: %s\n" "$1" - fi -} >&2 - -# @internal -__hookah_internal_info() { - local str="${2:-"Hookah (internal)"}" - - if __hookah_is_color; then - printf "\033[0;36m\033[1m$str \033[1m[info]:\033[0m %s\n" "$1" - else - printf "$str [info]: %s\n" "$1" - fi -} - -# @internal -__hookah_trap_err() { - local error_code=$? - - __hookah_internal_error "Your hook did not exit successfully (exit code $error_code)" - - exit $error_code -} diff --git a/.hooks/pre-commit b/.hooks/pre-commit deleted file mode 100755 index f86578d..0000000 --- a/.hooks/pre-commit +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -source "${0%/*}/.hookah/lib.sh" -hookah.init - -hookah.run ./bake test -hookah.run ./bake docs -git add ./docs/* \ No newline at end of file diff --git a/.lefthook.yaml b/.lefthook.yaml new file mode 100644 index 0000000..66806be --- /dev/null +++ b/.lefthook.yaml @@ -0,0 +1,6 @@ +pre-commit: + commands: + test: + run: './bake test' + lint: + run: './bake lint' diff --git a/.shellcheckrc b/.shellcheckrc new file mode 100644 index 0000000..f7e1745 --- /dev/null +++ b/.shellcheckrc @@ -0,0 +1,2 @@ +disable=SC2164 +disable=SC1091 diff --git a/Bakefile.sh b/Bakefile.sh index f1d9224..728ff8e 100644 --- a/Bakefile.sh +++ b/Bakefile.sh @@ -8,6 +8,10 @@ task.test() { bats tests } +task.lint() { + shellcheck ./pkg/**/*.sh +} + task.docs() { shdoc < './pkg/src/public/bash-core.sh' > './docs/api.md' }