Skip to content

Commit

Permalink
p
Browse files Browse the repository at this point in the history
Signed-off-by: ClaytonTDM <[email protected]>
  • Loading branch information
ClaytonTDM committed Oct 8, 2024
1 parent 9a52578 commit e7bfa45
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 40 deletions.
84 changes: 45 additions & 39 deletions .github/workflows/gifToWebp.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,52 @@
name: GIF to WebP Conversion

on:
push:
branches:
- main # or your default branch name
push:
branches:
- main # or your default branch name

permissions:
contents: write
contents: write

jobs:
convert-and-commit:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20'

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y imagemagick
sudo apt-get install -y webp
curl -L https://github.com/ImageOptim/gifski/releases/download/1.11.0/gifski_1.11.0_amd64.deb -o gifski.deb
sudo dpkg -i gifski.deb
- name: Run conversion script
run: |
node convert.js
- name: Commit and push changes
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add -A
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "Convert GIF files to WebP"
git push
fi
convert-and-commit:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "18"

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y imagemagick
sudo apt-get install -y webp
curl -L https://github.com/ImageOptim/gifski/releases/download/1.11.0/gifski_1.11.0_amd64.deb -o gifski.deb
sudo dpkg -i gifski.deb
- name: Run conversion script
run: |
node convert.js
- name: Check for changes
id: git-check
run: |
git add -A
if git diff --staged --quiet; then
echo "changes=false" >> $GITHUB_OUTPUT
else
echo "changes=true" >> $GITHUB_OUTPUT
fi
- name: Commit and push changes
if: steps.git-check.outputs.changes == 'true'
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -m "Convert GIF files to WebP and remove original GIFs"
git push
8 changes: 7 additions & 1 deletion convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ async function convertGifToWebp(inputPath, outputPath) {
]);
}
console.log(`Converted ${inputPath} to ${outputPath}`);

// Delete the original GIF file
await fs.unlink(inputPath);
console.log(`Deleted original GIF: ${inputPath}`);

return true;
} catch (error) {
console.error(`Error converting ${inputPath}: ${error.message}`);
Expand Down Expand Up @@ -197,8 +202,9 @@ async function processDirectory(directoryPath, allConvertedFiles = []) {
async function main() {
const rootDirectory = ".";
console.log(`Starting conversion process in ${rootDirectory}`);
await processDirectory(rootDirectory);
const convertedFiles = await processDirectory(rootDirectory);
console.log("Conversion process completed");
console.log(`Total files converted: ${convertedFiles.length}`);
}

main().catch((error) => console.error("An error occurred:", error));

0 comments on commit e7bfa45

Please sign in to comment.