diff options
author | Evan Read <eread@gitlab.com> | 2022-11-24 19:15:29 +0300 |
---|---|---|
committer | Marcel Amirault <mamirault@gitlab.com> | 2022-11-24 19:15:29 +0300 |
commit | 95a5390f185351f20081097da18c6f364ce96f8a (patch) | |
tree | 3abfa607e5aadd0af15bc2a982a84aa3fe4840af | |
parent | 9c61332c3ceaa6e03aa264f7f3b394afbc5ad8e0 (diff) |
Add ShellCheck to project
-rw-r--r-- | .gitlab/ci/build-and-deploy.gitlab-ci.yml | 6 | ||||
-rw-r--r-- | .gitlab/ci/test.gitlab-ci.yml | 13 | ||||
-rw-r--r-- | .tool-versions | 1 | ||||
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | doc/testing.md | 21 | ||||
-rw-r--r-- | lefthook.yml | 2 | ||||
-rwxr-xr-x | scripts/check-lunr-index.sh | 8 | ||||
-rwxr-xr-x | scripts/compress_images.sh | 9 | ||||
-rwxr-xr-x | scripts/deploy-review-app.sh (renamed from scripts/deploy-review-app) | 4 | ||||
-rwxr-xr-x | scripts/minify-assets.sh | 16 | ||||
-rwxr-xr-x | scripts/normalize-links.sh | 48 | ||||
-rwxr-xr-x | scripts/review-replace-urls.sh (renamed from scripts/review-replace-urls) | 0 | ||||
-rwxr-xr-x | tasks/unlinked-images.sh | 2 |
13 files changed, 71 insertions, 63 deletions
diff --git a/.gitlab/ci/build-and-deploy.gitlab-ci.yml b/.gitlab/ci/build-and-deploy.gitlab-ci.yml index 1cb646754..491434b42 100644 --- a/.gitlab/ci/build-and-deploy.gitlab-ci.yml +++ b/.gitlab/ci/build-and-deploy.gitlab-ci.yml @@ -81,8 +81,8 @@ review: before_script: [] cache: {} script: - - scripts/review-replace-urls - - scripts/deploy-review-app + - scripts/review-replace-urls.sh + - scripts/deploy-review-app.sh rules: - if: '$CI_PROJECT_PATH == "gitlab-renovate-forks/gitlab-docs"' when: manual @@ -109,7 +109,7 @@ review_stop: before_script: [] cache: {} script: - - scripts/deploy-review-app + - scripts/deploy-review-app.sh rules: - if: '$CI_PROJECT_PATH == "gitlab-renovate-forks/gitlab-docs"' allow_failure: true diff --git a/.gitlab/ci/test.gitlab-ci.yml b/.gitlab/ci/test.gitlab-ci.yml index 4c3ce4ead..631ca8982 100644 --- a/.gitlab/ci/test.gitlab-ci.yml +++ b/.gitlab/ci/test.gitlab-ci.yml @@ -126,6 +126,19 @@ markdownlint: - make markdownlint-tests # +# Run ShellCheck tests +# +shellcheck: + extends: + - .rules_site_tests + image: koalaman/shellcheck-alpine:v0.8.0 + needs: [] + stage: test + script: + - apk add make + - make shellcheck-tests + +# # Check for broken external links # test_external_links: diff --git a/.tool-versions b/.tool-versions index 40aeb466b..bdeea7f45 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,3 +1,4 @@ ruby 2.7.6 nodejs 16.15.0 +shellcheck 0.8.0 yarn 1.22.19 @@ -164,6 +164,10 @@ markdownlint-tests: @printf "\n$(INFO)INFO: Running markdownlint tests...$(END)\n" @yarn markdownlint doc/**/*.md +shellcheck-tests: + @printf "\n$(INFO)INFO: Running shellcheck tests...$(END)\n" + @shellcheck scripts/*.sh tasks/*.sh + check-global-navigation: @printf "\n$(INFO)INFO: Checking global navigation...$(END)\n" @scripts/check-navigation.sh diff --git a/doc/testing.md b/doc/testing.md index 9809fc614..f6d2921d0 100644 --- a/doc/testing.md +++ b/doc/testing.md @@ -10,16 +10,17 @@ configured in the project's [`.gitlab-ci.yml`](../.gitlab-ci.yml) file. These code tests are included in the project: -| Test target | Tool | Make target | Purpose | -|:----------- |:-------------|:---------------------|:-------------------------------------------| -| CSS | Stylelint | `stylelint-tests` | Code quality | -| Dockerfiles | Hadolint | `hadolint-tests` | Syntax checks | -| JavaScript | ESLint | `eslint-tests` | Syntax checks | -| JavaScript | Prettier | `prettier-tests` | Code formatting | -| Markdown | markdownlint | `markdownlint-tests` | Documentation formatting and syntax checks | -| Ruby | RSpec | `rspec-tests` | Unit tests | -| Vue | Jest | `jest-tests` | Unit tests | -| YAML | yamllint | `yamllint-tests` | Syntax checks | +| Test target | Tool | Make target | Purpose | +|:--------------|:-------------|:---------------------|:-------------------------------------------| +| CSS | Stylelint | `stylelint-tests` | Code quality | +| Dockerfiles | Hadolint | `hadolint-tests` | Syntax checks | +| JavaScript | ESLint | `eslint-tests` | Syntax checks | +| JavaScript | Prettier | `prettier-tests` | Code formatting | +| Markdown | markdownlint | `markdownlint-tests` | Documentation formatting and syntax checks | +| Ruby | RSpec | `rspec-tests` | Unit tests | +| Shell scripts | ShellCheck | `shellcheck-tests` | Syntax checks | +| Vue | Jest | `jest-tests` | Unit tests | +| YAML | yamllint | `yamllint-tests` | Syntax checks | ### Run code tests locally diff --git a/lefthook.yml b/lefthook.yml index 736217646..e8f377667 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -18,5 +18,7 @@ pre-push: run: make yamllint-tests markdownlint-tests: run: make markdownlint-tests + shellcheck-tests: + run: make shellcheck-tests navigation-checks: run: make check-global-navigation diff --git a/scripts/check-lunr-index.sh b/scripts/check-lunr-index.sh index b3019e2dd..2e368a389 100755 --- a/scripts/check-lunr-index.sh +++ b/scripts/check-lunr-index.sh @@ -18,17 +18,18 @@ COLOR_RESET="\e[39m" if [ "$CI" = "true" ]; then div_check=$(docker run --rm "$IMAGE_NAME" grep -o js-lunr-form "/usr/share/nginx/html/$GITLAB_VERSION/index.html") - index_check=$(docker run --rm "$IMAGE_NAME" ls "/usr/share/nginx/html/$GITLAB_VERSION/assets/javascripts/lunr-index.json" | wc -l) + index_check=$(docker run --rm "$IMAGE_NAME" find "/usr/share/nginx/html/$GITLAB_VERSION/assets/javascripts/lunr-index.json" | wc -l) else div_check=$(grep -o js-lunr-form public/index.html) - index_check=$(ls public/assets/javascripts/lunr-index.json | wc -l) + index_check=$(find public/assets/javascripts/lunr-index.json | wc -l) fi -if [ $index_check != 1 ]; +if [ "$index_check" != 1 ]; then # shellcheck disable=2059 printf "${COLOR_RED}ERROR: lunr.js index is not built!\n" printf " Did you forget to run 'make build-lunr-index'?\n" + # shellcheck disable=2059 printf " For more information, see https://gitlab.com/gitlab-org/gitlab-docs/-/blob/main/doc/docsearch.md#lunrjs-search${COLOR_RESET}\n" exit 1; else @@ -37,6 +38,7 @@ else # shellcheck disable=2059 printf "${COLOR_RED}ERROR: lunr.js index is found, but not enabled!\n" printf " Did you forget to build the site with ALGOLIA_SEARCH='false'?\n" + # shellcheck disable=2059 printf " For more information, see https://gitlab.com/gitlab-org/gitlab-docs/-/blob/main/doc/docsearch.md#lunrjs-search${COLOR_RESET}\n" exit 1; else diff --git a/scripts/compress_images.sh b/scripts/compress_images.sh index 87993268a..dd839d79f 100755 --- a/scripts/compress_images.sh +++ b/scripts/compress_images.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash TARGET="$1" VER="$2" @@ -23,7 +23,8 @@ if ! [ -d "$TARGET/$VER" ]; then fi # Compress images -for image in $(find ${TARGET}/${VER}/ -name "*.png") - do $PNG $image - echo "Compressing $image" +# shellcheck disable=SC2044 +for image in $(find "${TARGET}/${VER}/" -name "*.png") + do echo "Compressing $image" + $PNG "$image" done diff --git a/scripts/deploy-review-app b/scripts/deploy-review-app.sh index fa2bc0dc1..ea716099d 100755 --- a/scripts/deploy-review-app +++ b/scripts/deploy-review-app.sh @@ -31,14 +31,14 @@ function with_backoff { fi echo "Failure! Retrying in $timeout.." 1>&2 - sleep $timeout + sleep "$timeout" attempt=$(( attempt + 1 )) timeout=$(( timeout * 2 )) done if [[ $exitCode != 0 ]] then - echo "You've failed me for the last time! ($@)" 1>&2 + echo "You've failed me for the last time! ($*)" 1>&2 fi return $exitCode diff --git a/scripts/minify-assets.sh b/scripts/minify-assets.sh index 80bc7b919..cde1c20d6 100755 --- a/scripts/minify-assets.sh +++ b/scripts/minify-assets.sh @@ -1,10 +1,10 @@ -#!/bin/sh +#!/usr/bin/env bash TARGET="$1" VER="$2" MINIFY_FLAGS="--html-keep-document-tags --html-keep-whitespace --recursive" -if [ -z "$TARGET" -o -z "$VER" ]; then +if [ -z "$TARGET" ] || [ -z "$VER" ]; then echo "Usage: $0 <target> <ver>" echo "Either <target> or <ver> is missing. Exiting." exit 1 @@ -16,9 +16,7 @@ if ! [ -d "$TARGET" ]; then fi # Check if minify is in the PATH -which minify > /dev/null 2>&1 -# Check if the previous command has a 0 exit status -if [ $? -eq 0 ] +if which minify > /dev/null 2>&1 then MINIFY_BIN=$(which minify) else @@ -35,9 +33,9 @@ fi # Minify assets printf "Optimizing assets..." -printf "HTML..."; $MINIFY_BIN $MINIFY_FLAGS --type=html --match="\.html$" -o ${TARGET}/${VER}/ ${TARGET}/${VER} || true -printf "CSS..." ; $MINIFY_BIN $MINIFY_FLAGS --type=css --match="\.css$" -o ${TARGET}/${VER}/ ${TARGET}/${VER} || true -printf "JSON..."; $MINIFY_BIN $MINIFY_FLAGS --type=json --match="\.json$" -o ${TARGET}/${VER}/ ${TARGET}/${VER} || true -printf "SVG..." ; $MINIFY_BIN $MINIFY_FLAGS --type=svg --match="\.svg$" -o ${TARGET}/${VER}/ ${TARGET}/${VER} || true +printf "HTML..."; $MINIFY_BIN "$MINIFY_FLAGS" --type=html --match="\.html$" -o "${TARGET}/${VER}/" "${TARGET}/${VER}" || true +printf "CSS..." ; $MINIFY_BIN "$MINIFY_FLAGS" --type=css --match="\.css$" -o "${TARGET}/${VER}/" "${TARGET}/${VER}" || true +printf "JSON..."; $MINIFY_BIN "$MINIFY_FLAGS" --type=json --match="\.json$" -o "${TARGET}/${VER}/" "${TARGET}/${VER}" || true +printf "SVG..." ; $MINIFY_BIN "$MINIFY_FLAGS" --type=svg --match="\.svg$" -o "${TARGET}/${VER}/" "${TARGET}/${VER}" || true echo "Done" diff --git a/scripts/normalize-links.sh b/scripts/normalize-links.sh index 3f5d8e460..fd534f83d 100755 --- a/scripts/normalize-links.sh +++ b/scripts/normalize-links.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash TARGET="$1" # The directory that has all the HTML files including versions. # Usually public/ locally and /site in the Docker image. @@ -34,70 +34,56 @@ fi ## Relative URLs ## echo "Replace relative URLs in $TARGET/$VER for /ee/" -find ${TARGET}/$VER -type f -name '*.html' -print0 | xargs -0 sed -i 's#="/ee/#="/'"$VER"'/ee/#g' +find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 sed -i 's#="/ee/#="/'"$VER"'/ee/#g' echo "Replace relative URLs in $TARGET/$VER for /runner/" -find ${TARGET}/$VER -type f -name '*.html' -print0 | xargs -0 sed -i 's#="/runner/#="/'"$VER"'/runner/#g' +find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 sed -i 's#="/runner/#="/'"$VER"'/runner/#g' echo "Replace relative URLs in $TARGET/$VER for /omnibus/" -find ${TARGET}/$VER -type f -name '*.html' -print0 | xargs -0 sed -i 's#="/omnibus/#="/'"$VER"'/omnibus/#g' +find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 sed -i 's#="/omnibus/#="/'"$VER"'/omnibus/#g' echo "Replace relative URLs in $TARGET/$VER for /charts/" -find ${TARGET}/$VER -type f -name '*.html' -print0 | xargs -0 sed -i 's#="/charts/#="/'"$VER"'/charts/#g' +find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 sed -i 's#="/charts/#="/'"$VER"'/charts/#g' echo "Replace relative URLs in $TARGET/$VER for /operator/" -find ${TARGET}/$VER -type f -name '*.html' -print0 | xargs -0 sed -i 's#="/operator/#="/'"$VER"'/operator/#g' +find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 sed -i 's#="/operator/#="/'"$VER"'/operator/#g' echo "Replace relative URLs in $TARGET/$VER for /assets/" -find ${TARGET}/$VER -type f -name '*.html' -print0 | xargs -0 sed -i 's#="/assets/#="/'"$VER"'/assets/#g' +find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 sed -i 's#="/assets/#="/'"$VER"'/assets/#g' echo "Replace relative URLs in $TARGET/$VER for /frontend/" -find ${TARGET}/$VER -type f -name '*.html' -print0 | xargs -0 sed -i 's#="/frontend/#="/'"$VER"'/frontend/#g' +find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 sed -i 's#="/frontend/#="/'"$VER"'/frontend/#g' echo "Replace relative URLs in $TARGET/$VER for /" -find ${TARGET}/$VER -type f -name '*.html' -print0 | xargs -0 sed -i 's#<a href="/">#<a href="/'"$VER"'/">#g' +find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 sed -i 's#<a href="/">#<a href="/'"$VER"'/">#g' echo "Replace relative URLs in $TARGET/$VER for opensearch.xml" -find ${TARGET}/$VER -type f -name '*.html' -print0 | xargs -0 sed -i 's#="/opensearch.xml#="/'"$VER"'/opensearch.xml#g' +find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 sed -i 's#="/opensearch.xml#="/'"$VER"'/opensearch.xml#g' ## ## Full URLs ## echo "Replace full URLs in $TARGET/$VER for /ee/" -find ${TARGET}/$VER -type f -name '*.html' -print0 | xargs -0 sed -i 's#="https://docs.gitlab.com/ee/#="/'"$VER"'/ee/#g' +find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 sed -i 's#="https://docs.gitlab.com/ee/#="/'"$VER"'/ee/#g' echo "Replace full URLs in $TARGET/$VER for /runner/" -find ${TARGET}/$VER -type f -name '*.html' -print0 | xargs -0 sed -i 's#="https://docs.gitlab.com/runner/#="/'"$VER"'/runner/#g' +find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 sed -i 's#="https://docs.gitlab.com/runner/#="/'"$VER"'/runner/#g' echo "Replace full URLs in $TARGET/$VER for /omnibus/" -find ${TARGET}/$VER -type f -name '*.html' -print0 | xargs -0 sed -i 's#="https://docs.gitlab.com/omnibus/#="/'"$VER"'/omnibus/#g' +find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 sed -i 's#="https://docs.gitlab.com/omnibus/#="/'"$VER"'/omnibus/#g' echo "Replace full URLs in $TARGET/$VER for /charts/" -find ${TARGET}/$VER -type f -name '*.html' -print0 | xargs -0 sed -i 's#="https://docs.gitlab.com/charts/#="/'"$VER"'/charts/#g' +find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 sed -i 's#="https://docs.gitlab.com/charts/#="/'"$VER"'/charts/#g' echo "Replace full URLs in $TARGET/$VER for /operator/" -find ${TARGET}/$VER -type f -name '*.html' -print0 | xargs -0 sed -i 's#="https://docs.gitlab.com/operator/#="/'"$VER"'/operator/#g' +find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 sed -i 's#="https://docs.gitlab.com/operator/#="/'"$VER"'/operator/#g' echo "Fix URLs inside the sitemap" -find ${TARGET}/$VER -type f -name 'sitemap.xml' -print0 | xargs -0 sed -i 's#docs.gitlab.com/#docs.gitlab.com/'"$VER"'/#g' - -## -## In order to have clean URLs, we symlink README.html to index.html. -## That way, visiting https://docs.gitlab.com/ee/ would be the same as -## visiting https://docs.gitlab.com/ee/{README.html,index.html} -## For 13.9 and later, there's a raketask that is run instead of the -## command below. If the raketask is present, skip the command. -## -bundle exec rake -T | grep symlink_readmes -if [ $? -eq 1 ] -then - echo "Symlink all README.html to index.html" - for i in `find ${TARGET}/${VER} -name README.html`; do ln -sf README.html $(dirname $i)/index.html; done -fi +find "${TARGET}/$VER" -type f -name 'sitemap.xml' -print0 | xargs -0 sed -i 's#docs.gitlab.com/#docs.gitlab.com/'"$VER"'/#g' ## ## Don't deploy the CE docs since they are identical to the EE ones. ## https://gitlab.com/gitlab-org/gitlab-docs/issues/418 ## echo "Remove CE dir and symlink EE to CE" -if [ -d "${TARGET}/${VER}/ce/" ]; then cd ${TARGET}/${VER} && rm -r ce && ln -s ee ce; fi +if [ -d "${TARGET}/${VER}/ce/" ]; then cd "${TARGET}/${VER}" && rm -r ce && ln -s ee ce; fi diff --git a/scripts/review-replace-urls b/scripts/review-replace-urls.sh index 108b763ac..108b763ac 100755 --- a/scripts/review-replace-urls +++ b/scripts/review-replace-urls.sh diff --git a/tasks/unlinked-images.sh b/tasks/unlinked-images.sh index 6cc8bfabc..54758124f 100755 --- a/tasks/unlinked-images.sh +++ b/tasks/unlinked-images.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash unlinked_files=0 |