mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-06 07:17:27 +00:00
ci: Update node coverage badge to work without games.txt (#156)
* ci: Update node coverage badge to work without games.txt Fixes #155 using a new node script that should be more robust than the old shell script. * ci: Change badge cron time to less common time By doing at a less common time we should reduce action time usage as the runners will be under less load. * Add/Update badge * ci: Improve node-badge script Co-Authored-By: CosminPerRam <cosmin.p@live.com> * ci: Run node badge action if script changes * ci: Update node badge path for workspaces * ci: Revert loading games from index in node badge script --------- Co-authored-by: GitHub Action <action@github.com> Co-authored-by: CosminPerRam <cosmin.p@live.com>
This commit is contained in:
parent
3f1164ef5d
commit
0c7dbe76d7
3 changed files with 66 additions and 29 deletions
14
.github/badges/node.svg
vendored
14
.github/badges/node.svg
vendored
|
|
@ -1,20 +1,20 @@
|
|||
<svg width="163.6" height="20" viewBox="0 0 1636 200" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Node game coverage: 13%">
|
||||
<title>Node game coverage: 13%</title>
|
||||
<svg width="181.6" height="20" viewBox="0 0 1816 200" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Node game coverage: 14.06%">
|
||||
<title>Node game coverage: 14.06%</title>
|
||||
<linearGradient id="a" x2="0" y2="100%">
|
||||
<stop offset="0" stop-opacity=".1" stop-color="#EEE"/>
|
||||
<stop offset="1" stop-opacity=".1"/>
|
||||
</linearGradient>
|
||||
<mask id="m"><rect width="1636" height="200" rx="30" fill="#FFF"/></mask>
|
||||
<mask id="m"><rect width="1816" height="200" rx="30" fill="#FFF"/></mask>
|
||||
<g mask="url(#m)">
|
||||
<rect width="1276" height="200" fill="#555"/>
|
||||
<rect width="360" height="200" fill="#0f80c1" x="1276"/>
|
||||
<rect width="1636" height="200" fill="url(#a)"/>
|
||||
<rect width="540" height="200" fill="#0f80c1" x="1276"/>
|
||||
<rect width="1816" height="200" fill="url(#a)"/>
|
||||
</g>
|
||||
<g aria-hidden="true" fill="#fff" text-anchor="start" font-family="Verdana,DejaVu Sans,sans-serif" font-size="110">
|
||||
<text x="60" y="148" textLength="1176" fill="#000" opacity="0.25">Node game coverage</text>
|
||||
<text x="50" y="138" textLength="1176">Node game coverage</text>
|
||||
<text x="1331" y="148" textLength="260" fill="#000" opacity="0.25">13%</text>
|
||||
<text x="1321" y="138" textLength="260">13%</text>
|
||||
<text x="1331" y="148" textLength="440" fill="#000" opacity="0.25">14.06%</text>
|
||||
<text x="1321" y="138" textLength="440">14.06%</text>
|
||||
</g>
|
||||
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 1 KiB After Width: | Height: | Size: 1 KiB |
29
.github/workflows/node-badge.yml
vendored
29
.github/workflows/node-badge.yml
vendored
|
|
@ -4,10 +4,11 @@ name: "Generate node comparison badge"
|
|||
on:
|
||||
push:
|
||||
paths:
|
||||
- "src/games/definitions.rs"
|
||||
- "crates/lib/src/games/definitions.rs"
|
||||
- ".github/workflows/node-badge.yml"
|
||||
- ".github/workflows/scripts/node-badge.mjs"
|
||||
schedule:
|
||||
- cron: '0 0 * * 1' # Update once a week in case node-gamedig has changed
|
||||
- cron: '34 3 * * 2' # Update once a week in case node-gamedig has changed
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
|
|
@ -26,30 +27,14 @@ jobs:
|
|||
- uses: actions/checkout@v4
|
||||
with:
|
||||
repository: "gamedig/node-gamedig"
|
||||
sparse-checkout: "games.txt"
|
||||
path: "node-gamedig"
|
||||
sparse-checkout: |
|
||||
lib/games.js
|
||||
package.json
|
||||
|
||||
- name: Calculate comparison
|
||||
id: comparison
|
||||
run: |
|
||||
# Find list of node games
|
||||
node_games=$(awk -F "|" '/^[^#]/ {if(length($1) > 0) print $1 }' ./node-gamedig/games.txt)
|
||||
node_games_count=$(printf "%s\n" "$node_games" | wc -l)
|
||||
|
||||
# Calculate how many of those games we have definitions for
|
||||
rust_games_count=0
|
||||
for game in $node_games; do
|
||||
if grep "\"$game\" *=>" ./crates/lib/src/games/definitions.rs; then
|
||||
rust_games_count=$(( rust_games_count + 1 ))
|
||||
fi
|
||||
done
|
||||
|
||||
# Calculate percent
|
||||
percent=$(( rust_games_count * 100 / node_games_count))
|
||||
|
||||
echo "$rust_games_count/$node_games_count $percent%"
|
||||
# Output percentage
|
||||
echo "percent=$percent" >> "${GITHUB_OUTPUT}"
|
||||
run: node .github/workflows/scripts/node-badge.mjs
|
||||
|
||||
- name: Generate the badge SVG image
|
||||
uses: emibcn/badge-action@v2.0.2
|
||||
|
|
|
|||
52
.github/workflows/scripts/node-badge.mjs
vendored
Normal file
52
.github/workflows/scripts/node-badge.mjs
vendored
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
"use strict";
|
||||
|
||||
//! Calculate the percentage of games from node that we support
|
||||
// Expects node-gamedig checkout out in git root /node-gamedig
|
||||
// Expects the generic example to output a list of game IDs when no arguments are provided
|
||||
|
||||
import process from "node:process";
|
||||
import { closeSync, openSync, writeSync } from "node:fs";
|
||||
import { spawnSync } from "node:child_process";
|
||||
|
||||
const setOutput = (key, value) => {
|
||||
const file = openSync(process.env.GITHUB_OUTPUT, "a");
|
||||
writeSync(file, `${key}=${value}\n`);
|
||||
closeSync(file);
|
||||
}
|
||||
|
||||
// Get node IDs
|
||||
// NOTE: Here we directly import from games to avoid loading
|
||||
// unecessary parts of the library that would require us
|
||||
// to install dependencies.
|
||||
import { games } from "../../../node-gamedig/lib/games.js";
|
||||
|
||||
const node_ids = new Set(Object.keys(games));
|
||||
const node_total = node_ids.size;
|
||||
|
||||
// Get rust IDs
|
||||
|
||||
const command = spawnSync("cargo", ["run", "-p", "gamedig", "--example", "generic"]);
|
||||
|
||||
if (command.status !== 0) {
|
||||
console.error(command.stderr.toString("utf8"));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const rust_ids_pretty = command.stdout.toString("utf8");
|
||||
const rust_ids = new Set(rust_ids_pretty.split("\n").map(line => line.split("\t")[0]).filter(id => id.length > 0));
|
||||
|
||||
// Detect missing node IDs
|
||||
|
||||
for (const id of rust_ids) {
|
||||
if (node_ids.delete(id)) {
|
||||
rust_ids.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
console.log("Node remains", node_ids);
|
||||
console.log("Rust remains", rust_ids);
|
||||
|
||||
const percent = 1 - (node_ids.size / node_total);
|
||||
|
||||
// Output percent to 2 decimal places
|
||||
setOutput("percent", Math.round(percent*10000)/100);
|
||||
Loading…
Add table
Add a link
Reference in a new issue