mirror of
https://github.com/reiyua/github-profile-trophy-reiyua-mirror.git
synced 2026-11-17 06:02:09 +11:00
Add local SVG generator script and GitHub Action for trophy SVGs (#412)
* Wrote a simple render_svg.ts file that generates the svg given an github username, theme and out path. * render_svg.ts generates output dir if not exsists. * Added Section to README.md that explains how to use the render_svg.ts script. * Added an github action that utilizes the render_svg.ts script. * Added Usage of github action to README.md * Added simple CI Check if action runs. * Ran: deno fmt
This commit is contained in:
parent
97e9fad679
commit
2ba2fe648c
4 changed files with 154 additions and 0 deletions
26
.github/workflows/test-repository-action.yml
vendored
Normal file
26
.github/workflows/test-repository-action.yml
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
name: Test GitHub Profile Trophy Action
|
||||||
|
on: [push, pull_request, workflow_dispatch]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test-trophy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout this repo
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Test Action
|
||||||
|
id: trophy
|
||||||
|
uses: ./.
|
||||||
|
with:
|
||||||
|
username: ${{ github.repository_owner }}
|
||||||
|
output_path: ./trophy.svg
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Verify SVG generated
|
||||||
|
run: |
|
||||||
|
if [ -f trophy.svg ]; then
|
||||||
|
echo "SVG exsists ($(wc -c < trophy.svg) Bytes)"
|
||||||
|
file trophy.svg
|
||||||
|
else
|
||||||
|
echo "SVG failed to generate"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
28
README.md
28
README.md
|
|
@ -566,6 +566,34 @@ https://github-profile-trophy.vercel.app/?username=ryo-ma&no-frame=true
|
||||||
<img width="936" src="https://github.com/user-attachments/assets/54de15a3-d907-4a50-8117-170aae74d1cd">
|
<img width="936" src="https://github.com/user-attachments/assets/54de15a3-d907-4a50-8117-170aae74d1cd">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
## Generate an svg file localy
|
||||||
|
|
||||||
|
Using the render_svg.ts script you can generate your trophys as an svg file
|
||||||
|
given your username, (Enviroment Vars: See [env-example](env-example)).
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
deno run --allow-net --allow-env --allow-read --allow-write ./render_svg.ts USERNAME OUTPUT_DIR THEME
|
||||||
|
```
|
||||||
|
|
||||||
|
## Generate an svg inside Github CI (Workflow)
|
||||||
|
|
||||||
|
Using the provided github action you can easly generate the trophy inside an
|
||||||
|
github workflow. This eliminates the needs of an online service running but you
|
||||||
|
have to manualy update rerun the action to update the file.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- name: Generate trophy
|
||||||
|
uses: Erik-Donath/github-profile-trophy@feature/generate-svg
|
||||||
|
with:
|
||||||
|
username: your-username
|
||||||
|
output_path: trophy.svg
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
```
|
||||||
|
|
||||||
# Contribution Guide
|
# Contribution Guide
|
||||||
|
|
||||||
Check [CONTRIBUTING.md](./CONTRIBUTING.md) for more details.
|
Check [CONTRIBUTING.md](./CONTRIBUTING.md) for more details.
|
||||||
|
|
|
||||||
27
action.yml
Normal file
27
action.yml
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
name: Generate GitHub Profile Trophy SVG
|
||||||
|
description: Run the local generator script to produce an SVG.
|
||||||
|
inputs:
|
||||||
|
username:
|
||||||
|
description: "GitHub username to generate the trophy for"
|
||||||
|
required: true
|
||||||
|
output_path:
|
||||||
|
description: "Output path to write the SVG"
|
||||||
|
required: true
|
||||||
|
default: "trophy.svg"
|
||||||
|
token:
|
||||||
|
description: "PAT or token to use for GitHub API"
|
||||||
|
required: true
|
||||||
|
runs:
|
||||||
|
using: "composite"
|
||||||
|
steps:
|
||||||
|
- name: Setup Deno
|
||||||
|
uses: denoland/setup-deno@v1
|
||||||
|
with:
|
||||||
|
deno-version: v1.x
|
||||||
|
|
||||||
|
- name: Generate trophy
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN1: ${{ inputs.token }}
|
||||||
|
run: |
|
||||||
|
deno run --allow-net --allow-env --allow-read --allow-write $GITHUB_ACTION_PATH/render_svg.ts "${{ inputs.username }}" "${{ inputs.output_path }}"
|
||||||
73
render_svg.ts
Normal file
73
render_svg.ts
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
import "https://deno.land/x/dotenv@v0.5.0/load.ts";
|
||||||
|
|
||||||
|
const username = Deno.args[0];
|
||||||
|
const outputPath = Deno.args[1] ?? "./assets/trophy.svg";
|
||||||
|
const themeName = Deno.args[2] ?? "default";
|
||||||
|
|
||||||
|
if (!username) {
|
||||||
|
console.error(
|
||||||
|
"Usage: deno run --allow-net --allow-env --allow-read --allow-write ./render_svg.ts USERNAME [OUTPUT_PATH] [THEME]",
|
||||||
|
);
|
||||||
|
Deno.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
import { GithubApiService } from "./src/Services/GithubApiService.ts";
|
||||||
|
import { Card } from "./src/card.ts";
|
||||||
|
import { COLORS } from "./src/theme.ts";
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
console.log("Starting trophy render...");
|
||||||
|
console.log("Username:", username);
|
||||||
|
console.log("Output path:", outputPath);
|
||||||
|
console.log("Theme:", themeName);
|
||||||
|
|
||||||
|
const svc = new GithubApiService();
|
||||||
|
|
||||||
|
const userInfoOrError = await svc.requestUserInfo(username);
|
||||||
|
|
||||||
|
if (
|
||||||
|
!(userInfoOrError && (userInfoOrError as any).totalCommits !== undefined)
|
||||||
|
) {
|
||||||
|
console.error(
|
||||||
|
"Failed to fetch user info. Check token, username and rate limits.",
|
||||||
|
);
|
||||||
|
Deno.exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
const userInfo = userInfoOrError as any;
|
||||||
|
|
||||||
|
const panelSize = 115;
|
||||||
|
const maxRow = 10;
|
||||||
|
const maxColumn = -1; // auto
|
||||||
|
const marginWidth = 10;
|
||||||
|
const marginHeight = 10;
|
||||||
|
const noBackground = false;
|
||||||
|
const noFrame = false;
|
||||||
|
|
||||||
|
const card = new Card(
|
||||||
|
[],
|
||||||
|
[],
|
||||||
|
maxColumn,
|
||||||
|
maxRow,
|
||||||
|
panelSize,
|
||||||
|
marginWidth,
|
||||||
|
marginHeight,
|
||||||
|
noBackground,
|
||||||
|
noFrame,
|
||||||
|
);
|
||||||
|
const theme = (COLORS as any)[themeName] ?? (COLORS as any).default;
|
||||||
|
const svg = card.render(userInfo, theme);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const dir = outputPath.replace(/\/[^/]+$/, "");
|
||||||
|
if (dir) await Deno.mkdir(dir, { recursive: true });
|
||||||
|
} catch {
|
||||||
|
console.error("Failed to create directory. No permission?");
|
||||||
|
Deno.exit(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
await Deno.writeTextFile(outputPath, svg);
|
||||||
|
console.log(`Wrote ${outputPath}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
await main();
|
||||||
Loading…
Add table
Reference in a new issue