Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Amirault <mamirault@gitlab.com>2022-11-24 19:15:29 +0300
committerMarcel Amirault <mamirault@gitlab.com>2022-11-24 19:15:29 +0300
commit7fbb5e1313ebde811877044e87f444a0a283fed4 (patch)
tree8aebef4f6c6d438646164d9c4bd141b5f88ad2e8
parentdd505e0a4ce229c0e24c26a8ffca599f70f95712 (diff)
parent95a5390f185351f20081097da18c6f364ce96f8a (diff)
Merge branch 'eread/add-shellcheck-to-project' into 'main'
Add ShellCheck to project See merge request https://gitlab.com/gitlab-org/gitlab-docs/-/merge_requests/3291 Merged-by: Marcel Amirault <mamirault@gitlab.com> Approved-by: Marcel Amirault <mamirault@gitlab.com> Co-authored-by: Evan Read <eread@gitlab.com>
-rw-r--r--.gitlab/ci/build-and-deploy.gitlab-ci.yml6
-rw-r--r--.gitlab/ci/test.gitlab-ci.yml13
-rw-r--r--.tool-versions1
-rw-r--r--Makefile4
-rw-r--r--doc/testing.md21
-rw-r--r--lefthook.yml2
-rwxr-xr-xscripts/check-lunr-index.sh8
-rwxr-xr-xscripts/compress_images.sh9
-rwxr-xr-xscripts/deploy-review-app.sh (renamed from scripts/deploy-review-app)4
-rwxr-xr-xscripts/minify-assets.sh16
-rwxr-xr-xscripts/normalize-links.sh48
-rwxr-xr-xscripts/review-replace-urls.sh (renamed from scripts/review-replace-urls)0
-rwxr-xr-xtasks/unlinked-images.sh2
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 8a90beb1..ce41b369 100644
--- a/.gitlab/ci/build-and-deploy.gitlab-ci.yml
+++ b/.gitlab/ci/build-and-deploy.gitlab-ci.yml
@@ -108,8 +108,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
@@ -136,7 +136,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 4c3ce4ea..631ca898 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 40aeb466..bdeea7f4 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
diff --git a/Makefile b/Makefile
index 2e1a1c83..4cfff9d1 100644
--- a/Makefile
+++ b/Makefile
@@ -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 9809fc61..f6d2921d 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 73621764..e8f37766 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 b3019e2d..2e368a38 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 87993268..dd839d79 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 fa2bc0dc..ea716099 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 80bc7b91..cde1c20d 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 3f5d8e46..fd534f83 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 108b763a..108b763a 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 6cc8bfab..54758124 100755
--- a/tasks/unlinked-images.sh
+++ b/tasks/unlinked-images.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
unlinked_files=0