Skip to content

chore: enforce that site icons are .svg #8684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,14 @@ else
endif
.PHONY: fmt/shfmt

lint: lint/shellcheck lint/go lint/ts lint/helm
lint: lint/shellcheck lint/go lint/ts lint/helm lint/site-icons
.PHONY: lint

lint/site-icons:
./scripts/check_site_icons.sh

.PHONY: lint/site-icons

lint/ts:
cd site
yarn && yarn lint
Expand Down
44 changes: 44 additions & 0 deletions scripts/check_site_icons.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

set -euo pipefail
# shellcheck source=scripts/lib.sh
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
cdroot

cd site/static/icon

# These exceptions are here for backwards compatibility. All new icons should
# be SVG to minimize the size of our repo and our bundle.
exceptions=(
"aws.png"
"azure.png"
"docker.png"
"do.png"
"gcp.png"
"k8s.png"
)

function is_exception() {
local value="$1"
shift
for item; do
[[ "$item" == "$value" ]] && return 0
done
return 1
}

for file in *; do
# Extract filename
filename=$(basename -- "$file")

# Check if the file is in the exception list
if is_exception "$filename" "${exceptions[@]}"; then
continue
fi

# If not an exception, check if it's an svg file
if [[ "$file" != *.svg ]]; then
echo "Found a non-svg file not in exception list: $file"
exit 1
fi
done
14 changes: 13 additions & 1 deletion scripts/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,19 @@ realpath() {
# We have to define realpath before these otherwise it fails on Mac's bash.
SCRIPT="${BASH_SOURCE[1]:-${BASH_SOURCE[0]}}"
SCRIPT_DIR="$(realpath "$(dirname "$SCRIPT")")"
PROJECT_ROOT="$(cd "$SCRIPT_DIR" && realpath "$(git rev-parse --show-toplevel)")"

function project_root {
# Try to use `git rev-parse --show-toplevel` to find the project root.
# If this directory is not a git repository, this command will fail.
git rev-parse --show-toplevel 2>/dev/null && return

# This finds the Sapling root. This behavior is added so that @ammario
# and others can more easily experiment with Sapling, but we do not have a
# plan to support Sapling across the repo.
sl root 2>/dev/null && return
}

PROJECT_ROOT="$(cd "$SCRIPT_DIR" && realpath "$(project_root)")"

# pushd is a silent alternative to the real pushd shell command.
pushd() {
Expand Down