From c92a073a2f8625101b7fd03135e14973c28b10ad Mon Sep 17 00:00:00 2001 From: froxcey Date: Wed, 27 Dec 2023 09:40:30 +0800 Subject: [PATCH] Fix autoupdate --- .github/actions/zig-update.js | 29 +++++++++++++++++++++-------- .github/workflows/zig-update.yml | 5 +++-- .gitignore | 2 ++ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/.github/actions/zig-update.js b/.github/actions/zig-update.js index 692ee50..344c821 100644 --- a/.github/actions/zig-update.js +++ b/.github/actions/zig-update.js @@ -1,9 +1,9 @@ const https = require("https"); const fs = require("fs"); -const { execSync, exec } = require("child_process"); +const { execSync } = require("child_process"); const { Octokit } = require("@octokit/action"); -const req = https.get("https://ziglang.org/download/index.json", (res) => { +https.get("https://ziglang.org/download/index.json", (res) => { let data = ""; // A chunk of data has been received. @@ -18,7 +18,7 @@ const req = https.get("https://ziglang.org/download/index.json", (res) => { }); }); -function check(data) { +async function check(data) { if (!data.master.version.startsWith("0.12")) { console.error("Zig master is no longer on 0.12, please update"); process.exit(1); @@ -33,7 +33,10 @@ function check(data) { })(); if (localVer == remoteVer) return console.log("Nightly is up to date"); - const branchName = `zig_0.12.${remoteVer}`; + const dateString = new Date() + .toLocaleDateString("en-GB", { day: "numeric", month: "short" }) + .replace(" ", "-") + const branchName = "nightly_update_" + dateString; execSync(`git checkout -b "${branchName}"`); file = file.replace(verMatch, `"${remoteVer}"`); @@ -45,19 +48,29 @@ function check(data) { data.master["aarch64-linux"].shasum, data.master["x86_64-linux"].shasum, ]; - file = file.replace(/sha256 "([a-f]|\d)*"/, () => { + file = file.replace(/sha256 "([a-f]|\d)*"/g, () => { replacementIndex++; return `sha256 "${newSHA[replacementIndex]}"`; }); fs.writeFileSync(path, file); + execSync( + ` git config --global user.name "froxcey"; + git config --global user.email "danichen204@gmail.com"; + git add -A; + git commit -m "[Autoupdate]: Sync zig@0.12 to ${remoteVer}"; + git push -f origin ${branchName};`, + ); + const octokit = new Octokit(); const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/"); - octokit.git.createCommit({ + octokit.pulls.create({ owner, repo, - message: `"[Autoupdate]: Sync zig@0.12 to ${remoteVer}"`, + base: "main", + head: branchName, + title: `Nightly update: ${dateString}`, + body: `- Update Zig@0.12 to ${remoteVer}`, }); - octokit.pulls.create({ owner, repo, base: "main", head: branchName }); } diff --git a/.github/workflows/zig-update.yml b/.github/workflows/zig-update.yml index 33fe549..f98a571 100644 --- a/.github/workflows/zig-update.yml +++ b/.github/workflows/zig-update.yml @@ -1,13 +1,14 @@ -name: Zig nightly update +name: Nightly update on: schedule: - cron: '16 0 * * *' + jobs: update-zig: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v4 with: version: 12 - run: npm install @octokit/action diff --git a/.gitignore b/.gitignore index 9daa824..760b7e8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .DS_Store node_modules +package.json +package-lock.json