Trailhead Stats GitHub Action

November 29, 2024 ยท View on GitHub

GitHub release MegaLinter CI codecov

Trailhead Stats Logo

Description

Trailhead Stats is a GitHub Action created to dynamically display Trailhead statistics based on a specified Trailhead username. This action can be used to showcase your Trailhead achievements, such as badges, points and more, directly in your GitHub repository's README or other Markdown files.

Usage

Prerequisites

For the standard use case of having your Trailhead Stats displayed on your GitHub homepage, you need:

If you're lost, follow the quickstart documentation.

GitHub Action

To use this action in your workflow, add the following step:

- uses: nabondance/trailhead-stats@v2
  permissions:
    contents: write
  with:
    trailhead-username: 'your_trailhead_username'
    display-type: 'card' # Optional
    display-file: 'README.md' # Optional
    file-format: 'md' # Optional

This will fetch your Trailhead stats and display them in the specified format.

Special Tags in Display File

To insert the Trailhead stats into your display-file (like README.md), you need to place special comment tags in your file. These tags define where the Trailhead stats will be inserted or updated.

Insert the following tags in your file:

<!--TH_Stats:start-->
<!--TH_Stats:end-->

The action will automatically update the content between these tags with the latest Trailhead stats. Ensure these tags are in place for the action to work correctly.

Example Workflow

Here's an example of a complete workflow using the Trailhead Stats action:

name: Update Trailhead Stats

on:
  schedule:
    - cron: '0 0 * * *' # Runs daily

jobs:
  update-stats:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - uses: nabondance/trailhead-stats@v2
        with:
          trailhead-username: 'your_trailhead_username'
          display-type: 'card'

This workflow will update your Trailhead stats in your repository's README.md daily.

Inputs

Input NameKindDescriptionDefault
trailhead-usernameRequiredThe username on Trailhead.username
display-fileConfigThe file to update for displaying the Trailhead stats.README.md
file-formatConfigFormat of the file. Options: md, html.md
card-pathConfigFolder path to save the cardimages
display-typePreferenceThe type of display output. Options: text, card, output.text
dark-stylePreferenceThe kind of dark theme. Options: dimmed, dark, high-contrastdimmed
show-*PreferenceOn a card, customize the element. See Card Display customization.
output-onlyDebugSet to true to only output without modifying the file.false
no-commitDebugSet to true to not commit the modification.false

Outputs

stats

The fetched Trailhead stats.

Visual display in your file

Display TypeExample Light ThemeExample Dark Theme
textText LightText Dark
cardCard LightCard Dark
outputObject to use in a GitHub ActionObject to use in a GitHub Action

Card features

Card Display customization

Theses inputs allows you to select what is displayed and how.

Input NameDescriptionOptionsDefault
show-skillDisplay or hide the skill bar.hidden, visiblevisible
show-skill-numberThe max number of skills to display in the card.any number5
show-skill-themeColor theme for the skills in the card.see Card skill themedefault
show-skill-custom-color-highHexadecimal color of the highest skillsany valid hexadecimal``
show-skill-custom-color-mediumHexadecimal color of the medium skillsany valid hexadecimal``
show-skill-custom-color-lowHexadecimal color of the lowest skillsany valid hexadecimal``
show-certification-latestDisplay or hide the latest certification.hidden, visiblevisible
show-badge-latestDisplay or hide the latest badge.hidden, visiblevisible
show-superbadge-latestDisplay or hide the latest superbadge.hidden, visiblevisible
show-event-badge-latestDisplay or hide the latest event badge.hidden, visiblevisible
show-stamp-latestDisplay or hide the latest stamp.hidden, visiblevisible
show-certificationHow to display the certifications.hidden, icon, table, detail, numberdetail
show-badgeHow to display the badges.hidden, icon, table, detail, numberhidden
show-superbadgeHow to display the superbadges.hidden, icon, table, detail, numbericon
show-event-badgeHow to display the event badges.hidden, icon, table, detail, numbericon
show-stampHow to display the stamps.hidden, icon, table, detail, numbertable

You can see how the stat will look depending on the display option:

Selected Display OptionExample
hiddenhidden
visiblevisible
iconicon
tabletable
detaildetail
numbernumber

Card theme

Dark Theme Styles

According to GitHub, there is different dark themes styles that you can also select using the input dark-style:

Dark StyleExample
dimmeddimmed
darkdark
high-contrasthigh-contrast

Skill Themes

You can select the colors of the skills by specifying a theme using the input show-skill-theme:

Skill ThemeExample
default (light theme)Skill Theme default
default (dark theme)Skill Theme default
olympicSkill Theme olympic
halloweenSkill Theme halloween
winterSkill Theme winter
springSkill Theme spring
summerSkill Theme summer

Card automatism

Theses features doesn't require any configuration, they are fully automatic

  • Card is displayed inside the file selected by display-file, with the correct format set by file-format.
  • Clicking on the card will redirect to the trailhead profile.
  • The card won't display empty blocs (Certifications, Superbadges, Stamps).
  • The Card will be displayed on light or dark theme based on the GitHub theme of the user.
  • If all the custom skill colors aren't set, it will use the specified theme or default theme if none.

Card UI display examples

There are countless permutations possible. Here are some examples with inputs and card results.

Versions

Consider using a released version. You can specify only a major version in order to automatically get all the new released features. Thanks to semantic versioning, breaking changes will be in a new major version.

uses: nabondance/trailhead-stats@v2

If you want a specific version, you can specify it:

uses: nabondance/trailhead-stats@v1.2.3

How it Works

  1. Query the trailhead information of the specified username
  2. Generate an html/css page depending on the show-* inputs
  3. Screenshot the html/css page
  4. Update the specified display-file with the screenshots links
  5. Commit and push the changes to the repo

Troubleshooting

Having issues with the Trailhead Stats GitHub Action? Here are some common problems and their solutions:

Common Issues

1. Stats Not Updating

Problem: The Trailhead stats in the README file are not updating.

Solution: Ensure that the <!--TH_Stats:start--> and <!--TH_Stats:end--> tags are correctly placed in your display-file. The action updates the content between these tags.


2. Git Command Fails

Problem: The Git commands fails during execution.

Solution: Check that you granted the content:write permission for the job in your workflow.


3. GitHub Action Fails

Problem: The GitHub Action fails during execution.

Solution: Check the action logs in your repository's "Actions" tab for specific error messages. Common issues include incorrect input parameters or network issues.


4. Incorrect Trailhead Username

Problem: The stats displayed do not match your Trailhead profile.

Solution: Verify that the trailhead-username input is correctly set to your Trailhead username. The username should match exactly with your Trailhead profile.


Advanced Troubleshooting

If you're experiencing other issues, try the following steps:

  • Check GitHub Action Version: Ensure you are using the latest version of the Trailhead Stats GitHub Action.
  • Review Workflow File: Double-check your workflow file for syntax errors or misconfigurations.
  • Manual Trigger: Try running the workflow manually from the "Actions" tab to see if the issue persists.

Still need help? Feel free to open an issue on the GitHub repository with a detailed description of your problem.

Customization

You can customize the action by changing the input parameters as per your requirement.

Contribution

Contributions to the Trailhead Stats GitHub Action are welcome. Please feel free to fork the repository, make changes, and create a pull request.

Abandoned Features

Feature: Any stat depending of the earning date of a badge.

Reason: Earned Date not available without login.