From 27d5af5fd0b0308181a0a46b04832b1c096ad04c Mon Sep 17 00:00:00 2001 From: Seth Falco Date: Sat, 25 May 2024 09:19:49 +0100 Subject: [PATCH] feat: migrate to makefile and add deduplicate task Co-authored-by: John Kenny --- .editorconfig | 2 ++ .github/workflows/build-and-deploy.yml | 15 ++------- .gitignore | 4 +++ Makefile | 46 ++++++++++++++++++++++++++ README.md | 1 + 5 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 Makefile diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..8c5189d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,2 @@ +[Makefile] +indent_style = tab diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index 11acc0c..cca81f0 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -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: diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5f490fc --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/dist/ +/svgs/ +/filter.txt +/*.tar.* diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d81ff53 --- /dev/null +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index 67c47ee..295a28e 100644 --- a/README.md +++ b/README.md @@ -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