Skip to content

Commit

Permalink
feat: migrate to makefile and add deduplicate task (#2)
Browse files Browse the repository at this point in the history
Co-authored-by: John Kenny <johnkenny54@yahoo.com>
  • Loading branch information
SethFalco and johnkenny54 committed May 25, 2024
1 parent 78f50b2 commit 32ed67e
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Makefile]
indent_style = tab
15 changes: 3 additions & 12 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,10 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build test suite
run: |
mkdir -p svgs/W3C_SVG_11_TestSuite dist
wget https://www.w3.org/Graphics/SVG/Test/20110816/archives/W3C_SVG_11_TestSuite.tar.gz
tar -tf W3C_SVG_11_TestSuite.tar.gz | grep -E '^svg/.+\.svgz?$' > filter.txt
tar -C svgs/W3C_SVG_11_TestSuite -xf W3C_SVG_11_TestSuite.tar.gz -T filter.txt
wget https://download.kde.org/stable/frameworks/5.113/oxygen-icons-5.113.0.tar.xz
tar -tf oxygen-icons-5.113.0.tar.xz | grep -E '\.svgz?$' > filter.txt
tar -C svgs -xf oxygen-icons-5.113.0.tar.xz -T filter.txt
find svgs -type l -delete
find svgs -type f -name "*.svgz" -exec sh -c '7z e -so {} > $(echo {} | sed s/\.svgz$/\.svg/)' \; -delete
find svgs -type f -exec bash -c 'if [ $(file -bi {} | sed -e "s/.* charset=//") == 'utf-16le' ]; then echo "$(iconv -f utf-16le -t utf-8 {})" > {}; fi' \;
tar czf dist/svgo-test-suite.tar.gz svgs/*
run: make build
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
on:
pull_request:
branches:
- main

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build test suite
run: make build
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/dist/
/svgs/
/filter.txt
/*.tar.*
46 changes: 46 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
clean:
rm -rf dist
rm -rf svgs
rm -f oxygen-icons-*.tar.xz
rm -f W3C_SVG_11_TestSuite.tar.gz

fetch-w3c-test-suite:
mkdir -p svgs/W3C_SVG_11_TestSuite
wget https://www.w3.org/Graphics/SVG/Test/20110816/archives/W3C_SVG_11_TestSuite.tar.gz --no-clobber
tar -tf W3C_SVG_11_TestSuite.tar.gz | grep -E '^svg/.+\.svgz?$$' > filter.txt
tar -C svgs/W3C_SVG_11_TestSuite -xf W3C_SVG_11_TestSuite.tar.gz -T filter.txt
rm filter.txt

fetch-oxygen-icons:
mkdir -p svgs
wget https://download.kde.org/stable/frameworks/5.113/oxygen-icons-5.113.0.tar.xz --no-clobber
tar -tf oxygen-icons-5.113.0.tar.xz | grep -E '\.svgz?$$' > filter.txt
tar -C svgs -xf oxygen-icons-5.113.0.tar.xz -T filter.txt
rm filter.txt

normalize:
find svgs -type l -delete
find svgs -type f -name "*.svgz" -exec sh -c '7z e -so {} > $$(echo {} | sed s/\.svgz$$/\.svg/)' \; -delete
find svgs -type f -exec bash -c 'if [ $$(file -bi {} | sed -e "s/.* charset=//") == 'utf-16le' ]; then echo "$$(iconv -f utf-16le -t utf-8 {})" > {}; fi' \;

deduplicate:
@find svgs -type f | while read FILE; \
do \
HASH=$$(sha1sum $$FILE | awk "{ print \$$1 }"); \
if echo $$HASHES | grep $$HASH -q; then \
rm $$FILE; \
else \
HASHES="$$HASHES $$HASH"; \
fi; \
done;

package:
mkdir -p dist
tar czf dist/svgo-test-suite.tar.gz svgs/*

build:
make fetch-w3c-test-suite
make fetch-oxygen-icons
make normalize
make deduplicate
make package
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Here are the differences between the repack and the originals:
* Excludes symlinks.
* Converts SVGZ files to SVGs.
* Includes only SVG files.
* Deletes duplicate files.

## SVG Optimizer

Expand Down

0 comments on commit 32ed67e

Please sign in to comment.