Skip to content

Commit

Permalink
ci: fix gh actions (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminshafii authored Dec 20, 2024
1 parent 283c364 commit 84331d1
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 65 deletions.
27 changes: 1 addition & 26 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1 @@
name: Build Obsidian Plugin

on: push

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "18.x"

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: Install dependencies
run: pnpm install

- name: Build plugin
run: pnpm build

87 changes: 55 additions & 32 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,59 @@
name: Release Obsidian plugin
name: Release Obsidian Plugin

on:
push:
tags:
- "*"
push:
tags:
- "*"

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "18.x"

- name: Build plugin
run: |
npm install
npm run build
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "GH_TOKEN: $GH_TOKEN"
echo "GITHUB_REF: $GITHUB_REF"
tag="${GITHUB_REF#refs/tags/}"
gh release create "$tag" \
--title="$tag" \
main.js manifest.json styles.css
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "18.x"

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: Install dependencies
run: pnpm install

- name: Build plugin
run: pnpm --filter "./packages/plugin" build

- name: Get plugin version
id: version
run: |
version=$(node -p "require('./packages/plugin/manifest.json').version")
echo "version=$version" >> $GITHUB_OUTPUT
- name: Create Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Create a temporary directory for release files
mkdir release
cp packages/plugin/dist/main.js release/
cp packages/plugin/dist/styles.css release/
cp packages/plugin/manifest.json release/
# Create release notes from git log
git log --pretty=format:"- %s" $(git describe --tags --abbrev=0 HEAD^)..HEAD > release/notes.md
# Create the release
gh release create "${{ steps.version.outputs.version }}" \
--title="Version ${{ steps.version.outputs.version }}" \
--notes-file=release/notes.md \
--draft=false \
release/main.js \
release/styles.css \
release/manifest.json
41 changes: 41 additions & 0 deletions packages/plugin/.github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build Obsidian Plugin

on:
push:
paths:
- 'packages/plugin/**'
pull_request:
paths:
- 'packages/plugin/**'

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "18.x"

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: Install dependencies
run: |
cd packages/plugin
pnpm install
- name: Build plugin
run: |
cd packages/plugin
GITHUB_ACTIONS=true pnpm build
- name: Run tests
run: |
cd packages/plugin
pnpm test
59 changes: 59 additions & 0 deletions packages/plugin/.github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Release Obsidian Plugin

on:
push:
tags:
- "test-*"
- "*"
paths:
- 'packages/plugin/**'

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "18.x"

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: Install dependencies
run: |
cd packages/plugin
pnpm install
- name: Build plugin
run: |
cd packages/plugin
GITHUB_ACTIONS=true pnpm build
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd packages/plugin
echo "Creating release for tag ${GITHUB_REF#refs/tags/}"
if [[ ${GITHUB_REF#refs/tags/} == test-* ]]; then
echo "TEST MODE: Would create release with files:"
echo "- dist/main.js"
echo "- manifest.json"
echo "- dist/styles.css"
# Verify files exist
ls -la dist/main.js manifest.json dist/styles.css || true
else
gh release create "${GITHUB_REF#refs/tags/}" \
--title="${GITHUB_REF#refs/tags/}" \
--draft=false \
--prerelease=false \
dist/main.js manifest.json dist/styles.css
fi
7 changes: 7 additions & 0 deletions packages/plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Build output
dist/

# Development output
main.js
styles.css
data.json
File renamed without changes.
15 changes: 10 additions & 5 deletions packages/plugin/esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ if you want to view the source, please visit the github repository of this plugi
`;

const prod = process.argv[2] === "production";
const isGithubAction = process.env.GITHUB_ACTIONS === "true";

// Determine output directory based on environment
const outdir = isGithubAction ? "dist" : "../..";

const context = await esbuild.context({
banner: {
Expand Down Expand Up @@ -42,7 +46,7 @@ const context = await esbuild.context({
logLevel: "info",
sourcemap: prod ? false : "inline",
treeShaking: true,
outdir: "../..", // Output to dist directory instead of root
outdir: outdir,
plugins: [
postcss({
plugins: {
Expand All @@ -53,14 +57,15 @@ const context = await esbuild.context({
extract: true,
}),
],
define: prod ? {
'process.env.NODE_ENV': '"production"'
} : {},
define: {
'process.env.NODE_ENV': prod ? '"production"' : '"development"',
'process.env.GITHUB_ACTIONS': JSON.stringify(process.env.GITHUB_ACTIONS || "false"),
},
loader: {
'.ts': 'ts',
'.wasm': 'binary',
},
tsconfig: "tsconfig.json", // Specify the path to your tsconfig.json
tsconfig: "tsconfig.json",
});

if (prod) {
Expand Down
9 changes: 9 additions & 0 deletions packages/plugin/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "fileorganizer2000",
"name": "AI File Organizer 2000",
"version": "1.132.0",
"minAppVersion": "0.15.0",
"description": "An AI assistant to organize and chat with your vault",
"author": "Benjamin Ashgan Shafii",
"isDesktopOnly": true
}
2 changes: 1 addition & 1 deletion packages/plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@file-organizer/plugin",
"version": "1.131.1",
"version": "1.132.0",
"description": "AI File Organizer 2000",
"main": "main.js",
"scripts": {
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion versions.json → packages/plugin/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -337,5 +337,6 @@
"1.129.3": "0.15.0",
"1.129.4": "0.15.0",
"1.130.0": "0.15.0",
"1.131.1": "0.15.0"
"1.131.1": "0.15.0",
"1.132.0": "0.15.0"
}

0 comments on commit 84331d1

Please sign in to comment.