Skip to content

Commit dfe2ef1

Browse files
ci: switch user script updates from manual to GitHub Actions (#230)
1 parent bdf7aa9 commit dfe2ef1

File tree

3 files changed

+61
-14
lines changed

3 files changed

+61
-14
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Update userscripts
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
update-userscripts:
9+
runs-on: ubuntu-latest
10+
11+
strategy:
12+
matrix:
13+
node-version: [22.x]
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Use Node.js ${{ matrix.node-version }}
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: ${{ matrix.node-version }}
22+
23+
- run: npm ci
24+
25+
- run: npm run ci:build
26+
27+
- uses: peter-evans/create-pull-request@v7
28+
with:
29+
commit-message: "ci: update userscripts"
30+
delete-branch: true
31+
title: "ci: update userscripts"
32+
base: main
33+
body: |
34+
This PR was automatically generated to update the userscripts. It contains the latest changes from the main branch, and should be merged when the new release is ready.
35+
branch: update-userscripts
36+
reviewers: Robot-Inventor

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"scripts": {
88
"build": "cross-env NODE_OPTIONS=--experimental-transform-types NODE_ENV=production rspack build",
99
"watch": "cross-env NODE_OPTIONS=--experimental-transform-types NODE_ENV=development rspack build --watch",
10+
"ci:build": "cross-env NODE_OPTIONS=--experimental-transform-types NODE_ENV=production rspack build --env updateUserScripts",
1011
"format": "prettier --write ./src/**/*",
1112
"format:check": "prettier --check ./src/**/*",
1213
"lint": "eslint ./src/**/*.ts ./rspack.config.ts ./script/**/*.ts",

rspack.config.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import { exec } from "child_process";
44
import { watch } from "chokidar";
55

66
class RunCommandsPlugin {
7+
private readonly env: Record<string, unknown>;
8+
9+
public constructor(env: Record<string, unknown>) {
10+
this.env = env;
11+
}
12+
713
private static copyManifest(callback?: () => void): void {
814
exec("npx tsx ./script/copyManifest.ts", (err, stdout) => {
915
// eslint-disable-next-line no-console
@@ -23,7 +29,6 @@ class RunCommandsPlugin {
2329
});
2430
}
2531

26-
// eslint-disable-next-line class-methods-use-this
2732
public apply(compiler: Compiler): void {
2833
let isWatchMode = false;
2934
let isFirstRun = true;
@@ -56,29 +61,34 @@ class RunCommandsPlugin {
5661

5762
isFirstRun = false;
5863

59-
exec("npx tsx ./script/addUserScriptComment.ts", (err, stdout) => {
60-
if (err) {
61-
// eslint-disable-next-line no-console
62-
console.error(`Error: ${err.message}`);
63-
} else {
64-
// eslint-disable-next-line no-console
65-
console.log(stdout);
66-
}
64+
if (this.env.updateUserScripts) {
65+
exec("npx tsx ./script/addUserScriptComment.ts", (err, stdout) => {
66+
if (err) {
67+
// eslint-disable-next-line no-console
68+
console.error(`Error: ${err.message}`);
69+
} else {
70+
// eslint-disable-next-line no-console
71+
console.log(stdout);
72+
}
73+
callback();
74+
});
75+
} else {
6776
callback();
68-
});
77+
}
6978
});
7079
}
7180
}
7281

7382
const isProduction = process.env.NODE_ENV === "production";
7483
/* eslint-disable sort-keys */
75-
const config = defineConfig({
84+
// eslint-disable-next-line max-lines-per-function
85+
const config = defineConfig((env) => ({
7686
mode: isProduction ? "production" : "development",
7787
devtool: isProduction ? false : "source-map",
7888
entry: {
7989
"./chrome/js/index.js": "./src/ts/index.ts",
8090
"./firefox/js/index.js": "./src/ts/index.ts",
81-
"../index.user.js": "./src/ts/index.ts"
91+
...(env.updateUserScripts ? { "../index.user.js": "./src/ts/index.ts" } : {})
8292
},
8393
output: {
8494
filename: "[name]",
@@ -105,7 +115,7 @@ const config = defineConfig({
105115
extensions: [".ts", ".js"]
106116
},
107117
plugins: [
108-
new RunCommandsPlugin(),
118+
new RunCommandsPlugin(env),
109119
new CopyRspackPlugin({
110120
patterns: [
111121
{
@@ -131,7 +141,7 @@ const config = defineConfig({
131141
]
132142
})
133143
]
134-
});
144+
}));
135145
/* eslint-enable sort-keys */
136146

137147
export default config;

0 commit comments

Comments
 (0)