From dc396b6301f482fbe6dd4390c1a97ab5c960acd3 Mon Sep 17 00:00:00 2001 From: Maxime Desroches Date: Wed, 14 Aug 2024 11:34:52 -0700 Subject: [PATCH] lint.sh: better shebang lint (#33296) -e old-commit-hash: 585f362738908bb4c98e87fac0cd7cb64a78d6b4 --- scripts/git_rewrite/rewrite-git-history.sh | 15 ++++++++------- scripts/lint/check_shebang_format.sh | 4 ++-- selfdrive/test/ci_shell.sh | 3 ++- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/scripts/git_rewrite/rewrite-git-history.sh b/scripts/git_rewrite/rewrite-git-history.sh index 5a97e6bbad..cce4455ce5 100755 --- a/scripts/git_rewrite/rewrite-git-history.sh +++ b/scripts/git_rewrite/rewrite-git-history.sh @@ -1,4 +1,5 @@ -#!/bin/bash -e +#!/usr/bin/env bash +set -e SRC=/tmp/openpilot/ SRC_CLONE=/tmp/openpilot-clone/ @@ -209,7 +210,7 @@ if [ ! -f "$SRC_CLONE/rewrite-branches-done" ]; then MERGE_BASE=$(git merge-base master origin/$BRANCH) || true if [ -n "$MERGE_BASE" ]; then echo "Rewriting branch: $BRANCH" - + # create a new branch based on the new master NEW_MERGE_BASE=$(grep "^$MERGE_BASE " "commit-map.txt" | awk '{print $2}') if [ -z "$NEW_MERGE_BASE" ]; then @@ -217,10 +218,10 @@ if [ ! -f "$SRC_CLONE/rewrite-branches-done" ]; then continue fi git checkout -b ${BRANCH}_new $NEW_MERGE_BASE - + # get the range of commits unique to this branch COMMITS=$(git rev-list --reverse $MERGE_BASE..origin/${BRANCH}) - + HAS_ERROR=0 # simple delimiter @@ -263,7 +264,7 @@ if [ ! -f "$SRC_CLONE/rewrite-branches-done" ]; then git commit --amend -m "$(git log -1 --pretty=%B)" -m "Former-commit-id: $COMMIT" > /dev/null fi done - + # force push the new branch if [ $HAS_ERROR -eq 0 ]; then # git lfs goes haywire here, so we need to install and uninstall @@ -271,7 +272,7 @@ if [ ! -f "$SRC_CLONE/rewrite-branches-done" ]; then git lfs uninstall --local > /dev/null git push -f origin ${BRANCH}_new:${BRANCH} fi - + # clean up local branch git checkout master > /dev/null git branch -D ${BRANCH}_new > /dev/null @@ -318,7 +319,7 @@ if [ ! -f "$SRC_CLONE/validation-done" ]; then # echo -ne "[$CURRENT_COMMIT_NUMBER/$TOTAL_COMMITS] Comparing old commit $OLD_COMMIT_SHORT ($OLD_DATE) with new commit $NEW_COMMIT_SHORT ($NEW_DATE)"\\r echo "[$CURRENT_COMMIT_NUMBER/$TOTAL_COMMITS] Comparing old commit $OLD_COMMIT_SHORT ($OLD_DATE) with new commit $NEW_COMMIT_SHORT ($NEW_DATE)" - + # generate lists of files and their hashes for the old and new commits, excluding ignored files OLD_FILES=$(git ls-tree -r $OLD_COMMIT | grep -vE "$(IFS='|'; echo "${VALIDATE_IGNORE_FILES[*]}")") NEW_FILES=$(git ls-tree -r $NEW_COMMIT | grep -vE "$(IFS='|'; echo "${VALIDATE_IGNORE_FILES[*]}")") diff --git a/scripts/lint/check_shebang_format.sh b/scripts/lint/check_shebang_format.sh index 8d48602e6c..89b95d5929 100755 --- a/scripts/lint/check_shebang_format.sh +++ b/scripts/lint/check_shebang_format.sh @@ -2,12 +2,12 @@ FAIL=0 -if grep '^#!.*python$' $@ | grep -v '#!/usr/bin/env python3$'; then +if grep '^#!.*python' $@ | grep -v '#!/usr/bin/env python3$'; then echo -e "Invalid shebang! Must use '#!/usr/bin/env python3'\n" FAIL=1 fi -if grep '^#!.*bash$' $@ | grep -v '#!/usr/bin/env bash$'; then +if grep '^#!.*bash' $@ | grep -v '#!/usr/bin/env bash$'; then echo -e "Invalid shebang! Must use '#!/usr/bin/env bash'" FAIL=1 fi diff --git a/selfdrive/test/ci_shell.sh b/selfdrive/test/ci_shell.sh index a5ff714b2d..76f0a9f78c 100755 --- a/selfdrive/test/ci_shell.sh +++ b/selfdrive/test/ci_shell.sh @@ -1,4 +1,5 @@ -#!/bin/bash -e +#!/usr/bin/env bash +set -e DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)" OP_ROOT="$DIR/../../"