From 93aae762a698077bde48ba7f76a9a82fe1e0be5f Mon Sep 17 00:00:00 2001 From: Gabriel Kerneis Date: Thu, 18 Nov 2021 16:04:13 +0100 Subject: [PATCH] Offer to run tests before pushing in contrib/setup Also make clearer that the default choice is "no" for interactive prompts. --- .github/workflows/main.yml | 2 +- .pre-commit-config.yaml | 6 ++++++ contrib/run-tests.sh | 2 ++ contrib/setup | 31 +++++++++++++++++++++---------- 4 files changed, 30 insertions(+), 11 deletions(-) create mode 100755 contrib/run-tests.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8bc47cef4..f1d22dff0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,7 +21,7 @@ jobs: ./contrib/setup source venv/bin/activate sed -i "/no-commit-to-branch/,+1d" .pre-commit-config.yaml - pre-commit run --all-files + pre-commit run --hook-stage commit --all-files abi: runs-on: ubuntu-20.04 steps: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5d6f57cfa..a21e7150e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,4 @@ +default_stages: [commit] repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.0.1 @@ -53,6 +54,11 @@ repos: language: system entry: shellcheck --severity=warning -e SC2068 types: [shell] + - id: run-tests + name: run tests before pushing + language: script + entry: ./contrib/run-tests.sh + stages: [push] - id: clang-format name: clang-format language: script diff --git a/contrib/run-tests.sh b/contrib/run-tests.sh new file mode 100755 index 000000000..9a2209223 --- /dev/null +++ b/contrib/run-tests.sh @@ -0,0 +1,2 @@ +#!/bin/sh +meson build && ninja -C build test diff --git a/contrib/setup b/contrib/setup index 65a67f725..9c6d6ccbc 100755 --- a/contrib/setup +++ b/contrib/setup @@ -12,7 +12,7 @@ rename_branch() NEW=main if git log $OLD >/dev/null 2>&1 && git remote get-url origin 2>&1 | grep fwupd/fwupd.git >/dev/null 2>&1; then - read -p "Rename existing $OLD branch to $NEW? (y/n) " question + read -p "Rename existing $OLD branch to $NEW? (y/N) " question if [ "$question" = "y" ]; then git branch -m $OLD $NEW git fetch origin @@ -24,7 +24,7 @@ rename_branch() setup_deps() { - read -p "Install build dependencies? (y/n) " question + read -p "Install build dependencies? (y/N) " question if [ "$question" = "y" ]; then $(which sudo) python3 $HELPER install-dependencies $HELPER_ARGS -y fi @@ -32,7 +32,7 @@ setup_deps() setup_run_dev() { - read -p "Set up dbus activated daemon and PolicyKit actions from /usr/local? (y/n) " question + read -p "Set up dbus activated daemon and PolicyKit actions from /usr/local? (y/N) " question if [ "$question" = "y" ]; then ./contrib/prepare-system /usr/local install fi @@ -40,7 +40,7 @@ setup_run_dev() setup_unsafe_polkit_rules() { - read -p "Install developer-friendly **unsafe** PolicyKit rules into /etc/polkit-1/rules.d? (y/n) " question + read -p "Install developer-friendly **unsafe** PolicyKit rules into /etc/polkit-1/rules.d? (y/N) " question if [ "$question" = "y" ]; then sudo cp ./policy/org.freedesktop.fwupd-unsafe.rules /etc/polkit-1/rules.d/ fi @@ -85,6 +85,16 @@ setup_precommit() pre-commit install } +setup_prepush() +{ + read -p "Run tests locally before pushing to remote branches? THIS WILL SLOW DOWN EVERY PUSH but reduce the risk of failing CI. (y/N) " question + if [ "$question" = "y" ]; then + pre-commit install -t pre-push + else + pre-commit uninstall -t pre-push + fi +} + check_markdown() { if ! python3 $HELPER test-markdown; then @@ -128,6 +138,12 @@ detect_os() #needed for arguments for some commands detect_os "$@" +#always setup pre-commit +setup_precommit + +#always setup git environment +setup_git + #if interactive install build deps and prepare environment if [ -t 2 ]; then case $OS in @@ -143,10 +159,5 @@ if [ -t 2 ]; then check_markdown setup_vscode rename_branch + setup_prepush fi - -#always setup pre-commit -setup_precommit - -#always setup git environment -setup_git