Skip to content

Commit b64121c

Browse files
authored
Merge pull request #7 from unyt-org/dev
Dev branch
2 parents 64e6f52 + 136d2e9 commit b64121c

22 files changed

+1329
-1262
lines changed

.cargo/.gitkeep

Whitespace-only changes.

.github/tools/create-release.ts

100644100755
File mode changed.

.github/tools/get-nightly-ref.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env -S deno run --allow-env=GITHUB_TOKEN,GITHUB_REPOSITORY,GITHUB_OUTPUT --allow-write --allow-net=api.github.com
2+
import { Octokit } from "https://esm.sh/[email protected]?dts";
3+
const token = Deno.env.get("GITHUB_TOKEN");
4+
if (!token) {
5+
console.error("GITHUB_TOKEN not set");
6+
Deno.exit(1);
7+
}
8+
const repoFull = Deno.env.get("GITHUB_REPOSITORY");
9+
if (!repoFull) {
10+
console.error("GITHUB_REPOSITORY not set");
11+
Deno.exit(1);
12+
}
13+
const [owner, repo] = repoFull.split("/");
14+
const octokit = new Octokit({ auth: token });
15+
16+
const { data: pulls } = await octokit.request(
17+
"GET /repos/{owner}/{repo}/pulls",
18+
{ owner, repo, state: "open", per_page: 100 },
19+
);
20+
21+
// newest‑updated PR with label "nightly"
22+
const nightly = pulls
23+
.filter((pr) => pr.labels.some((l) => l.name === "nightly"))
24+
.sort((a, b) => Date.parse(b.updated_at) - Date.parse(a.updated_at))[0];
25+
26+
if (!nightly) {
27+
console.log("::warning::No open PR with label 'nightly' found.");
28+
Deno.exit(1);
29+
}
30+
31+
console.log(
32+
`Found open PR #${nightly.number} with label 'nightly': ${nightly.html_url}`,
33+
);
34+
35+
const outPath = Deno.env.get("GITHUB_OUTPUT");
36+
if (outPath) {
37+
await Deno.writeTextFile(outPath, `ref=${nightly.head.sha}\n`, {
38+
append: true,
39+
});
40+
}
41+
Deno.exit(0);

.github/tools/install-codesign.ts

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env -S deno run -A
2+
import { Octokit } from "https://esm.sh/[email protected]?dts";
3+
// --allow-env=GITHUB_TOKEN --allow-write --allow-net
4+
const token = Deno.env.get("GITHUB_TOKEN");
5+
if (!token) {
6+
console.error("GITHUB_TOKEN not set");
7+
Deno.exit(1);
8+
}
9+
10+
const [owner, repo] = "indygreg/apple-platform-rs".split("/");
11+
const octokit = new Octokit({ auth: token });
12+
13+
const getTag = async (version: string) => {
14+
if (version === "latest") {
15+
const latestRelease = await octokit.request("GET /repos/{owner}/{repo}/releases/latest", {
16+
owner,
17+
repo,
18+
});
19+
if (!latestRelease.data.tag_name)
20+
throw new Error("No tag name found in latest release");
21+
return latestRelease.data.tag_name;
22+
}
23+
return `apple-codesign/${version}`;
24+
}
25+
const getArtifactName = (version: string) => {
26+
const prefix = `apple-codesign-${version}-${Deno.build.arch}-`;
27+
const platform = Deno.build.os;
28+
if (platform === "darwin") {
29+
return `${prefix}apple-${platform}.tar.gz`;
30+
} else if (platform === "linux") {
31+
return `${prefix}unknown-linux-musl.tar.gz`;
32+
} else if (platform === "windows") {
33+
return `${prefix}pc-windows-msvc.zip`;
34+
} else {
35+
throw new Error(`Unsupported platform: ${platform}`);
36+
}
37+
}
38+
39+
const version = Deno.args[0] || "latest";
40+
const tag = await getTag(version);
41+
42+
const release = await octokit.request(
43+
"GET /repos/{owner}/{repo}/releases/tags/{tag}",
44+
{
45+
owner,
46+
repo,
47+
tag,
48+
}
49+
);
50+
console.info(`Found release: ${tag} (${release.data.id})`);
51+
52+
if (!release.data.assets || release.data.assets.length === 0) {
53+
console.error("No assets found in release");
54+
Deno.exit(1);
55+
}
56+
const artifactName = getArtifactName(tag.replace("apple-codesign/", ""));
57+
const asset = release.data.assets.find(
58+
(a) => a.name === artifactName
59+
);
60+
if (!asset) {
61+
console.error(`No asset found with name ${artifactName}`);
62+
Deno.exit(1);
63+
}
64+
console.info(`Found asset: ${asset.name} (${asset.id})`);
65+
const downloadUrl = asset.browser_download_url;
66+
console.info(`Downloading from ${downloadUrl}`);
67+
const response = await fetch(downloadUrl);
68+
const compressedFile = await Deno.open(artifactName, { create: true, write: true })
69+
await response.body!.pipeTo(compressedFile.writable);
70+
71+
const outDir = "./bin/";
72+
await Deno.mkdir(outDir, { recursive: true });
73+
74+
const extractCmd = artifactName.endsWith(".zip")
75+
? new Deno.Command("unzip", {args: ["-o", artifactName, "-d", outDir]})
76+
: new Deno.Command("tar", {args: ["-xzf", artifactName, "-C", outDir]});
77+
78+
const { success } = await extractCmd.output();
79+
if (!success) {
80+
console.error("Extraction failed");
81+
Deno.exit(1);
82+
}
83+
84+
const binPath = `${outDir}/${artifactName.replace(".tar.gz", "").replace(".zip", "")}/rcodesign`;
85+
await Deno.chmod(binPath, 0o755);
86+
87+
const githubOutput = Deno.env.get("GITHUB_OUTPUT");
88+
if (githubOutput) {
89+
const output = `rcodesign_path=${Deno.cwd()}/${binPath}\n`;
90+
await Deno.writeTextFile(githubOutput, output, { append: true });
91+
}
92+
93+
Deno.exit(0);
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Deploy example endpoint
2+
on:
3+
workflow_dispatch: {}
4+
workflow_run:
5+
workflows: ["Nightly Build"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
11+
get-ref:
12+
name: Get nightly ref
13+
runs-on: ubuntu-latest
14+
outputs:
15+
ref: ${{ steps.choose.outputs.ref }}
16+
tag_suffix: ${{ steps.choose.outputs.tag_suffix }}
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
- name: Install Deno
24+
uses: denoland/setup-deno@v2
25+
with:
26+
deno-version: v2.x
27+
- name: Get latest commit hash
28+
id: choose
29+
run: |
30+
set -eo pipefail
31+
.github/tools/get-nightly-ref.ts
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
GITHUB_REPOSITORY: ${{ github.repository }}
35+
36+
deploy:
37+
runs-on: self-hosted
38+
needs: get-ref
39+
steps:
40+
- name: Checkout code
41+
uses: actions/checkout@v4
42+
with:
43+
ref: ${{ needs.get-ref.outputs.ref }}
44+
- name: Download executable with curl
45+
run: |
46+
curl -L https://github.com/unyt-org/datex-cli/releases/download/nightly/datex-x86_64-unknown-linux-gnu.zip
47+
unzip datex-x86_64-unknown-linux-gnu.zip -d /usr/local/bin
48+
chmod +x /usr/local/bin/datex
49+
- name: Copy config file
50+
run: |
51+
mkdir -p /etc/datex
52+
cp example-config.json /etc/datex/example.json
53+
- name: Run datex process in background
54+
run: |
55+
nohup datex repl -v --config /etc/datex/example.json > /var/log/datex.log 2>&1 &

0 commit comments

Comments
 (0)