Skip to content

Commit

Permalink
feat: Setup CI/CD Pipeline, Linters, and Development Environment
Browse files Browse the repository at this point in the history
  • Loading branch information
antonko committed Mar 14, 2024
1 parent b7137f4 commit dbce910
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Auto detect text files and perform LF normalization
* text=auto
* text=lf
*.js linguist-detect=false
30 changes: 30 additions & 0 deletions .github/workflows/commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Code Check on Push

on:
push:
branches-ignore:
- main

jobs:
lint-and-build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Install dependencies
run: npm install
working-directory: ./blurhasher

- name: Run linter
run: npm run lint
working-directory: ./blurhasher

- name: Build
run: npm run build
working-directory: ./blurhasher
29 changes: 29 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Pull Request Check

on:
pull_request:
branches: [main]

jobs:
lint-and-build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Install dependencies
run: npm install
working-directory: ./blurhasher

- name: Run linter
run: npm run lint
working-directory: ./blurhasher

- name: Build
run: npm run build
working-directory: ./blurhasher
62 changes: 49 additions & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,19 @@ name: Release CI/CD

on:
push:
branches: [semver-ci-cd]
pull_request:
branches: [semver-ci-cd]
branches: [main]

jobs:
permissions:
contents: write

build-and-release:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: "20"
registry-url: "https://registry.npmjs.org/"

- name: Change to project directory
run: cd blurhasher

- name: Install dependencies
run: npm install
Expand All @@ -33,10 +24,55 @@ jobs:
run: npm run lint
working-directory: ./blurhasher

build:
needs: lint
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Install dependencies
run: npm install
working-directory: ./blurhasher

- name: Build
run: npm run build
working-directory: ./blurhasher

- name: Archive built files
run: tar -czvf build.tar.gz -C ./blurhasher dist package.json package-lock.json

- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: built-files
path: build.tar.gz

semantic-release:
needs: build
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: built-files
path: ./blurhasher

- name: Semantic Release
run: npx semantic-release
working-directory: ./blurhasher
Expand Down
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
"recommendations": ["dbaeumer.vscode-eslint"]
}
5 changes: 2 additions & 3 deletions blurhasher/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "directus-extension-blurhasher",
"description": "Please enter a description for your extension",
"description": "A Directus extension for generating and storing BlurHash strings, enhancing image loading visuals.",
"icon": "extension",
"version": "0.1.0",
"author": "Anton Kovalev <antonko@gmail.com>",
Expand All @@ -23,12 +23,11 @@
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/npm",
[
"@semantic-release/github",
{
"assets": [
"./dist/**"
{"path": "build.tar.gz", "label": "Built Files"}
],
"releasedLabels": "released"
}
Expand Down
4 changes: 2 additions & 2 deletions blurhasher/src/blurhash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const streamToBuffer = async (stream: Readable): Promise<Buffer> => {
};

export const generateBlurHashFromStream = async (
stream: Readable
stream: Readable,
): Promise<string | null> => {
try {
const buffer = await streamToBuffer(stream);
Expand All @@ -26,7 +26,7 @@ export const generateBlurHashFromStream = async (
info.width,
info.height,
4,
4
4,
);
return blurHash;
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions blurhasher/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default defineHook(
action("files.upload", async ({ payload, key }, context) => {
if (
!["image/jpeg", "image/png", "image/webp", "image/tiff"].includes(
payload.type
payload.type,
)
) {
logger.info("[blurhasher]: The file is not a image - skipped");
Expand All @@ -40,5 +40,5 @@ export default defineHook(
itemService.updateOne(key, { blurhash: blurHash });
});
});
}
},
);

0 comments on commit dbce910

Please sign in to comment.