diff --git a/.circleci/config.yml b/.circleci/config.yml index 19a63c458..8e8b43069 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -41,12 +41,16 @@ jobs: docker: - image: koalaman/shellcheck-alpine:v0.9.0 steps: + - checkout - run: name: Install dependencies - command: apk add bash git openssh-client grep - - checkout + command: | + apk add bash git openssh-client grep + git clone --depth 1 --branch v1.10.0 https://github.com/bats-core/bats-core.git + cd bats-core + ./install.sh /usr/local - run: - name: Run static analysis on bash scripts + name: Run tests and static analysis on bash scripts command: ./dev-scripts/check-bash check_privilege_guard: executor: ubuntu @@ -55,7 +59,7 @@ jobs: - run: name: Check for unnecessary privilege escalation command: ./dev-scripts/check-privilege-guard - lint_sql: + check_sql: executor: python steps: - checkout @@ -67,7 +71,7 @@ jobs: command: | . venv/bin/activate pip install --requirement dev_requirements.txt - ./dev-scripts/lint-sql + ./dev-scripts/check-sql check_style: executor: node steps: @@ -95,7 +99,7 @@ jobs: . venv/bin/activate pip install --requirement requirements.txt ./dev-scripts/decode-edid - build_python: + check_python: executor: python steps: - checkout @@ -107,8 +111,8 @@ jobs: command: | . venv/bin/activate pip install --requirement dev_requirements.txt - ./dev-scripts/build-python - build_javascript: + ./dev-scripts/check-python + check_javascript: executor: node steps: - checkout @@ -117,25 +121,12 @@ jobs: command: npm install - run: name: Run build script - command: ./dev-scripts/build-javascript - build_bash: - executor: ubuntu - steps: - - checkout - - run: - name: Install dependencies - command: | - git clone --depth 1 --branch v1.10.0 https://github.com/bats-core/bats-core.git - cd bats-core - sudo ./install.sh /usr/local - - run: - name: Run build script - command: ./dev-scripts/build-bash - e2e: + command: ./dev-scripts/check-javascript + run_e2e_tests: docker: # To run tests against the dev server, Playwright needs a CircleCI image - # with Python, Node, and a browser. While the build_python and - # build_javascript steps use python-3.9.17 and node-18.16.1 respectively, + # with Python, Node, and a browser. While the check_python and + # check_javascript steps use python-3.9.17 and node-18.16.1 respectively, # the CircleCI image with *both* python and node in the closest versions # is python:3.9.17-browsers. It has python-3.9.17 and node-18.16.0. # @@ -186,7 +177,7 @@ jobs: root: ./debian-pkg/releases paths: - "*.deb" - lint_debian_package: + check_debian_package: executor: ubuntu steps: - checkout @@ -288,15 +279,14 @@ workflows: - check_whitespace - check_bash - check_privilege_guard - - lint_sql + - check_sql - check_style - decode_edid - - build_python - - build_javascript - - build_bash + - check_python + - check_javascript + - run_e2e_tests - build_debian_package - - e2e - - lint_debian_package: + - check_debian_package: requires: - build_debian_package - build_bundle: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 65e2237b5..0e7015975 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -32,7 +32,7 @@ python3 -m venv venv && \ To run TinyPilot's build scripts, run: ```bash -./dev-scripts/build +./dev-scripts/check-all ``` ### Run end-to-end tests diff --git a/dev-scripts/build-bash b/dev-scripts/build-bash deleted file mode 100755 index b68ddc628..000000000 --- a/dev-scripts/build-bash +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -# Exit on first failure. -set -e - -# Echo commands before executing them, by default to stderr. -set -x - -# Exit on unset variable. -set -u - -# Run bats tests. -bats \ - --recursive \ - scripts/ \ - debian-pkg/ \ - dev-scripts/ diff --git a/dev-scripts/build b/dev-scripts/check-all similarity index 64% rename from dev-scripts/build rename to dev-scripts/check-all index 1eef7316c..b450fdcf6 100755 --- a/dev-scripts/build +++ b/dev-scripts/check-all @@ -9,9 +9,12 @@ set -x # Exit on unset variable. set -u -./dev-scripts/check-trailing-whitespace -./dev-scripts/check-trailing-newline ./dev-scripts/check-bash -./dev-scripts/build-python -./dev-scripts/build-javascript +./dev-scripts/check-for-init-files +./dev-scripts/check-javascript +./dev-scripts/check-privilege-guard +./dev-scripts/check-python +./dev-scripts/check-sql ./dev-scripts/check-style +./dev-scripts/check-trailing-whitespace +./dev-scripts/check-trailing-newline diff --git a/dev-scripts/check-bash b/dev-scripts/check-bash index f6dd56a52..f26d99b01 100755 --- a/dev-scripts/check-bash +++ b/dev-scripts/check-bash @@ -1,15 +1,18 @@ #!/bin/bash -# -# Run static analysis on bash scripts. -# Exit on first failing command. +# Run tests and static analysis on bash scripts. + +# Exit on first failure. set -e +# Echo commands before executing them, by default to stderr. +set -x + # Exit on unset variable. set -u +# Run static analysis with shellcheck. BASH_SCRIPTS=() - while read -r filepath; do if head -n 1 "${filepath}" | grep --quiet \ --regexp '#!/bin/bash' \ @@ -20,7 +23,12 @@ while read -r filepath; do BASH_SCRIPTS+=("${filepath}") fi done < <(git ls-files) - readonly BASH_SCRIPTS - shellcheck "${BASH_SCRIPTS[@]}" + +# Run bats tests. +bats \ + --recursive \ + scripts/ \ + debian-pkg/ \ + dev-scripts/ diff --git a/dev-scripts/build-javascript b/dev-scripts/check-javascript similarity index 76% rename from dev-scripts/build-javascript rename to dev-scripts/check-javascript index 08e8ec57e..fd3058e13 100755 --- a/dev-scripts/build-javascript +++ b/dev-scripts/check-javascript @@ -12,7 +12,8 @@ set -u # Location of app source files. SOURCE_DIR="app" -./dev-scripts/lint-frontend +# Check for JavaScript anti-patterns. +./node_modules/.bin/eslint "./**/*.js" "./**/*.html" # Run unit tests. ./node_modules/.bin/mocha \ diff --git a/dev-scripts/build-python b/dev-scripts/check-python similarity index 100% rename from dev-scripts/build-python rename to dev-scripts/check-python diff --git a/dev-scripts/lint-sql b/dev-scripts/check-sql similarity index 100% rename from dev-scripts/lint-sql rename to dev-scripts/check-sql diff --git a/dev-scripts/git-hooks/pre-commit b/dev-scripts/git-hooks/pre-commit index 9a9eb7c6a..ce1053b3d 100755 --- a/dev-scripts/git-hooks/pre-commit +++ b/dev-scripts/git-hooks/pre-commit @@ -9,4 +9,4 @@ set -x # Exit on unset variable. set -u -./dev-scripts/build +./dev-scripts/check-all diff --git a/dev-scripts/lint-frontend b/dev-scripts/lint-frontend deleted file mode 100755 index 4d958c24c..000000000 --- a/dev-scripts/lint-frontend +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -# Checks for JavaScript anti-patterns. - -# Exit on first failure. -set -e - -# Echo commands before executing them, by default to stderr. -set -x - -# Exit on unset variable. -set -u - -./node_modules/.bin/eslint "./**/*.js" "./**/*.html"