2023-10-08 15:51:06 +00:00
name : Code Quality
# spell-checker:ignore TERMUX reactivecircus Swatinem noaudio pkill swiftshader dtolnay juliangruber
2023-12-01 10:52:23 +00:00
on :
pull_request :
push :
branches :
- main
2023-10-08 15:51:06 +00:00
2023-10-13 06:13:10 +00:00
env :
# * style job configuration
STYLE_FAIL_ON_FAULT : true ## (bool) fail the build if a style job contains a fault (error or warning); may be overridden on a per-job basis
2023-10-08 15:51:06 +00:00
permissions :
contents : read # to fetch code (actions/checkout)
# End the current execution if there is a new changeset in the PR.
concurrency :
group : ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress : ${{ github.ref != 'refs/heads/main' }}
jobs :
style_format :
name : Style/format
runs-on : ${{ matrix.job.os }}
strategy :
fail-fast : false
matrix :
job :
- { os: ubuntu-latest , features : feat_os_unix }
steps :
- uses : actions/checkout@v4
- uses : dtolnay/rust-toolchain@master
with :
toolchain : stable
components : rustfmt
- uses : Swatinem/rust-cache@v2
- name : Initialize workflow variables
id : vars
shell : bash
run : |
## VARs setup
outputs() { step_id="${{ github.action }}"; for var in "$@" ; do echo steps.${step_id}.outputs.${var}="${!var}"; echo "${var}=${!var}" >> $GITHUB_OUTPUT; done; }
# failure mode
unset FAIL_ON_FAULT ; case '${{ env.STYLE_FAIL_ON_FAULT }}' in
'' |0|f|false|n|no|off) FAULT_TYPE=warning ;;
*) FAIL_ON_FAULT=true ; FAULT_TYPE=error ;;
esac;
outputs FAIL_ON_FAULT FAULT_TYPE
- name : "`cargo fmt` testing"
shell : bash
run : |
## `cargo fmt` testing
unset fault
fault_type="${{ steps.vars.outputs.FAULT_TYPE }}"
fault_prefix=$(echo "$fault_type" | tr '[:lower:]' '[:upper:]')
# * convert any errors/warnings to GHA UI annotations; ref: <https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message>
S=$(cargo fmt -- --check) && printf "%s\n" "$S" || { printf "%s\n" "$S" ; printf "%s\n" "$S" | sed -E -n -e "s/^Diff[[:space:]]+in[[:space:]]+${PWD//\//\\/}\/(.*)[[:space:]]+at[[:space:]]+[^0-9]+([0-9]+).*$/::${fault_type} file=\1,line=\2::${fault_prefix}: \`cargo fmt\`: style violation (file:'\1', line:\2; use \`cargo fmt -- \"\1\"\`)/p" ; fault=true ; }
if [ -n "${{ steps.vars.outputs.FAIL_ON_FAULT }}" ] && [ -n "$fault" ]; then exit 1 ; fi
style_lint :
name : Style/lint
runs-on : ${{ matrix.job.os }}
env :
SCCACHE_GHA_ENABLED : "true"
RUSTC_WRAPPER : "sccache"
strategy :
fail-fast : false
matrix :
job :
- { os: ubuntu-latest , features : feat_os_unix }
- { os: macos-latest , features : feat_os_macos }
- { os: windows-latest , features : feat_os_windows }
steps :
- uses : actions/checkout@v4
- uses : dtolnay/rust-toolchain@master
with :
toolchain : stable
components : clippy
- uses : Swatinem/rust-cache@v2
- name : Run sccache-cache
2024-09-27 10:35:36 +00:00
uses : mozilla-actions/sccache-action@v0.0.6
2023-10-08 15:51:06 +00:00
- name : Initialize workflow variables
id : vars
shell : bash
run : |
## VARs setup
outputs() { step_id="${{ github.action }}"; for var in "$@" ; do echo steps.${step_id}.outputs.${var}="${!var}"; echo "${var}=${!var}" >> $GITHUB_OUTPUT; done; }
# failure mode
unset FAIL_ON_FAULT ; case '${{ env.STYLE_FAIL_ON_FAULT }}' in
'' |0|f|false|n|no|off) FAULT_TYPE=warning ;;
*) FAIL_ON_FAULT=true ; FAULT_TYPE=error ;;
esac;
outputs FAIL_ON_FAULT FAULT_TYPE
- name : "`cargo clippy` lint testing"
2024-03-31 23:41:43 +00:00
uses : nick-fields/retry@v3
2024-03-31 15:41:22 +00:00
with :
max_attempts : 3
retry_on : error
timeout_minutes : 90
shell : bash
command : |
## `cargo clippy` lint testing
unset fault
2024-04-02 21:30:28 +00:00
CLIPPY_FLAGS="-W clippy::default_trait_access -W clippy::manual_string_new -W clippy::cognitive_complexity -W clippy::implicit_clone -W clippy::range-plus-one -W clippy::redundant-clone -W clippy::match_bool"
2024-03-31 15:41:22 +00:00
fault_type="${{ steps.vars.outputs.FAULT_TYPE }}"
fault_prefix=$(echo "$fault_type" | tr '[:lower:]' '[:upper:]')
# * convert any warnings to GHA UI annotations; ref: <https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message>
2024-04-17 05:42:14 +00:00
S=$(cargo clippy --all-targets --features ${{ matrix.job.features }} -pcoreutils -- ${CLIPPY_FLAGS} -D warnings 2>&1) && printf "%s\n" "$S" || { printf "%s\n" "$S" ; printf "%s" "$S" | sed -E -n -e '/^error:/{' -e "N; s/^error:[[:space:]]+(.*)\\n[[:space:]]+-->[[:space:]]+(.*):([0-9]+):([0-9]+).*$/::${fault_type} file=\2,line=\3,col=\4::${fault_prefix}: \`cargo clippy\`: \1 (file:'\2', line:\3)/p;" -e '}' ; fault=true ; }
2024-03-31 15:41:22 +00:00
if [ -n "${{ steps.vars.outputs.FAIL_ON_FAULT }}" ] && [ -n "$fault" ]; then exit 1 ; fi
2023-10-08 15:51:06 +00:00
style_spellcheck :
name : Style/spelling
runs-on : ${{ matrix.job.os }}
strategy :
matrix :
job :
- { os: ubuntu-latest , features : feat_os_unix }
steps :
- uses : actions/checkout@v4
- name : Initialize workflow variables
id : vars
shell : bash
run : |
## VARs setup
outputs() { step_id="${{ github.action }}"; for var in "$@" ; do echo steps.${step_id}.outputs.${var}="${!var}"; echo "${var}=${!var}" >> $GITHUB_OUTPUT; done; }
# failure mode
unset FAIL_ON_FAULT ; case '${{ env.STYLE_FAIL_ON_FAULT }}' in
'' |0|f|false|n|no|off) FAULT_TYPE=warning ;;
*) FAIL_ON_FAULT=true ; FAULT_TYPE=error ;;
esac;
outputs FAIL_ON_FAULT FAULT_TYPE
- name : Install/setup prerequisites
shell : bash
run : |
2024-02-04 15:43:41 +00:00
sudo apt-get -y update ; sudo apt-get -y install npm ; sudo npm install cspell -g ;
2023-10-08 15:51:06 +00:00
- name : Run `cspell`
shell : bash
run : |
## Run `cspell`
unset fault
fault_type="${{ steps.vars.outputs.FAULT_TYPE }}"
fault_prefix=$(echo "$fault_type" | tr '[:lower:]' '[:upper:]')
# * find cspell configuration ; note: avoid quotes around ${cfg_file} b/c `cspell` (v4) doesn't correctly dequote the config argument (or perhaps a subshell expansion issue?)
cfg_files=($(shopt -s nullglob ; echo {.vscode,.}/{,.}c[sS]pell{.json,.config{.js,.cjs,.json,.yaml,.yml},.yaml,.yml} ;))
cfg_file=${cfg_files[0]}
unset CSPELL_CFG_OPTION ; if [ -n "$cfg_file" ]; then CSPELL_CFG_OPTION="--config $cfg_file" ; fi
2024-02-04 15:43:41 +00:00
S=$(cspell ${CSPELL_CFG_OPTION} --no-summary --no-progress "**/*") && printf "%s\n" "$S" || { printf "%s\n" "$S" ; printf "%s" "$S" | sed -E -n "s/${PWD//\//\\/}\/(.*):(.*):(.*) - (.*)/::${fault_type} file=\1,line=\2,col=\3::${fault_type^^}: \4 (file:'\1', line:\2)/p" ; fault=true ; true ; }
2023-10-08 15:51:06 +00:00
if [ -n "${{ steps.vars.outputs.FAIL_ON_FAULT }}" ] && [ -n "$fault" ]; then exit 1 ; fi
toml_format :
2023-10-08 15:54:36 +00:00
name : Style/toml
2023-10-08 15:51:06 +00:00
runs-on : ubuntu-latest
steps :
- name : Clone repository
uses : actions/checkout@v4
- name : Check
run : npx --yes @taplo/cli fmt --check