Skip to content

Commit fdedafe

Browse files
committed
chore: add automation scripts for automatically updating the repo
1 parent 5cb2c22 commit fdedafe

File tree

7 files changed

+248
-23
lines changed

7 files changed

+248
-23
lines changed

.github/workflows/update_deps.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: check_updates
2+
3+
on:
4+
workflow_dispatch:
5+
# run this monday to thursday
6+
schedule:
7+
- cron: "0 11 * * 1-4"
8+
9+
jobs:
10+
build:
11+
name: check updates
12+
if: github.repository == 'denoland/deno-js-loader'
13+
runs-on: ubuntu-latest
14+
timeout-minutes: 45
15+
16+
steps:
17+
- name: Clone repository
18+
uses: actions/checkout@v4
19+
with:
20+
token: ${{ secrets.DENOBOT_PAT }}
21+
22+
- uses: denoland/setup-deno@v2
23+
24+
- name: Run script
25+
env:
26+
GITHUB_TOKEN: ${{ secrets.DENOBOT_PAT }}
27+
GH_WORKFLOW_ACTOR: ${{ github.actor }}
28+
run: |
29+
git config user.email "denobot@users.noreply.github.com"
30+
git config user.name "denobot"
31+
deno run -A ./scripts/update-deps.ts
32+
deno task wasmbuild
33+
deno test -A
34+
deno run -A ./scripts/commit.ts
35+
36+
# This is necessary to prevent GH automatically dsiabling this workflow after 60 days.
37+
workflow-keepalive:
38+
if: github.event_name == 'schedule'
39+
runs-on: ubuntu-latest
40+
permissions:
41+
actions: write
42+
steps:
43+
- uses: liskin/gh-workflow-keepalive@f72ff1a1336129f29bf0166c0fd0ca6cf1bcb38c

deno.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
"tasks": {
44
"wasmbuild": "cd src/rs_lib && deno run -A jsr:@deno/wasmbuild@0.19.2 --out ../lib"
55
},
6+
"lint": {
7+
"rules": {
8+
"exclude": ["no-explicit-any"]
9+
}
10+
},
611
"publish": {
712
"exclude": [
813
"!./src/lib",
@@ -18,6 +23,8 @@
1823
"tests/jsx/testdata"
1924
],
2025
"imports": {
21-
"@std/assert": "jsr:@std/assert@^1.0.13"
26+
"@david/dax": "jsr:@david/dax@^0.43.2",
27+
"@std/assert": "jsr:@std/assert@^1.0.13",
28+
"@std/toml": "jsr:@std/toml@^1.0.7"
2229
}
2330
}

deno.lock

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

scripts/commit.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import $ from "@david/dax";
2+
3+
const rootDir = $.path(import.meta.dirname!).parentOrThrow();
4+
const denoDir = rootDir.join("deno");
5+
6+
const hasGitChanges = (await $`git status --porcelain`.text()).trim().length > 0;
7+
if (!hasGitChanges) {
8+
$.log("Had no git changes. Exiting.");
9+
Deno.exit(0);
10+
}
11+
12+
const newCommit = (await $`git rev-parse HEAD`.cwd(denoDir).text()).trim();
13+
$.logStep("Updating to", newCommit);
14+
15+
await $`git add .`.cwd(rootDir);
16+
const commitMessage = `chore: bumping to Deno ${newCommit}`;
17+
await $`git commit -m ${commitMessage}`;
18+
await $`git push`;

scripts/update-deps.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env -S deno run -A
2+
import $ from "@david/dax";
3+
import * as toml from "@std/toml";
4+
5+
const rootDir = $.path(import.meta.dirname!).parentOrThrow();
6+
const denoDir = rootDir.join("deno");
7+
8+
const oldCommit = (await $`git rev-parse HEAD`.cwd(denoDir).text()).trim();
9+
$.logLight("Previous commit", oldCommit);
10+
await $`git fetch --depth=1 origin`.cwd(denoDir);
11+
await $`git checkout origin/HEAD`.cwd(denoDir);
12+
const newCommit = (await $`git rev-parse HEAD`.cwd(denoDir).text()).trim();
13+
$.logLight("New commit", newCommit);
14+
15+
const denoCargoTomlPath = denoDir.join("Cargo.toml");
16+
const denoCargoToml = toml.parse(denoCargoTomlPath.readTextSync()) as any;
17+
const denoDependencies = denoCargoToml.workspace.dependencies;
18+
19+
const localCargoTomlPath = rootDir.join("src/rs_lib/Cargo.toml");
20+
const localCargoToml = toml.parse(localCargoTomlPath.readTextSync()) as any;
21+
22+
for (const [key, value] of Object.entries(localCargoToml.dependencies)) {
23+
const newVersion = getVersion(denoDependencies[key]);
24+
if (newVersion == null) {
25+
continue;
26+
}
27+
if (typeof value === "string") {
28+
if (value !== newVersion) {
29+
$.logLight(`Updating ${key}@${value} to ${newVersion}`);
30+
localCargoToml.dependencies[key] = newVersion;
31+
}
32+
} else if (value != null && typeof value === "object" && "version" in value) {
33+
if (value.version !== newVersion) {
34+
$.logLight(`Updating ${key}@${value.version} to ${newVersion}`);
35+
value.version = newVersion;
36+
}
37+
}
38+
}
39+
40+
localCargoTomlPath.writeTextSync(
41+
toml.stringify(localCargoToml)
42+
.trimStart()
43+
.replace(
44+
"[dependencies]",
45+
"# update this by running ./scripts/update-deps.ts\n[dependencies]",
46+
),
47+
);
48+
49+
function getVersion(dep: any): string | undefined {
50+
if (typeof dep === "string") {
51+
return dep;
52+
} else if (dep != null && typeof dep.version === "string") {
53+
return dep.version;
54+
} else {
55+
return undefined;
56+
}
57+
}

src/rs_lib/Cargo.lock

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

src/rs_lib/Cargo.toml

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,60 @@ edition = "2024"
77
crate-type = ["cdylib"]
88
path = "lib.rs"
99

10+
# update this by running ./scripts/update-deps.ts
1011
[dependencies]
11-
anyhow = "1.0.98"
12+
anyhow = "1.0.57"
1213
console_error_panic_hook = "0.1.6"
1314
js-sys = "=0.3.77"
14-
serde = "1"
15+
serde = "1.0.149"
1516
serde-wasm-bindgen = "=0.6.5"
1617
wasm-bindgen = "=0.2.100"
1718
wasm-bindgen-futures = "=0.4.50"
18-
async-trait = "0.1.88"
19-
deno_ast = { version = "0.48.0", features = ["transpiling"] }
20-
deno_cache_dir = { version = "0.22.2", features = ["sync"] }
21-
deno_config = { version = "0.56.0", features = ["workspace", "sync"] }
22-
deno_error = "0.6.1"
23-
deno_graph = { version = "0.95.1", features = ["swc"], default-features = false }
24-
deno_npm_cache = { path = "../../deno/resolvers/npm_cache" }
25-
deno_npm_installer = { path = "../../deno/resolvers/npm_installer", default-features = false }
26-
deno_path_util = "0.4.0"
27-
deno_resolver = { path = "../../deno/resolvers/deno", features = ["deno_ast", "graph", "sync"] }
28-
deno_semver = "0.8.0"
29-
deno_unsync = { version = "0.4.4", default-features = false }
30-
node_resolver = { path = "../../deno/resolvers/node", features = ["sync"] }
31-
sys_traits = { version = "0.1.16", features = ["real", "wasm"] }
32-
url = "2.5.4"
19+
async-trait = "0.1.73"
20+
deno_error = "=0.6.1"
21+
deno_path_util = "=0.4.0"
22+
deno_semver = "=0.8.0"
23+
url = "2.5"
24+
25+
[dependencies.deno_ast]
26+
version = "=0.48.0"
27+
features = ["transpiling"]
28+
29+
[dependencies.deno_cache_dir]
30+
version = "=0.22.2"
31+
features = ["sync"]
32+
33+
[dependencies.deno_config]
34+
version = "=0.56.0"
35+
features = ["workspace","sync"]
36+
37+
[dependencies.deno_graph]
38+
version = "=0.95.1"
39+
features = ["swc"]
40+
default-features = false
41+
42+
[dependencies.deno_npm_cache]
43+
path = "../../deno/resolvers/npm_cache"
44+
45+
[dependencies.deno_npm_installer]
46+
path = "../../deno/resolvers/npm_installer"
47+
default-features = false
48+
49+
[dependencies.deno_resolver]
50+
path = "../../deno/resolvers/deno"
51+
features = ["deno_ast","graph","sync"]
52+
53+
[dependencies.deno_unsync]
54+
version = "0.4.4"
55+
default-features = false
56+
57+
[dependencies.node_resolver]
58+
path = "../../deno/resolvers/node"
59+
features = ["sync"]
60+
61+
[dependencies.sys_traits]
62+
version = "=0.1.16"
63+
features = ["real","wasm"]
3364

3465
[profile.release]
3566
codegen-units = 1

0 commit comments

Comments
 (0)