Skip to content
Open
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
57 changes: 56 additions & 1 deletion .github/workflows/deploy-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,60 @@ jobs:
find ./content/hardware -type f -name "*-pinout.png" -exec cp {} ./static/resources/pinouts/ \;
find ./content/hardware -type f -name "*-step.zip" -exec cp {} ./static/resources/models/ \;

- name: Check for large files
run: |
find content -type f \( -name "*.png" -o -name "*.jpg" -o -name "*.jpeg" -o -name "*.svg" -o -name "*.gif" \) -size +2M -print0 |
while IFS= read -r -d $'\0' file; do
size=$(ls -lh "$file" | awk '{print $5}')
echo "::warning file=$file::File '$file' is very large: $size. Consider optimizing it."
done

find content -type f \( -name "*.pdf" -o -name "*.zip" -o -name "*.mp4" \) -size +10M -print0 |
while IFS= read -r -d $'\0' file; do
size=$(ls -lh "$file" | awk '{print $5}')
echo "::warning file=$file::File '$file' is very large: $size. This can impact repository size and checkout times."
done

# - name: Fail on Oversized Files
# id: fail_on_oversized_files
# run: |
# #!/bin/bash
# # This script is a stricter check that fails the workflow if files exceed size limits.
# set -e

# # Thresholds in Megabytes (same as the warning step)
# IMAGE_LIMIT_MB=2
# ASSET_LIMIT_MB=10

# # Find oversized files and prepare a detailed report
# OVERSIZED_FILES=$(find content -type f \
# \( \( -name "*.png" -o -name "*.jpg" -o -name "*.jpeg" -o -name "*.svg" -o -name "*.gif" \) -size "+${IMAGE_LIMIT_MB}M" \) -o \
# \( \( -name "*.pdf" -o -name "*.zip" -o -name "*.mp4" \) -size "+${ASSET_LIMIT_MB}M" \) \
# -exec ls -lh {} + | awk '{printf " - %s (%s)\n", $9, $5}')

# # Check if the report is non-empty and fail the job if so
# if [ -n "$OVERSIZED_FILES" ]; then
# echo "::error::Found files exceeding size limits. This new check is failing the build as intended."
# echo "--------------------------------------------------"
# echo "Oversized Files Found:"
# echo "$OVERSIZED_FILES"
# echo "--------------------------------------------------"
# echo "Limits:"
# echo " - Images (PNG, JPG, SVG, GIF): ${IMAGE_LIMIT_MB}MB"
# echo " - Assets (PDF, ZIP, MP4): ${ASSET_LIMIT_MB}MB"
# exit 1
# else
# echo "No oversized files found. New check passed."
# fi

- name: Compress Large Images
run: |
sudo apt-get update && sudo apt-get install -y jpegoptim optipng
echo "Compressing large JPGs..."
find content -type f \( -name "*.jpg" -o -name "*.jpeg" \) -size +2M -print -exec jpegoptim --strip-all {} \;
echo "Compressing large PNGs..."
find content -type f -name "*.png" -size +2M -print -exec optipng -o2 {} \;

- name: Gatsby main cache
uses: actions/cache@v4
id: gatsby-cache-folder
Expand All @@ -91,7 +145,8 @@ jobs:

- run: npm install

- run: npm run build
- name: Build
run: npm run build

- name: Clean up node_modules # Just to save space
run: rm -rf node_modules
Expand Down
57 changes: 56 additions & 1 deletion .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,60 @@ jobs:
find ./content/hardware -type f -name "*-pinout.png" -exec cp {} ./static/resources/pinouts/ \;
find ./content/hardware -type f -name "*-step.zip" -exec cp {} ./static/resources/models/ \;

- name: Check for large files
run: |
find content -type f \( -name "*.png" -o -name "*.jpg" -o -name "*.jpeg" -o -name "*.svg" -o -name "*.gif" \) -size +2M -print0 |
while IFS= read -r -d $'\0' file; do
size=$(ls -lh "$file" | awk '{print $5}')
echo "::warning file=$file::File '$file' is very large: $size. Consider optimizing it."
done

find content -type f \( -name "*.pdf" -o -name "*.zip" -o -name "*.mp4" \) -size +10M -print0 |
while IFS= read -r -d $'\0' file; do
size=$(ls -lh "$file" | awk '{print $5}')
echo "::warning file=$file::File '$file' is very large: $size. This can impact repository size and checkout times."
done

# - name: Fail on Oversized Files
# id: fail_on_oversized_files
# run: |
# #!/bin/bash
# # This script is a stricter check that fails the workflow if files exceed size limits.
# set -e

# # Thresholds in Megabytes (same as the warning step)
# IMAGE_LIMIT_MB=2
# ASSET_LIMIT_MB=10

# # Find oversized files and prepare a detailed report
# OVERSIZED_FILES=$(find content -type f \
# \( \( -name "*.png" -o -name "*.jpg" -o -name "*.jpeg" -o -name "*.svg" -o -name "*.gif" \) -size "+${IMAGE_LIMIT_MB}M" \) -o \
# \( \( -name "*.pdf" -o -name "*.zip" -o -name "*.mp4" \) -size "+${ASSET_LIMIT_MB}M" \) \
# -exec ls -lh {} + | awk '{printf " - %s (%s)\n", $9, $5}')

# # Check if the report is non-empty and fail the job if so
# if [ -n "$OVERSIZED_FILES" ]; then
# echo "::error::Found files exceeding size limits. This new check is failing the build as intended."
# echo "--------------------------------------------------"
# echo "Oversized Files Found:"
# echo "$OVERSIZED_FILES"
# echo "--------------------------------------------------"
# echo "Limits:"
# echo " - Images (PNG, JPG, SVG, GIF): ${IMAGE_LIMIT_MB}MB"
# echo " - Assets (PDF, ZIP, MP4): ${ASSET_LIMIT_MB}MB"
# exit 1
# else
# echo "No oversized files found. New check passed."
# fi

- name: Compress Large Images
run: |
sudo apt-get update && sudo apt-get install -y jpegoptim optipng
echo "Compressing large JPGs..."
find content -type f \( -name "*.jpg" -o -name "*.jpeg" \) -size +2M -print -exec jpegoptim --strip-all {} \;
echo "Compressing large PNGs..."
find content -type f -name "*.png" -size +2M -print -exec optipng -o2 {} \;

- name: Gatsby main cache
uses: actions/cache@v4
id: gatsby-cache-folder
Expand All @@ -91,7 +145,8 @@ jobs:

- run: npm install

- run: npm run build
- name: Build
run: npm run build

- name: Clean up node_modules # Just to save space
run: rm -rf node_modules
Expand Down
108 changes: 106 additions & 2 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,72 @@ concurrency:
cancel-in-progress: true

jobs:
image-size-check:
name: Image Size Check
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44

- name: Enforce Image Size Limits on Changed Files
if: steps.changed-files.outputs.all_changed_files
run: |
#!/bin/bash
set -e

# Input from the previous step
CHANGED_FILES="${{ steps.changed-files.outputs.all_changed_files }}"

IMAGE_LIMIT_MB=2
GIF_LIMIT_MB=10

OVERSIZED_IMAGES=""
OVERSIZED_GIFS=""

for file in $CHANGED_FILES; do
if [[ "$file" == *.png || "$file" == *.jpg || "$file" == *.jpeg || "$file" == *.svg ]]; then
size_in_bytes=$(stat -c%s "$file")
limit_in_bytes=$((IMAGE_LIMIT_MB * 1024 * 1024))
if [ "$size_in_bytes" -gt "$limit_in_bytes" ]; then
size_human=$(ls -lh "$file" | awk '{print $5}')
OVERSIZED_IMAGES+=" - $file ($size_human)\n"
fi
elif [[ "$file" == *.gif ]]; then
size_in_bytes=$(stat -c%s "$file")
limit_in_bytes=$((GIF_LIMIT_MB * 1024 * 1024))
if [ "$size_in_bytes" -gt "$limit_in_bytes" ]; then
size_human=$(ls -lh "$file" | awk '{print $5}')
OVERSIZED_GIFS+=" - $file ($size_human)\n"
fi
fi
done

# This job is used to render datasheets, but only if they have changed.
# --- Report errors if any oversized files are found ---
ERROR_MESSAGE=""
if [ -n "$OVERSIZED_IMAGES" ]; then
ERROR_MESSAGE+="Found images exceeding the ${IMAGE_LIMIT_MB}MB limit:\n"
ERROR_MESSAGE+="${OVERSIZED_IMAGES}"
fi

if [ -n "$OVERSIZED_GIFS" ]; then
ERROR_MESSAGE+="Found GIFs exceeding the ${GIF_LIMIT_MB}MB limit:\n"
ERROR_MESSAGE+="${OVERSIZED_GIFS}"
fi

if [ -n "$ERROR_MESSAGE" ]; then
echo -e "::error::Oversized images found in this PR. Please optimize or remove them.\n"
echo -e "--------------------------------------------------"
echo -e "$ERROR_MESSAGE"
echo -e "--------------------------------------------------"
exit 1
else
echo "All changed images are within their size limits. Check passed."
fi
# This job is used to render datasheets, but only if they have changed.
# It's a separate job so we don't have to cleanup the machine afterwards.
render-datasheets:
name: Render Datasheets
Expand Down Expand Up @@ -67,7 +131,7 @@ jobs:
fetch-depth: 1

- name: Cleanup runner disk
uses: ./.github/actions/cleanup-disk
uses: ./.github/actions/cleanup-disk
- uses: actions/setup-node@v4
with:
node-version: 18
Expand All @@ -89,6 +153,46 @@ jobs:
find ./content/hardware -type f -name "*-pinout.png" -exec cp {} ./static/resources/pinouts/ \;
find ./content/hardware -type f -name "*-step.zip" -exec cp {} ./static/resources/models/ \;

# - name: Fail on Oversized Files
# id: fail_on_oversized_files
# run: |
# #!/bin/bash
# # This script is a stricter check that fails the workflow if files exceed size limits.
# set -e

# # Thresholds in Megabytes (same as the warning step)
# IMAGE_LIMIT_MB=2
# ASSET_LIMIT_MB=10

# # Find oversized files and prepare a detailed report
# OVERSIZED_FILES=$(find content -type f \
# \( \( -name "*.png" -o -name "*.jpg" -o -name "*.jpeg" -o -name "*.svg" -o -name "*.gif" \) -size "+${IMAGE_LIMIT_MB}M" \) -o \
# \( \( -name "*.pdf" -o -name "*.zip" -o -name "*.mp4" \) -size "+${ASSET_LIMIT_MB}M" \) \
# -exec ls -lh {} + | awk '{printf " - %s (%s)\n", $9, $5}')

# # Check if the report is non-empty and fail the job if so
# if [ -n "$OVERSIZED_FILES" ]; then
# echo "::error::Found files exceeding size limits. This new check is failing the build as intended."
# echo "--------------------------------------------------"
# echo "Oversized Files Found:"
# echo "$OVERSIZED_FILES"
# echo "--------------------------------------------------"
# echo "Limits:"
# echo " - Images (PNG, JPG, SVG, GIF): ${IMAGE_LIMIT_MB}MB"
# echo " - Assets (PDF, ZIP, MP4): ${ASSET_LIMIT_MB}MB"
# exit 1
# else
# echo "No oversized files found. New check passed."
# fi

- name: Compress Large Images
run: |
sudo apt-get update && sudo apt-get install -y jpegoptim optipng
echo "Compressing large JPGs..."
find content -type f \( -name "*.jpg" -o -name "*.jpeg" \) -size +2M -print -exec jpegoptim --strip-all {} \;
echo "Compressing large PNGs..."
find content -type f -name "*.png" -size +2M -print -exec optipng -o2 {} \;

- name: Gatsby main cache
uses: actions/cache@v4
id: gatsby-cache-folder
Expand Down
Loading