Skip to content

Commit

Permalink
fix: correct leveled dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
0-vortex committed May 16, 2023
1 parent 271b14c commit 30ceb10
Show file tree
Hide file tree
Showing 5 changed files with 441 additions and 119 deletions.
46 changes: 44 additions & 2 deletions .github/workflows/development.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Development"
name: Development

on:
pull_request:
Expand All @@ -7,7 +7,49 @@ on:
- edited
- synchronize
- reopened
workflow_call:

jobs:
test:
uses: open-sauced/open-sauced/.github/workflows/development.yml@main
name: Test application
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: "☁️ checkout repository"
uses: actions/checkout@v3

- name: "🔧 setup node"
uses: actions/setup-node@v3
with:
node-version: 18

- name: "🔧 install npm@latest"
run: npm i -g npm@latest

- name: "📦 install dependencies"
uses: bahmutov/npm-install@v1

- name: "🔍 run tests"
run: npm run test --if-present

lint:
name: Code standards
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: "☁️ checkout repository"
uses: actions/checkout@v3

- name: "🔧 setup node"
uses: actions/setup-node@v3
with:
node-version: 18

- name: "🔧 install npm@latest"
run: npm i -g npm@latest

- name: "📦 install dependencies"
uses: bahmutov/npm-install@v1

- name: "🔍 lint code"
run: npm run lint --if-present
36 changes: 18 additions & 18 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: "☁️ compute environment variables"
id: env
run: |
echo "::set-output name=DEPLOY_ENVIRONMENT::$([[ ${{ github.ref_name }} == 'main' ]] && echo 'production' || echo ${{ github.ref_name }})"
echo "DEPLOY_ENVIRONMENT=$([[ ${{ github.ref_name }} == 'main' ]] && echo 'production' || echo ${{ github.ref_name }})" >> $GITHUB_OUTPUT
test:
name: Test and lint
Expand All @@ -28,13 +28,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: "☁️ checkout repository"
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: "🔧 setup buildx"
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2

- name: "🔧 cache docker layers"
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
Expand All @@ -43,13 +43,13 @@ jobs:
- name: "🔧 docker meta"
id: meta
uses: docker/metadata-action@v3
uses: docker/metadata-action@v4
with:
images: ${{ github.repository }}
tags: latest

- name: "📦 docker build"
uses: docker/build-push-action@v2
uses: docker/build-push-action@v4
with:
context: .
tags: ${{ steps.meta.outputs.tags }}
Expand All @@ -60,7 +60,7 @@ jobs:
cache-to: type=gha, scope=${{ github.workflow }}

- name: "📂 docker artifacts"
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: docker
path: /tmp/docker.tar
Expand All @@ -70,10 +70,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: "☁️ checkout repository"
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: "🔧 setup node"
uses: actions/setup-node@v2.1.5
uses: actions/setup-node@v3
with:
node-version: 16

Expand All @@ -85,15 +85,15 @@ jobs:

- name: "📊 repository visualizer"
id: diagram
uses: githubocto/repo-visualizer@0.7.1
uses: githubocto/repo-visualizer@0.9.1
with:
excluded_paths: "node_modules,build,.storybook,.netlify,.github,npm-shrinkwrap.json"
output_file: "public/diagram.svg"
should_push: false
root_path: "src/"

- name: "📊 visualiser artifacts"
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: diagram
path: public/diagram.svg
Expand All @@ -102,7 +102,7 @@ jobs:
run: npm run build

- name: "📂 production artifacts"
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: build
path: build
Expand All @@ -120,7 +120,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: "☁️ checkout repository"
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

Expand All @@ -129,7 +129,7 @@ jobs:
rm -rf public/diagram.svg
- name: "📂 download docker artifacts"
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: docker
path: /tmp
Expand All @@ -140,20 +140,20 @@ jobs:
docker image ls -a
- name: "📂 download build artifacts"
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: build
path: build

- name: "📂 download diagram artifacts"
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: diagram
path: public/

- name: "🚀 release"
id: semantic-release
uses: open-sauced/release@v1
uses: open-sauced/release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -164,7 +164,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: "♻️ remove build artifacts"
uses: geekyeggo/delete-artifact@v1
uses: geekyeggo/delete-artifact@v2
with:
name: |
build
Expand Down
86 changes: 53 additions & 33 deletions .squoosh.mjs
Original file line number Diff line number Diff line change
@@ -1,46 +1,66 @@
import { dirname } from "path";
import {execa} from "execa";
import { mkdtemp } from 'node:fs/promises';
import { join } from 'node:path';
import { tmpdir } from 'node:os';
import { writeFileSync } from "node:fs";
import glob from "glob";
import pLimit from "p-limit";
import sharp from "sharp";

const limit = pLimit(3);
const [globs] = process.argv.slice(2);
const algo = {
'jpg': '--mozjpeg',
'jpeg': '--mozjpeg',
'png': '--oxipng',
'webp': '--webp',
'avif': '--avif',
'jxl': '--jxl',
'wp2': '--wp2',
};
const promises = [];
const errors = [];

const imgs = glob.sync(globs, {nonull: false});

imgs && imgs.map(async (img) => promises.push(
limit(async () => {
try {
const dir = dirname(img);
const ext = /\.([^\.]+)$/ig.exec(img)[1];

await execa("squoosh-cli", [
algo[ext],
"auto",
"--output-dir",
dir,
img
], {
stderr: process.stdout,
stdout: process.stdout
});
} catch (e) {
console.log(e);
// errors.push(e.message || e);
}
})
));
if (imgs.length !== 0) {
const dir = await mkdtemp(join(tmpdir(), 'optimise-'));

imgs.map(async (img) => promises.push(
limit(async () => {
try {
const ext = /\.([^\.]+)$/ig.exec(img)[1];
const outputFile = join(dir, img);

// Convert and optimize images
let image = sharp(img);

switch (ext) {
case 'jpg':
image.jpeg({ mozjpeg: true });
break;
case 'jpeg':
image.jpeg({ mozjpeg: true });
break;
case 'png':
image.png({ oxipng: true });
break;
case 'webp':
image.webp();
break;
case 'avif':
image.avif();
break;
case 'jxl':
image.jxl();
break;
case 'wp2':
image.wp2();
break;
default:
throw new Error(`Unsupported file extension: ${ext}`);
}

writeFileSync(img, await image.toBuffer());

// await image.toFile(outputFile);
} catch (e) {
console.log(e);
errors.push(e.message || e);
}
})
));
}

await Promise.all(promises);

Expand Down
Loading

0 comments on commit 30ceb10

Please sign in to comment.