Skip to content

Commit 68e530d

Browse files
committed
add CI/CD
1 parent 577a233 commit 68e530d

File tree

4 files changed

+87
-9
lines changed

4 files changed

+87
-9
lines changed

.github/workflows/build-deploy.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Build
2+
3+
run-name: Build Code
4+
5+
on:
6+
push:
7+
branches: ['main']
8+
9+
permissions:
10+
contents: write
11+
12+
concurrency:
13+
group: "build"
14+
cancel-in-progress: true
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout Repo
22+
uses: actions/checkout@v3
23+
24+
- name: Build
25+
run: |
26+
npm ci
27+
npm run build
28+
cd dist
29+
touch .nojekyll
30+
31+
- name: Minify Code
32+
uses: Lenni009/minify-js@main
33+
with:
34+
directory: dist
35+
overwrite: true
36+
37+
- name: Deploy to GitHub Pages
38+
uses: JamesIves/github-pages-deploy-action@v4
39+
with:
40+
folder: dist # The folder the action should deploy.

.github/workflows/test-build.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Test Build
2+
run-name: Test Build
3+
4+
on:
5+
pull_request:
6+
types: [opened, synchronize]
7+
8+
concurrency:
9+
group: "testbuild"
10+
cancel-in-progress: true
11+
12+
jobs:
13+
Build:
14+
runs-on: ubuntu-latest
15+
16+
permissions:
17+
pull-requests: write
18+
contents: write
19+
20+
steps:
21+
- name: Checkout Repo
22+
uses: actions/checkout@v3
23+
24+
- name: Test Build
25+
uses: Lenni009/test-build-vite-action@main

index.html

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,30 @@
44
<head>
55
<meta charset="UTF-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7-
<title>Document</title>
7+
<title>Image Compressor</title>
88
<script type="module" src="src/main.ts"></script>
9+
<style>
10+
h1 {
11+
text-align: center;
12+
}
13+
14+
.container {
15+
margin-block-start: 1rem;
16+
}
17+
</style>
918
</head>
1019

1120
<body>
12-
<h1>Image Compressor</h1>
13-
<h2>Input</h2>
14-
<input type="file">
21+
<div class="container">
22+
<h1>Image Compressor</h1>
23+
<p>Compresses Images to below 10MB</p>
24+
<h2>Input</h2>
25+
<input type="file">
1526

16-
<h2>Output</h2>
17-
<a href="" id="download" download style="display: none;">Download</a>
18-
<p id="status" style="display: none;">Compressing...</p>
27+
<h2>Output</h2>
28+
<a href="" id="download" download style="display: none;">Download</a>
29+
<p id="status" style="display: none;">Compressing...</p>
30+
</div>
1931
</body>
2032

2133
</html>

src/main.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import '@picocss/pico';
12
import { compress, EImageType } from 'image-conversion';
23

34
const input = document.querySelector('input');
@@ -30,10 +31,10 @@ async function compressFile(file: File): Promise<Blob> {
3031
if (file.size < maxSize) return file; // if below 10 MB, don't do anything
3132
const name = file.name;
3233
const res = await compress(file, {
33-
quality, //The compressed image size is 9000kb
34+
quality,
3435
type: EImageType.JPEG,
3536
scale: 1,
36-
}); // NoSonar compress to 9MB
37+
});
3738
quality -= 0.01; // NoSonar reduce quality by 1%;
3839
if (res.size > maxSize) return await compressFile(new File([res], name, { type: 'image/jpeg' }));
3940
quality = 1; // reset quality

0 commit comments

Comments
 (0)