Skip to content

Commit

Permalink
chore: add linter to plugin build workflow
Browse files Browse the repository at this point in the history
This update includes the following changes:
- Add eslint to the workflow
- Refactor workflow to add linter as a blocking check before compiling plugin code
- Add workflow step with cached node dependencies to speed up the build process
  • Loading branch information
bandantonio committed Mar 1, 2024
1 parent cae7cca commit d8237dc
Show file tree
Hide file tree
Showing 9 changed files with 314 additions and 350 deletions.
4 changes: 2 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
"sourceType": "module"
},
"rules": {
"no-unused-vars": "off",
"no-unused-vars": "warn",
"@typescript-eslint/no-unused-vars": ["error", { "args": "none" }],
"@typescript-eslint/ban-ts-comment": "off",
"no-prototype-builtins": "off",
"no-prototype-builtins": "warn",
"@typescript-eslint/no-empty-function": "off"
}
}
27 changes: 27 additions & 0 deletions .github/actions/node-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: 'Node setup and cache'
description: 'Setup Node.js packages and restore cache'

inputs:
node-version:
description: 'Node version to use, default to 20'
required: true
default: '20'
outputs:
cache-hit:
description: 'Forward actions/cache cache-hit output'
value: ${{ steps.node-cache.outputs.cache-hit }}

runs:
using: 'composite'
steps:
- name: ⚙️ Setup node.js ${{ inputs.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}

- name: 📦 Cache node modules
id: node-cache
uses: actions/cache@v4
with:
path: node_modules
key: node-modules-${{ inputs.node-version }}-${{ hashFiles('package-lock.json') }}
68 changes: 48 additions & 20 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,62 @@
name: Release Obsidian plugin

on:
push:
tags:
- "*"
name: Release Obsidian Plugin
on: [push]

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

jobs:
build:
node-setup:
name: ⚙️ Setup Node.js
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ./.github/actions/node-cache
id: cache-node-modules
with:
node-version: '20'
- run: npm i
if: steps.cache-node-modules.outputs.cache-hit != 'true'

- name: Use Node.js
uses: actions/setup-node@v3
run-lint:
name: ✅ Linter
needs: node-setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/node-cache
id: cache-node-modules
with:
node-version: "18.x"
node-version: '20'

- name: Build plugin
run: |
npm install
npm run build
- name: ✅ Run code style linter
id: linter
run: npm run lint

release-plugin:
name: 📦 Release Obsidian Plugin
needs: run-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/node-cache
id: cache-node-modules
with:
node-version: '20'

- name: 📗 Build plugin
id: build_plugin
if: steps.cache-node-modules.outcome == 'success'
run: npm run build

- name: Create release
- name: 📦 Create release
if: steps.build_plugin.outcome == 'success' && contains(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
tag="${GITHUB_REF#refs/tags/}"
tag='${GITHUB_REF#refs/tags/}'
gh release create "$tag" \
--title="$tag" \
gh release create '$tag' \
--title='$tag' \
--draft \
main.js manifest.json styles.css
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Import all your Apple Books highlights to Obsidian.

![GitHub Downloads](https://img.shields.io/github/downloads/bandantonio/obsidian-apple-books-highlights-plugin/total?style=for-the-badge&logo=github&color=573e7a)


## Overview

This plugin aims to be a **fast**, **customizable**, **reliable**, and **up-to-date** solution to import your Apple Books highlights to Obsidian:
Expand Down
6 changes: 4 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class IBookHighlightsPlugin extends Plugin {
settings: IBookHighlightsPluginSettings;

async onload() {
let settings = await this.loadSettings();
const settings = await this.loadSettings();

if (settings.importOnStart) {
await this.importAndSaveHighlights();
Expand Down Expand Up @@ -50,6 +50,7 @@ export default class IBookHighlightsPlugin extends Plugin {
});
}

//eslint-disable-next-line
onunload() { }

async loadSettings() {
Expand Down Expand Up @@ -110,7 +111,8 @@ export default class IBookHighlightsPlugin extends Plugin {
if (bookRelatedAnnotations.length > 0) {
// Obsidian forbids adding certain characters to the title of a note, so they must be replaced with a dash (-)
// | # ^ [] \ / :
const normalizedBookTitle = book.ZTITLE.replace(/[|#\^\[\]\\\/:]+/g, ' -');
//eslint-disable-next-line
const normalizedBookTitle = book.ZTITLE.replace(/[\|\#\^\[\]\\\/\:]+/g, ' -');

highlights.push({
bookTitle: normalizedBookTitle,
Expand Down
Loading

0 comments on commit d8237dc

Please sign in to comment.