Skip to content

Commit ee8301c

Browse files
release build automation
1 parent 3160831 commit ee8301c

File tree

6 files changed

+188
-80
lines changed

6 files changed

+188
-80
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": "1.1.4",
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: 2 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: 4 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": [],
@@ -44,4 +43,4 @@
4443
"webpack-cli": "^5.1.4",
4544
"webpack-preprocessor-loader": "^1.3.0"
4645
}
47-
}
46+
}

webpack.config.js

Lines changed: 102 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,116 @@
11
const path = require("path");
22
const webpack = require("webpack");
3+
const fs = require('fs');
4+
5+
class UpdateAndCopyManifestPlugin {
6+
apply(compiler) {
7+
compiler.hooks.afterEmit.tap('UpdateAndCopyManifestPlugin', (compilation) => {
8+
const packageJsonPath = path.resolve(__dirname, 'package.json');
9+
const manifestJsonPath = path.resolve(__dirname, 'manifest.json');
10+
const outputDir = path.resolve(__dirname, 'dist', 'circuit-sketcher');
11+
12+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
13+
const version = packageJson.version;
14+
15+
const manifestJson = JSON.parse(fs.readFileSync(manifestJsonPath, 'utf8'));
16+
manifestJson.version = version;
17+
18+
fs.writeFileSync(manifestJsonPath, JSON.stringify(manifestJson, null, 4), 'utf8');
19+
20+
console.log('Updated manifest.json with version:', version);
21+
22+
if (!fs.existsSync(outputDir)) {
23+
fs.mkdirSync(outputDir, { recursive: true });
24+
}
25+
26+
const outputManifestPath = path.join(outputDir, 'manifest.json');
27+
fs.copyFileSync(manifestJsonPath, outputManifestPath);
28+
29+
console.log('Copied manifest.json to:', outputManifestPath);
30+
});
31+
}
32+
}
333

434
const postcssLoader = {
5-
loader: "postcss-loader",
6-
options: {
7-
postcssOptions: {
8-
plugins: [
9-
require("postcss-url")({
10-
url: "inline",
11-
maxSize: Infinity,
12-
}),
13-
],
35+
loader: "postcss-loader",
36+
options: {
37+
postcssOptions: {
38+
plugins: [
39+
require("postcss-url")({
40+
url: "inline",
41+
maxSize: Infinity,
42+
}),
43+
],
44+
},
1445
},
15-
},
1646
};
1747

1848
const ENVIRONMENT = "production";
1949

2050
module.exports = {
21-
entry: "./src/main.ts",
22-
module: {
23-
rules: [
24-
{
25-
test: /\.tsx?$/,
26-
use: [
27-
{
28-
loader: "ts-loader",
29-
},
30-
{
31-
loader: "webpack-preprocessor-loader",
32-
options: {
33-
params: {
34-
dev: ENVIRONMENT === "development", // for preprocessor commands defined with `#!if dev` and `#!endif` (multiple lines)
35-
},
36-
directives: {
37-
dev: ENVIRONMENT === "development", // for preprocessor command `#!dev` (single line)
38-
},
51+
entry: "./src/main.ts",
52+
module: {
53+
rules: [
54+
{
55+
test: /\.tsx?$/,
56+
use: [
57+
{
58+
loader: "ts-loader",
59+
},
60+
{
61+
loader: "webpack-preprocessor-loader",
62+
options: {
63+
params: {
64+
dev: ENVIRONMENT === "development", // for preprocessor commands defined with `#!if dev` and `#!endif` (multiple lines)
65+
},
66+
directives: {
67+
dev: ENVIRONMENT === "development", // for preprocessor command `#!dev` (single line)
68+
},
69+
},
70+
},
71+
],
72+
exclude: /node_modules/,
73+
},
74+
{
75+
test: /\.css$/,
76+
use: ["style-loader", "css-loader", postcssLoader],
77+
exclude: /node_modules/,
78+
},
79+
{
80+
test: /\.scss$/,
81+
use: ["style-loader", "css-loader", "sass-loader", postcssLoader],
82+
exclude: /node_modules/,
83+
},
84+
{
85+
test: /\.svg$/,
86+
use: "raw-loader",
87+
exclude: /node_modules/,
3988
},
40-
},
4189
],
42-
exclude: /node_modules/,
43-
},
44-
{
45-
test: /\.css$/,
46-
use: ["style-loader", "css-loader", postcssLoader],
47-
exclude: /node_modules/,
48-
},
49-
{
50-
test: /\.scss$/,
51-
use: ["style-loader", "css-loader", "sass-loader", postcssLoader],
52-
exclude: /node_modules/,
53-
},
54-
{
55-
test: /\.svg$/,
56-
use: "raw-loader",
57-
exclude: /node_modules/,
58-
},
59-
],
60-
},
61-
resolve: {
62-
extensions: [".ts", ".tsx", ".js"],
63-
alias: {
64-
react: path.resolve(__dirname, "node_modules/react"),
65-
"react-dom": path.resolve(__dirname, "node_modules/react-dom"),
6690
},
67-
},
68-
output: {
69-
filename: "main.js",
70-
path: path.resolve(__dirname, "dist/circuit-sketcher"),
71-
libraryTarget: "commonjs",
72-
},
73-
target: "node",
74-
//devtool: "inline-source-map",
75-
externals: {
76-
obsidian: "commonjs obsidian",
77-
},
78-
mode: ENVIRONMENT,
79-
plugins: [
80-
new webpack.BannerPlugin({
81-
banner: `/*! Also see LICENSE file in the root of the project. */`,
82-
raw: true,
83-
}),
84-
],
91+
resolve: {
92+
extensions: [".ts", ".tsx", ".js"],
93+
alias: {
94+
react: path.resolve(__dirname, "node_modules/react"),
95+
"react-dom": path.resolve(__dirname, "node_modules/react-dom"),
96+
},
97+
},
98+
output: {
99+
filename: "main.js",
100+
path: path.resolve(__dirname, "dist/circuit-sketcher"),
101+
libraryTarget: "commonjs",
102+
},
103+
target: "node",
104+
//devtool: "inline-source-map",
105+
externals: {
106+
obsidian: "commonjs obsidian",
107+
},
108+
mode: ENVIRONMENT,
109+
plugins: [
110+
new webpack.BannerPlugin({
111+
banner: `/*! Also see LICENSE file in the root of the project. */`,
112+
raw: true,
113+
}),
114+
new UpdateAndCopyManifestPlugin(),
115+
],
85116
};

0 commit comments

Comments
 (0)