Skip to content

Commit

Permalink
chore: better workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
nekomeowww committed Nov 25, 2024
1 parent 8758c4d commit f77316b
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 6 deletions.
42 changes: 40 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
name: Lint
permissions:
pull-requests: write
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -50,11 +50,49 @@ jobs:
- name: Lint
run: pnpm run lint

typecheck:
name: Type Check
permissions:
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Node.js 22.x
uses: actions/setup-node@v3
with:
node-version: 22.x

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
run_install: false

- name: Obtain pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Obtain pnpm store cache
uses: actions/cache@v4
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Type Check
run: pnpm run typecheck

build-test:
name: Build Test
permissions:
pull-requests: write
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
11 changes: 11 additions & 0 deletions build.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { copyFile, rm } from 'node:fs/promises'
import { join } from 'node:path'

import { cwd } from 'node:process'
import builtins from 'builtin-modules'
import { defineBuildConfig } from 'unbuild'

import { generateObsidianPluginManifest } from './scripts/manifest'
import { toErrorable } from './scripts/utils'

export default defineBuildConfig({
outDir: './dist',
Expand Down Expand Up @@ -47,8 +52,14 @@ export default defineBuildConfig({
inlineDependencies: true,
},
hooks: {
'build:before': async () => {
await toErrorable(async () => await rm(join(cwd(), 'main.js')))
await toErrorable(async () => await rm(join(cwd(), 'manifest.json')))
},
'build:done': async () => {
await generateObsidianPluginManifest()
await copyFile(join(cwd(), 'dist', 'main.js'), join(cwd(), 'main.js'))
await copyFile(join(cwd(), 'dist', 'manifest.json'), join(cwd(), 'manifest.json'))
},
},
})
1 change: 1 addition & 0 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ words:
- collab
- easytag
- emittypes
- Errorable
- iconify
- lezer
- Logseq
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@
"dist"
],
"scripts": {
"cleanup": "rm -rf ./main.js && rm -rf ./main.js.map",
"build": "unbuild && pnpm run cleanup && pnpm run copy",
"copy": "cp ./dist/main.js ./main.js && cp ./dist/manifest.json ./manifest.json",
"build": "unbuild",
"lint": "eslint --cache .",
"lint:fix": "eslint --cache --fix ."
"lint:fix": "eslint --cache --fix .",
"typecheck": "tsc --noEmit"
},
"devDependencies": {
"@antfu/eslint-config": "^3.9.2",
Expand Down
8 changes: 8 additions & 0 deletions scripts/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export async function toErrorable<P, R>(fn: (...args: P[]) => Promise<R>): Promise<R | undefined> {
try {
return await fn()
}
catch {
return undefined
}
}

0 comments on commit f77316b

Please sign in to comment.