From c52207f55658ec34c4ea8324c6062e56038ea129 Mon Sep 17 00:00:00 2001 From: Spenser Black Date: Wed, 10 Jun 2026 12:51:07 +0000 Subject: [PATCH 1/2] Add GitHub action --- .dockerignore | 1 + action/Dockerfile | 3 +++ action/README.md | 41 +++++++++++++++++++++++++++++++++++++++++ action/action.yml | 30 ++++++++++++++++++++++++++++++ action/entrypoint.sh | 7 +++++++ 5 files changed, 82 insertions(+) create mode 100644 action/Dockerfile create mode 100644 action/README.md create mode 100644 action/action.yml create mode 100755 action/entrypoint.sh diff --git a/.dockerignore b/.dockerignore index 9c83831..e9a8855 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,6 +5,7 @@ spec/ .github/ .ruby-lsp/ .vscode/ +action/ .editorconfig .env .env.example diff --git a/action/Dockerfile b/action/Dockerfile new file mode 100644 index 0000000..f845664 --- /dev/null +++ b/action/Dockerfile @@ -0,0 +1,3 @@ +FROM ghcr.io/spenserblack/github-polyglot:v0.1.0-rc.2 +COPY entrypoint.sh /entrypoint.sh +ENTRYPOINT [ "/entrypoint.sh" ] diff --git a/action/README.md b/action/README.md new file mode 100644 index 0000000..f302f00 --- /dev/null +++ b/action/README.md @@ -0,0 +1,41 @@ +# GitHub Polyglot action + +This action runs the `github-polyglot` gem in a Docker container. + +## Inputs + +### `token` + +Optional. GitHub API token to avoid rate limits when scanning repository language details. + +### `user` + +Optional. The user to collect data for. Defaults to the owner of the repository that is running +the action. + +### `format` + +Optional. The format of the output. Defaults to `print` (a display format for terminal display). + +## Outputs + +### `output` + +The output of the `github-polyglot` gem. + +## Example + +```yaml +# ... +steps: +- uses: spenserblack/github-polyglot/action@main + id: github-polyglot + with: + token: ${{ secrets.PAT }} + format: svg +- name: Create language stats image + env: + SVG: ${{ steps.github-polyglot.outputs.output }} + run: echo "$SVG" > language-stats.svg + # Commit the SVG with your favorite commands or actions +``` diff --git a/action/action.yml b/action/action.yml new file mode 100644 index 0000000..8850156 --- /dev/null +++ b/action/action.yml @@ -0,0 +1,30 @@ +name: GitHub Polyglot +description: Compile language statistics for a GitHub user +branding: + icon: code + color: orange +inputs: + token: + description: The GitHub token for the API + required: false + user: + description: The user to analyze + required: true + default: ${{ github.repository_owner }} + format: + description: The format of the output + required: true + default: print +outputs: + output: + description: The output of the executable +runs: + using: docker + image: Dockerfile + env: + GITHUB_TOKEN: ${{ inputs.token }} + args: + - "--user" + - ${{ inputs.user }} + - "--format" + - ${{ inputs.format }} diff --git a/action/entrypoint.sh b/action/entrypoint.sh new file mode 100755 index 0000000..b68c6bc --- /dev/null +++ b/action/entrypoint.sh @@ -0,0 +1,7 @@ +#!/bin/sh +OUTPUT="$(github-polyglot "$@")" +# NOTE: We still want to show the output to the user, which can be helpful if the user is using +# the `print` format and just wants to see the output in the action log. +echo "$OUTPUT" +# NOTE: Save the output to the `output` output of the action +echo -n "output=$OUTPUT" >> $GITHUB_OUTPUT From 3b1444256966fb3edb85022ef2ad953bd2552952 Mon Sep 17 00:00:00 2001 From: Spenser Black Date: Wed, 10 Jun 2026 13:29:13 +0000 Subject: [PATCH 2/2] Force empty string tokens to be `nil` Fixes an issue where a no permissions error would be raised if `GITHUB_TOKEN=""`. --- lib/github_polyglot/cli.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/github_polyglot/cli.rb b/lib/github_polyglot/cli.rb index 7efda5f..420bf6d 100644 --- a/lib/github_polyglot/cli.rb +++ b/lib/github_polyglot/cli.rb @@ -17,6 +17,7 @@ def run Dotenv.load token = ENV.fetch(GithubPolyglot::TOKEN_ENV_VAR, nil) + token = nil if token&.empty? @polyglot = GithubPolyglot.new(username: @username, token: token) output_format end