Skip to content

Commit fa81dea

Browse files
authored
chore: add action to bump OPENCLAW_GIT_REF (vignesh07#78)
1 parent ef609b7 commit fa81dea

2 files changed

Lines changed: 97 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Bump OpenClaw release ref
2+
3+
on:
4+
schedule:
5+
- cron: "23 9 * * *" # daily 09:23 UTC
6+
workflow_dispatch: {}
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
bump:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Node
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: 22
23+
24+
- name: Bump Dockerfile OPENCLAW_GIT_REF if needed
25+
run: node scripts/bump-openclaw-ref.mjs
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Create PR
30+
uses: peter-evans/create-pull-request@v6
31+
with:
32+
token: ${{ secrets.GITHUB_TOKEN }}
33+
commit-message: "chore: bump OPENCLAW_GIT_REF to latest release"
34+
title: "chore: bump OPENCLAW_GIT_REF to latest OpenClaw release"
35+
body: |
36+
Automated update of the default OpenClaw build ref (`OPENCLAW_GIT_REF`) to the latest upstream release tag.
37+
38+
This keeps the Railway template stable-by-default while staying current.
39+
branch: chore/bump-openclaw-ref
40+
delete-branch: true
41+
labels: |
42+
automated
43+
dependencies

scripts/bump-openclaw-ref.mjs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import fs from "node:fs";
2+
3+
const owner = "openclaw";
4+
const repo = "openclaw";
5+
const token = process.env.GITHUB_TOKEN;
6+
if (!token) {
7+
console.error("Missing GITHUB_TOKEN");
8+
process.exit(2);
9+
}
10+
11+
async function gh(path) {
12+
const url = `https://api.github.com${path}`;
13+
const res = await fetch(url, {
14+
headers: {
15+
authorization: `Bearer ${token}`,
16+
accept: "application/vnd.github+json",
17+
"user-agent": "clawdbot-railway-template-bot",
18+
},
19+
});
20+
if (!res.ok) {
21+
throw new Error(`GitHub API ${res.status}: ${await res.text()}`);
22+
}
23+
return res.json();
24+
}
25+
26+
function readCurrentTag(dockerfile) {
27+
const m = dockerfile.match(/\nARG OPENCLAW_GIT_REF=([^\n]+)\n/);
28+
return m ? m[1].trim() : null;
29+
}
30+
31+
function replaceTag(dockerfile, next) {
32+
const re = /\nARG OPENCLAW_GIT_REF=([^\n]+)\n/;
33+
if (!re.test(dockerfile)) throw new Error("Could not find OPENCLAW_GIT_REF line");
34+
return dockerfile.replace(re, `\nARG OPENCLAW_GIT_REF=${next}\n`);
35+
}
36+
37+
const latest = await gh(`/repos/${owner}/${repo}/releases/latest`);
38+
const latestTag = latest.tag_name;
39+
if (!latestTag) throw new Error("No tag_name in latest release response");
40+
41+
const dockerPath = "Dockerfile";
42+
const docker = fs.readFileSync(dockerPath, "utf8");
43+
const currentTag = readCurrentTag(docker);
44+
if (!currentTag) throw new Error("Could not parse current OPENCLAW_GIT_REF");
45+
46+
console.log(`current=${currentTag} latest=${latestTag}`);
47+
48+
if (currentTag === latestTag) {
49+
console.log("No update needed.");
50+
process.exit(0);
51+
}
52+
53+
fs.writeFileSync(dockerPath, replaceTag(docker, latestTag));
54+
console.log(`Updated ${dockerPath} to ${latestTag}`);

0 commit comments

Comments
 (0)