From c04c77b7e4903ffdb1440e0f80cb8470280046fa Mon Sep 17 00:00:00 2001 From: QuentinBisson Date: Tue, 16 Apr 2024 13:14:48 +0200 Subject: [PATCH] Remove shellcheck and remove values.schema.json Signed-off-by: QuentinBisson --- .editorconfig | 2 +- .github/workflows/pre-commit.yaml | 30 ++++++ .pre-commit-config.yaml | 4 - helm/dashboards/values.schema.json | 102 +++++++++--------- scripts/get-dashboard.sh | 6 +- scripts/get-dashboards.sh | 4 +- scripts/make-dashboards.sh | 8 +- scripts/sync-kube-mixin.sh | 2 +- scripts/update-dashboard.sh | 6 +- scripts/update-dashboards.sh | 6 +- scripts/update-monitoring-mixin-dashboards.sh | 2 +- scripts/upload-dashboard.sh | 4 +- scripts/upload-dashboards.sh | 10 +- 13 files changed, 106 insertions(+), 80 deletions(-) create mode 100644 .github/workflows/pre-commit.yaml diff --git a/.editorconfig b/.editorconfig index 0a143b75..c7855b31 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,7 +3,7 @@ # top-most EditorConfig file root = true -[helm/dashboards/**/*.json] +[helm/dashboards/{charts, dashboards}/**/*.json] indent_style = space indent_size = 2 end_of_line = lf diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml new file mode 100644 index 00000000..cb31482e --- /dev/null +++ b/.github/workflows/pre-commit.yaml @@ -0,0 +1,30 @@ +name: pre-commit + +on: + pull_request: + branches: + - main + paths: + - 'helm/dashboards/**' # helm chart directory + +jobs: + upgrade: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + - name: Cache pre-commit hooks + uses: actions/cache@v2 + with: + path: ~/.cache/pre-commit + key: ${{ runner.os }}-precommit-${{ hashFiles('.pre-commit-config.yaml') }} + - name: Install pre-commit + run: pip install pre-commit + - name: Run pre-commit on changed files + run: pre-commit run --show-diff-on-failure --color=always --all-files diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 34d2589f..8ea7e1da 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,8 +1,4 @@ repos: -- repo: https://github.com/shellcheck-py/shellcheck-py - rev: v0.8.0.3 - hooks: - - id: shellcheck - repo: https://github.com/editorconfig-checker/editorconfig-checker.python rev: '2.7.3' hooks: diff --git a/helm/dashboards/values.schema.json b/helm/dashboards/values.schema.json index 015734ea..c6503901 100644 --- a/helm/dashboards/values.schema.json +++ b/helm/dashboards/values.schema.json @@ -1,59 +1,59 @@ { - "$schema": "http://json-schema.org/schema#", - "type": "object", - "properties": { - "home": { - "type": "object", - "properties": { - "urls": { - "type": "array", - "items": { + "$schema": "http://json-schema.org/schema#", + "type": "object", + "properties": { + "home": { "type": "object", "properties": { - "description": { - "type": "string" - }, - "link": { - "type": "string" - }, - "name": { - "type": "string" - }, - "provider": { - "type": "string" - } + "urls": { + "type": "array", + "items": { + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "link": { + "type": "string" + }, + "name": { + "type": "string" + }, + "provider": { + "type": "string" + } + } + } + } } - } - } - } - }, - "name": { - "type": "string" - }, - "namespace": { - "type": "string" - }, - "project": { - "type": "object", - "properties": { - "branch": { - "type": "string" }, - "commit": { - "type": "string" - } - } - }, - "provider": { - "type": "object", - "properties": { - "kind": { - "type": "string" + "name": { + "type": "string" + }, + "namespace": { + "type": "string" + }, + "project": { + "type": "object", + "properties": { + "branch": { + "type": "string" + }, + "commit": { + "type": "string" + } + } + }, + "provider": { + "type": "object", + "properties": { + "kind": { + "type": "string" + } + } + }, + "serviceType": { + "type": "string" } - } - }, - "serviceType": { - "type": "string" } - } } diff --git a/scripts/get-dashboard.sh b/scripts/get-dashboard.sh index b359f751..ede8c5c4 100755 --- a/scripts/get-dashboard.sh +++ b/scripts/get-dashboard.sh @@ -22,11 +22,11 @@ set -e OUTPUT=/dev/stdout TMP=$(mktemp --tmpdir curl.XXXXXXXXXX) -trap rm -rf "$TMP" EXIT +trap "rm -rf $TMP" EXIT -HTTP_CODE=$(curl --output "$TMP" --write '%{http_code}' --silent --show-error --header "Authorization: Bearer $GRAFANA_API_KEY" https://giantswarm.grafana.net/api/dashboards/uid/"$1") +HTTP_CODE=$(curl --output "$TMP" --write '%{http_code}' --silent --show-error --header "Authorization: Bearer $GRAFANA_API_KEY" https://giantswarm.grafana.net/api/dashboards/uid/$1) if [[ ${HTTP_CODE} -lt 200 || ${HTTP_CODE} -gt 299 ]] ; then - echo "$HTTP_CODE" + echo $HTTP_CODE cat "$TMP" exit 1 fi diff --git a/scripts/get-dashboards.sh b/scripts/get-dashboards.sh index ab09fcbf..cc1756c9 100755 --- a/scripts/get-dashboards.sh +++ b/scripts/get-dashboards.sh @@ -21,8 +21,8 @@ script_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd -P)" -"$script_path"/list-dashboards.sh "$1" | while read -r d; do +$script_path/list-dashboards.sh $1 | while read d; do uid=$(echo -n "$d" | cut -d: -f1) echo "$d" - "$script_path"/get-dashboard.sh "$uid" "$2" + $script_path/get-dashboard.sh $uid $2 done diff --git a/scripts/make-dashboards.sh b/scripts/make-dashboards.sh index 52ac3b7a..4d778f6b 100755 --- a/scripts/make-dashboards.sh +++ b/scripts/make-dashboards.sh @@ -8,8 +8,8 @@ OUTPUT_DIRECTORY="./output" echo "Cleaning output directory" rm -rf ./$OUTPUT_DIRECTORY && mkdir ./$OUTPUT_DIRECTORY -for dashboard in "$DASHBOARD_DIRECTORY"/*; do - dashboard=$(basename "$dashboard") +for dashboard in $DASHBOARD_DIRECTORY/*; do + dashboard=$(basename $dashboard) dashboard=${dashboard%.*} if [ "$dashboard" = "stdlib" ]; then @@ -19,8 +19,8 @@ for dashboard in "$DASHBOARD_DIRECTORY"/*; do echo "Making dashboard $dashboard.jsonnet" jsonnet \ - --jpath "$GOPATH"/src/github.com/grafana/grafonnet-lib/ \ - $DASHBOARD_DIRECTORY/"$dashboard".jsonnet > $OUTPUT_DIRECTORY/"$dashboard".json + --jpath $GOPATH/src/github.com/grafana/grafonnet-lib/ \ + $DASHBOARD_DIRECTORY/$dashboard.jsonnet > $OUTPUT_DIRECTORY/$dashboard.json done echo "Made all dashboards" diff --git a/scripts/sync-kube-mixin.sh b/scripts/sync-kube-mixin.sh index 517d4e23..1073c8ee 100755 --- a/scripts/sync-kube-mixin.sh +++ b/scripts/sync-kube-mixin.sh @@ -34,7 +34,7 @@ function tune_dashboard { # make a temporary dir to work in TMPDIR=$(mktemp -d -t 'tmp.XXXXXXXXXX') -trap rm -f "$TMPDIR" EXIT +trap 'rm -f $TMPDIR' EXIT MIXIN_REPO="git@github.com:giantswarm/giantswarm-kubernetes-mixin.git" # clone a branch of tag if provided BRANCH=${1:-""} diff --git a/scripts/update-dashboard.sh b/scripts/update-dashboard.sh index aa082f0b..3009fd3e 100755 --- a/scripts/update-dashboard.sh +++ b/scripts/update-dashboard.sh @@ -13,10 +13,10 @@ set -e OUTPUT=$(mktemp --tmpdir curl.XXXXXXXXXX) INPUT=$(mktemp --tmpdir dashboard.XXXXXXXXXX) -trap rm -rf "$INPUT" "$OUTPUT" EXIT +trap "rm -rf $INPUT $OUTPUT" EXIT -jq '.message="update by giantswarm/dashboards"' "$1" > "$INPUT" -HTTP_CODE=$(curl --output "$OUTPUT" --write '%{http_code}' --silent --show-error --request POST --data @"$INPUT" --header "Content-Type: application/json" --header "Authorization: Bearer $GRAFANA_API_KEY" https://giantswarm.grafana.net/api/dashboards/db) +jq '.message="update by giantswarm/dashboards"' $1 > $INPUT +HTTP_CODE=$(curl --output "$OUTPUT" --write '%{http_code}' --silent --show-error --request POST --data @$INPUT --header "Content-Type: application/json" --header "Authorization: Bearer $GRAFANA_API_KEY" https://giantswarm.grafana.net/api/dashboards/db) if [[ ${HTTP_CODE} -lt 200 || ${HTTP_CODE} -gt 299 ]] ; then echo -n "HTTP $HTTP_CODE " cat "$OUTPUT" diff --git a/scripts/update-dashboards.sh b/scripts/update-dashboards.sh index dde01df3..a1e3621b 100755 --- a/scripts/update-dashboards.sh +++ b/scripts/update-dashboards.sh @@ -10,8 +10,8 @@ script_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd -P)" -find "$1" | while read -r f; do - d=$(jq -r '.dashboard.uid + ":" + .dashboard.title' "$1/$f") +ls $1 | while read f; do + d=$(cat "$1/$f" |jq -r '.dashboard.uid + ":" + .dashboard.title') echo "$d" - "$script_path"/update-dashboard.sh "$1/$f" + $script_path/update-dashboard.sh "$1/$f" done diff --git a/scripts/update-monitoring-mixin-dashboards.sh b/scripts/update-monitoring-mixin-dashboards.sh index 504fd38e..8f4b8012 100755 --- a/scripts/update-monitoring-mixin-dashboards.sh +++ b/scripts/update-monitoring-mixin-dashboards.sh @@ -12,7 +12,7 @@ set -e TMPDIR="$(mktemp -d)" -trap rm -rf "$TMPDIR" EXIT +trap "rm -rf $TMPDIR" EXIT main() { diff --git a/scripts/upload-dashboard.sh b/scripts/upload-dashboard.sh index 7db0d6ea..bbd609da 100755 --- a/scripts/upload-dashboard.sh +++ b/scripts/upload-dashboard.sh @@ -6,13 +6,13 @@ GRAFANA_URL="https://giantswarm.grafana.net" FOLDER_ID="31" # Playground folder OUTPUT_DIRECTORY="./output" -if [ -z "$GRAFANA_API_KEY" ]; then +if [ -z $GRAFANA_API_KEY ]; then echo "Grafana API key not set" exit 1 fi filename=$1 -dashboard_data=$(cat "$OUTPUT_DIRECTORY"/"$filename") +dashboard_data=`cat $OUTPUT_DIRECTORY/$filename` curl \ --header "Authorization: Bearer $GRAFANA_API_KEY" \ diff --git a/scripts/upload-dashboards.sh b/scripts/upload-dashboards.sh index b6a647db..0e7d1983 100755 --- a/scripts/upload-dashboards.sh +++ b/scripts/upload-dashboards.sh @@ -6,7 +6,7 @@ GRAFANA_URL="https://giantswarm.grafana.net" FOLDER_ID="40" # Official folder OUTPUT_DIRECTORY="./output" -if [ -z "$GRAFANA_API_KEY" ]; then +if [ -z $GRAFANA_API_KEY ]; then echo "Grafana API key not set" exit 1 fi @@ -22,17 +22,17 @@ for uid in $uids; do curl \ --header "Authorization: Bearer $GRAFANA_API_KEY" \ --request "DELETE" \ - $GRAFANA_URL/api/dashboards/uid/"$uid" + $GRAFANA_URL/api/dashboards/uid/$uid echo done echo "Uploading all dashboards" -for dashboard in "$OUTPUT_DIRECTORY"/*; do - dashboard=$(basename "$dashboard") +for dashboard in $OUTPUT_DIRECTORY/*; do + dashboard=$(basename $dashboard) dashboard=${dashboard%.*} - dashboard_data=$(cat "$OUTPUT_DIRECTORY"/"$dashboard".json) + dashboard_data=`cat $OUTPUT_DIRECTORY/$dashboard.json` curl \ --header "Authorization: Bearer $GRAFANA_API_KEY" \