What it does
Draws cards for your GitHub profile, as SVG files that stay sharp on any screen:
- Contributions: your contributions since you joined GitHub and in the last 12 months, your commits, your current and longest streaks of days with contributions, and your languages by commits and by repositories.
- Statistics: your repositories and their stars, how many times they were viewed and cloned, the downloads of your releases and your GitHub Actions runs, with charts of the last 30 days.
- Activity: your pull requests, issues, reviews and new repositories, your followers, your contributions by type and by day of the week, and the repositories you commit to most.
- Visitors: the unique visitors and cloners of your repositories in the last 14 days, the sites that sent them and the pages they viewed.
- GitHub Actions: your runs of the last 30 days, how many succeeded and failed, how long they took and your busiest workflows.
- Code: the size of your code in each language, your largest repositories, your stars month by month, and your forks and watchers.
rghcard is also a GitHub Action: a workflow in your profile repository refreshes the cards every week and keeps the history of your page views and clones, which GitHub itself keeps for 14 days only. The cards come in the colours of GitHub’s dark and light modes, and your profile shows each reader those of their mode.
The cards on your GitHub profile
The workflow runs the rghcard action on GitHub, so this needs no R on your computer.
Your profile repository. GitHub shows on your profile the README of the repository named after your user name,
github.com/<you>/<you>. If you have none, create it, public, with a README.-
The workflow. In that repository, click Add file > Create new file, name the file
.github/workflows/rghcard.yml(typing the slashes makes the folders), paste this, and click Commit changes:name: rghcard on: schedule: - cron: "17 5 * * 1" # every Monday at 05:17 UTC workflow_dispatch: # and when you run it from the Actions tab permissions: contents: write # to commit the cards and their history jobs: cards: runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 - uses: sedzinfo/rghcard@v0 with: token: ${{ secrets.RGHCARD_TOKEN }}The action installs R and rghcard on GitHub’s machine, collects your statistics, draws the cards and commits them, with their history.
@v0is the latest release of rghcard 0.x. Keep thecronline at least weekly, since GitHub keeps the traffic for 14 days. In R,use_rghcard_action()writes this workflow for you. A token for the traffic. GitHub shows the page views and clones of a repository only to those who can push to it, so the workflow needs a token of yours. This link opens GitHub’s form for a fine-grained token, filled in: the name
rghcard, one permission, Administration: Read-only, which reads the traffic and can change nothing, and Expiration: none, since the cards stop updating when the token expires. GitHub adds Metadata: Read-only, which every token has, by itself. Choose Repository access: All repositories, click Generate token and copy the token: GitHub shows it only once.The secret. In the profile repository, Settings > Secrets and variables > Actions > New repository secret: name it
RGHCARD_TOKENand paste the token.The first run. Actions > rghcard > Run workflow. A few minutes later the repository has the cards,
rghcard-<card>-dark.svgandrghcard-<card>-light.svgfor each card (contributions,stats,activity,visitors,actionsandcode), and their history, the folderrghcard-data.-
The cards in your README. Add this to
README.md, or the cards you want of it, in the order you want:<picture> <source media="(prefers-color-scheme: dark)" srcset="rghcard-contributions-dark.svg"/> <img alt="GitHub contributions" src="rghcard-contributions-light.svg" width="100%"/> </picture> <picture> <source media="(prefers-color-scheme: dark)" srcset="rghcard-stats-dark.svg"/> <img alt="GitHub statistics" src="rghcard-stats-light.svg" width="100%"/> </picture> <picture> <source media="(prefers-color-scheme: dark)" srcset="rghcard-activity-dark.svg"/> <img alt="GitHub activity" src="rghcard-activity-light.svg" width="100%"/> </picture> <picture> <source media="(prefers-color-scheme: dark)" srcset="rghcard-visitors-dark.svg"/> <img alt="GitHub visitors" src="rghcard-visitors-light.svg" width="100%"/> </picture> <picture> <source media="(prefers-color-scheme: dark)" srcset="rghcard-actions-dark.svg"/> <img alt="GitHub Actions" src="rghcard-actions-light.svg" width="100%"/> </picture> <picture> <source media="(prefers-color-scheme: dark)" srcset="rghcard-code-dark.svg"/> <img alt="GitHub code" src="rghcard-code-light.svg" width="100%"/> </picture>
Without the secret, the cards show your public statistics only: stars, forks, languages, release downloads, GitHub Actions runs and contributions, but no page views, clones or visitors. When the token expires or is revoked, the workflow fails with a message saying so, and GitHub tells you of the failed run by email: create a new token, or regenerate the old one, and paste it into the secret.
Options
The inputs of the action, under with:, change the cards:
| Input | Default | What it does |
|---|---|---|
token |
the workflow’s own token | A token of yours that can read the traffic of your repositories, from a secret. The workflow’s own token cannot, so without yours the cards show your public statistics only. |
cards |
contributions stats activity visitors actions code |
The cards to draw. |
themes |
dark light |
The themes of the cards: dark, light or both. |
format |
svg |
The format of the cards: svg, png or both. An SVG card is sharp on any screen and a tenth of the size of a PNG one, which counts in a repository that keeps every version of its cards. |
days |
30 |
How many days the statistics card and the GitHub Actions card cover, up to the day before the run: their page views, clones and runs. The visitors card always covers 14 days, those for which GitHub gives the referring sites. |
stats-panels |
The charts of the statistics card, one to three, such as views clones top_starred. Any card can show the charts of the others: Draw the cards in R lists all 23, and The statistics card, The contributions card and More cards explain them. Empty for the default charts. |
|
contributions-panels, activity-panels, visitors-panels, actions-panels, code-panels
|
The charts of the other cards, chosen in the same way. Empty for the default charts. | |
include-private |
false |
Include private repositories, and the commits in them? In a public repository, their names and numbers then become public. |
include-forks |
false |
Include forks, and the commits in them? |
cards-dir |
. |
The folder of the cards. |
data-dir |
rghcard-data |
The folder of the history. |
commit |
true |
Commit and push the cards and the history? With false, they are only drawn, for a later step. |
commit-message |
Update the GitHub statistics cards |
The message of the commit. |
For example, the dark contributions, statistics and GitHub Actions cards only, of the last 14 days, with other charts:
- uses: sedzinfo/rghcard@v0
with:
token: ${{ secrets.RGHCARD_TOKEN }}
cards: contributions stats actions
themes: dark
days: 14
stats-panels: views clones top_starredWith one theme, show each card with an <img> alone, such as <img alt="GitHub statistics" src="rghcard-stats-dark.svg" width="100%"/>: there is no card of the other mode for <picture> to choose.
Before version 0.4.0, the cards were PNG files. A profile that still shows rghcard-stats-dark.png and the like shows cards that are no longer updated, and the run warns of them: change .png to .svg in README.md and delete the PNG cards, or keep PNG cards with format: png.
What becomes public
In a public profile repository, the cards and rghcard-data/ are public:
- the page views, unique visitors, clones and unique cloners of each repository per day, and its ten top referring sites and ten most viewed pages, with their counts;
- the downloads of each release file, and your GitHub Actions runs, with their times;
- the bytes of code of each repository in each language, and the time of each star;
- how many followers you have, and how many users you follow;
- your contributions per day and by type, which your profile shows anyway, and your commits per repository and year.
Who visits, clones or stars your repositories is never collected: GitHub gives no names for the traffic, and rghcard keeps only the time of each star. Private repositories and forks are left out, and so are the commits in them, unless include-private or include-forks brings them in.
Installation
Only for using rghcard in R: to draw cards on your computer, or to set up the workflow from R. The cards on your GitHub profile need none of this.
1. Install R
Download R 4.1 or newer from CRAN, for Windows, macOS or Linux, and run the installer.
2. Install RStudio or Positron
An editor makes R easier to use. It is optional, and both are free, from Posit:
- RStudio Desktop
- Positron, which also runs Python
3. Install rghcard
Run one of these in RStudio, Positron or the R console. Each one also installs the packages rghcard needs.
From R-universe (recommended)
install.packages(
"rghcard",
repos = c("https://sedzinfo.r-universe.dev", "https://cloud.r-project.org")
)R-universe builds rghcard from this repository after every change, ready to install on Windows, macOS and Linux, and CRAN provides the packages it needs.
From GitHub
install.packages("pak") # once
pak::pak("sedzinfo/rghcard")From the release tarball
The Latest build pre-release has the source tarball and the PDF manual, rebuilt from main on every change:
install.packages("pak") # once
pak::pak("url::https://github.com/sedzinfo/rghcard/releases/download/latest/rghcard_0.4.0.tar.gz")From a clone of the repository
This repository keeps no files in Git LFS, so a plain clone with Git has everything:
install.packages("pak") # once
pak::local_install("path/to/rghcard")Usage
library(rghcard)
# try it with made-up statistics, without a token
stats_card(example_stats(), "card.svg")
view_card("card.svg") # in the Viewer pane
view_card("card.svg", "plots") # in the Plots pane
# your own statistics: the traffic needs a token of yours, which the gh package finds in the
# GITHUB_PAT environment variable or the git credential store
stats <- collect_stats() # adds to the history in rghcard-data/
contributions_card(stats, "rghcard-contributions.svg")
stats_card(stats, "rghcard-stats.svg")
stats_card(stats, "rghcard-stats-light.svg", theme = "light")
# the other cards
activity_card(stats, "rghcard-activity.svg")
visitors_card(stats, "rghcard-visitors.svg")
actions_card(stats, "rghcard-actions.svg")
code_card(stats, "rghcard-code.svg")
# other charts, another period, a PNG
stats_card(stats, "card.png", days = 14, panels = c("views", "top_cloned", "languages"))
# the public statistics and the contributions of another user
octocat <- collect_stats(user = "octocat", dir = "octocat-data")
contributions_card(octocat, "octocat.svg")
view_card(stats_card(octocat, file = NULL)) # a card without a file
# the workflow, from R: writes .github/workflows/rghcard.yml into your profile repository
use_rghcard_action("path/to/your/profile/repository")The Get started article shows the cards and how to put them on your profile, and Draw the cards in R goes through doing it in R, step by step: the token, the charts, the history and charts of your own from it. Cards from a user name draws the cards of any user from their user name, in R or in a Shiny app. The contributions card, The statistics card and More cards explain each number and chart, and the help pages every option.