Skip to content

Commit

Permalink
feat: github-action (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuciNyan committed Aug 16, 2024
1 parent be53f56 commit b2b838d
Show file tree
Hide file tree
Showing 21 changed files with 122,569 additions and 288 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/generate-and-upload-card.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: generate-and-upload-card

on:
pull_request:
workflow_dispatch:

jobs:
generate:
permissions:
contents: write
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: generate github stats card
uses: LuciNyan/pixel-profile/action@feat-github-action
with:
outputs: |
dist/github-stats?username=LuciNyan&screen_effect=false&theme=fuji&dithering=true&hide=avatar
dist/github-stats-dark?username=LuciNyan&theme=fuji&hide=avatar&avatar_border=false&screen_effect=true
# push the content of <build_dir> to a branch
# the content will be available at https://raw.githubusercontent.com/<github_user>/<repository>/<target_branch>/<file> , or as github page
- name: push github-contribution-grid-snake.svg to the output branch
uses: crazy-max/ghaction-github-pages@v3.1.0
with:
target_branch: output
build_dir: dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ node_modules
coverage
benchmarks
vercel_token
.turbo/

# IDE
.vscode/*
Expand All @@ -15,4 +16,4 @@ vercel_token
*.code-workspace

dist
__diff_output__/
__diff_output__/
18 changes: 18 additions & 0 deletions action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "generate-pixel-github-stats"
description: "Generates a github stats card from a github user contributions."
author: "LuciNyan"

runs:
using: node20
main: libs/index.js

inputs:
github_token:
description: "github token used to fetch the contribution data. Default to the action token if empty."
required: false
default: ${{ github.token }}
outputs:
required: false
default: null
description: |
list of files to generate.
70 changes: 70 additions & 0 deletions action/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { parseOutputs } from './parseOutputs'
import { parseArray, parseBoolean, parseString } from './utils'
import * as core from '@actions/core'
import * as fs from 'fs'
import * as path from 'path'
import { fetchStats, renderStats } from 'pixel-profile'

async function main() {
try {
const githubToken = process.env.GITHUB_TOKEN ?? core.getInput('github_token')

const options = parseOutputs(core.getMultilineInput('outputs'))

for (const option of options) {
if (option === null) continue

const {
background,
color,
exclude_repo,
hide,
include_all_commits,
pixelate_avatar,
screen_effect,
show,
username,
theme,
avatar_border,
dithering,
filename
} = option

const showStats = parseArray(show)
const includeAllCommits = parseBoolean(include_all_commits)

const stats: Parameters<typeof renderStats>[0] = await fetchStats(
typeof username === 'string' ? username : '',
includeAllCommits,
parseArray(exclude_repo),
showStats.includes('prs_merged') || showStats.includes('prs_merged_percentage'),
showStats.includes('discussions_started'),
showStats.includes('discussions_answered'),
githubToken
)

const options = {
background: parseString(background),
color: parseString(color),
hiddenStatsKeys: hide ? parseArray(hide) : undefined,
includeAllCommits,
pixelateAvatar: parseBoolean(pixelate_avatar),
theme: parseString(theme),
screenEffect: parseBoolean(screen_effect),
avatarBorder: parseBoolean(avatar_border),
dithering: parseBoolean(dithering),
isFastMode: false
}

const result = await renderStats(stats, options)

console.log(`💾 writing to ${filename}`)
fs.mkdirSync(path.dirname(filename), { recursive: true })
fs.writeFileSync(filename, result)
}
} catch (e: any) {
core.setFailed(`Action failed with "${e.message}"`)
}
}

main()
Loading

0 comments on commit b2b838d

Please sign in to comment.