build version check
Some checks failed
Build and Push Version Check Action / build (push) Failing after 4m33s

This commit is contained in:
Emmaline Autumn 2025-05-02 22:05:56 -06:00
parent daf1d5cb06
commit 6db4adeb39
6 changed files with 101 additions and 0 deletions

View File

@ -0,0 +1,25 @@
name: Build and Push Version Check Action
on:
push:
paths:
- version-check/**
- .gitea/workflows/build-version-check.yml
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build Docker image
run: |
docker build -t git.cyborggrizzly.com/BearMetal/ci-actions/version-check:latest ./version-check
- name: Log in to Gitea registry
run: |
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login git.cyborggrizzly.com -u ${{ secrets.REGISTRY_USER }} --password-stdin
- name: Push to registry
run: |
docker push git.cyborggrizzly.com/BearMetal/ci-actions/version-check:latest

8
deno.json Normal file
View File

@ -0,0 +1,8 @@
{
"tasks": {
"dev": "deno run --watch main.ts"
},
"imports": {
"@std/assert": "jsr:@std/assert@1"
}
}

13
version-check/Dockerfile Normal file
View File

@ -0,0 +1,13 @@
# Build the binary
FROM denoland/deno:latest AS builder
WORKDIR /src
COPY main.ts .
RUN deno compile --allow-read --allow-run --output version-check main.ts
# Final image
FROM alpine:latest
COPY --from=builder /src/version-check /usr/local/bin/version-check
ENTRYPOINT ["/usr/local/bin/version-check"]

0
version-check/README.md Normal file
View File

5
version-check/action.yml Normal file
View File

@ -0,0 +1,5 @@
name: Version Check & Tag
description: Ensures version correctness and creates missing git tags
runs:
using: "docker"
image: git.cyborggrizzly.com/BearMetal/ci-actions/version-check:latest

50
version-check/main.ts Normal file
View File

@ -0,0 +1,50 @@
const decoder = new TextDecoder();
const denoJson = JSON.parse(await Deno.readTextFile("deno.json"));
let version = denoJson.version;
if (!version) {
console.error("Missing 'version' in deno.json");
Deno.exit(1);
}
const branch = Deno.env.get("GITHUB_REF")?.replace("refs/heads/", "") ?? "";
if (branch.startsWith("prerelease-")) {
const suffix = branch.replace("prerelease-", "");
const base = version.split("-")[0];
const expected = `${base}-${suffix}`;
if (version !== expected) {
denoJson.version = expected;
await Deno.writeTextFile("deno.json", JSON.stringify(denoJson, null, 2));
await run("git", ["config", "user.name", "CI"]);
await run("git", ["config", "user.email", "ci@cyborggrizzly.com"]);
await run("git", ["add", "deno.json"]);
await run("git", [
"commit",
"-m",
`fix: sync version with branch ${branch}`,
]);
await run("git", ["push"]);
version = expected;
}
}
const tag = `v${version}`;
try {
await run("git", ["rev-parse", tag]);
console.log(`Tag ${tag} already exists.`);
} catch {
await run("git", ["tag", tag]);
await run("git", ["push", "origin", tag]);
}
async function run(cmd: string, args: string[]) {
const command = new Deno.Command(cmd, {
args,
stdout: "piped",
stderr: "piped",
});
const status = await command.output();
if (!status.success) {
const err = decoder.decode(await status.stderr);
throw new Error(`Command failed: ${cmd} ${args.join(" ")}\n${err}`);
}
}