Skip to content

Commit

Permalink
Fix autoupdate
Browse files Browse the repository at this point in the history
  • Loading branch information
Froxcey committed Dec 29, 2023
1 parent e783f91 commit c92a073
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
29 changes: 21 additions & 8 deletions .github/actions/zig-update.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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);
Expand All @@ -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}"`);
Expand All @@ -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 "[email protected]";
git add -A;
git commit -m "[Autoupdate]: Sync [email protected] 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 [email protected] to ${remoteVer}"`,
base: "main",
head: branchName,
title: `Nightly update: ${dateString}`,
body: `- Update [email protected] to ${remoteVer}`,
});
octokit.pulls.create({ owner, repo, base: "main", head: branchName });
}
5 changes: 3 additions & 2 deletions .github/workflows/zig-update.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.DS_Store
node_modules
package.json
package-lock.json

0 comments on commit c92a073

Please sign in to comment.