Skip to content

Commit 2ffe314

Browse files
release build automation
1 parent 3160831 commit 2ffe314

File tree

6 files changed

+250
-9
lines changed

6 files changed

+250
-9
lines changed

.github/workflows/main.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- "src/**"
8+
- "webpack.config.js"
9+
- "package.json"
10+
- ".github/workflows/**"
11+
pull_request:
12+
paths:
13+
- "src/**"
14+
- "webpack.config.js"
15+
- "package.json"
16+
- ".github/workflows/**"
17+
18+
permissions:
19+
contents: write
20+
21+
jobs:
22+
build:
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
# Step 1: Checkout the code
27+
- name: Checkout code
28+
uses: actions/checkout@v3
29+
30+
# Step 2: Set up Node.js using .nvmrc
31+
- name: Set up Node.js
32+
uses: actions/setup-node@v3
33+
with:
34+
node-version-file: .nvmrc
35+
36+
# Step 3: Install dependencies
37+
- name: Install dependencies
38+
run: npm install
39+
40+
# Step 4: Build the project
41+
- name: Build project
42+
run: npm run build
43+
44+
# Step 4.5: Extract version from package.json
45+
- name: Get Package Version
46+
id: pkg_version
47+
run: |
48+
VERSION=$(jq -r '.version' package.json)
49+
echo "VERSION=$VERSION" >> $GITHUB_ENV
50+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
51+
52+
# Step 5: Create a GitHub Release
53+
- name: Create Release
54+
id: create_release
55+
uses: actions/create-release@v1
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
with:
59+
tag_name: ${{ steps.pkg_version.outputs.VERSION }}
60+
release_name: Release ${{ steps.pkg_version.outputs.VERSION }}
61+
draft: false
62+
prerelease: false
63+
64+
# Step 6: Upload each as a release asset
65+
- name: Upload Release Assets
66+
env:
67+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68+
run: |
69+
UPLOAD_URL="${{ steps.create_release.outputs.upload_url }}"
70+
UPLOAD_URL="${UPLOAD_URL%\{*}"
71+
72+
for file in dist/circuit-sketcher/*; do
73+
curl -X POST \
74+
-H "Authorization: token $GITHUB_TOKEN" \
75+
-H "Content-Type: $(file -b --mime-type "$file")" \
76+
--data-binary @"$file" \
77+
"$UPLOAD_URL?name=$(basename "$file")"
78+
done

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v23.3.0
1+
v24.0.0

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "circuit-sketcher",
33
"name": "Circuit Sketcher",
4-
"version": "1.1.3",
4+
"version": "TBD",
55
"minAppVersion": "0.15.0",
66
"description": "Draw circuits on a canvas using circuit-sketcher-core.",
77
"author": "Code Forge Temple",

package-lock.json

Lines changed: 139 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
{
22
"name": "circuit-sketcher-obsidian-plugin",
3-
"version": "1.1.3",
3+
"version": "1.1.4",
44
"main": "main.js",
55
"author": "Code Forge Temple",
66
"license": "GPL",
77
"description": "A plugin for Obsidian to draw circuits on a canvas, based on circuit-sketcher-core.",
88
"scripts": {
9-
"copy:manifest": "cpx ./manifest.json ./dist/circuit-sketcher/",
10-
"copy": "npm run copy:manifest",
11-
"build": "webpack --stats-error-details && npm run copy",
9+
"typecheck": "tsc --noEmit",
10+
"build": "npm run lint && npm run typecheck && webpack --stats-error-details",
1211
"lint": "eslint ."
1312
},
1413
"keywords": [],
@@ -19,6 +18,7 @@
1918
"react-dom": "^19.0.0"
2019
},
2120
"devDependencies": {
21+
"copy-webpack-plugin": "^13.0.0",
2222
"@eslint/js": "^9.17.0",
2323
"@types/react": "^19.0.2",
2424
"@types/react-dom": "^19.0.2",
@@ -44,4 +44,4 @@
4444
"webpack-cli": "^5.1.4",
4545
"webpack-preprocessor-loader": "^1.3.0"
4646
}
47-
}
47+
}

webpack.config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const path = require("path");
22
const webpack = require("webpack");
3+
const CopyWebpackPlugin = require("copy-webpack-plugin");
4+
const fs = require("fs").promises;
35

46
const postcssLoader = {
57
loader: "postcss-loader",
@@ -81,5 +83,29 @@ module.exports = {
8183
banner: `/*! Also see LICENSE file in the root of the project. */`,
8284
raw: true,
8385
}),
86+
new CopyWebpackPlugin({
87+
patterns: [
88+
{
89+
from: path.resolve("./manifest.json"),
90+
to: "manifest.json",
91+
transform: async (content) => {
92+
try {
93+
const pkgPath = path.resolve("package.json");
94+
const pkgData = await fs.readFile(pkgPath, "utf8");
95+
const pkg = JSON.parse(pkgData);
96+
const manifest = JSON.parse(content.toString());
97+
98+
manifest.version = pkg.version;
99+
100+
return JSON.stringify(manifest, null, 4);
101+
} catch (error) {
102+
console.error("Error updating manifest.json:", error);
103+
104+
return content;
105+
}
106+
},
107+
},
108+
],
109+
}),
84110
],
85111
};

0 commit comments

Comments
 (0)