Skip to content
 
 

Latest commit

 

History

100 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Code Analyzer

A GitHub Action that counts the lines of code in the repository it lives in and writes a language breakdown into that repo's README. Runs on a schedule (and on push to main), needs no Personal Access Token, and never looks at any other repo.

This is a repo-local fork of arhamkhnz/github-code-analyzer. The upstream tool scans every public repo on your account and reports one account-wide total, which needs a broad repo-scoped PAT. This version counts only the repo it is installed in, using the runner's built-in GITHUB_TOKEN — so there is nothing to set up beyond enabling write permissions for Actions.

[ LANGUAGES BREAKDOWN ]


[ TOTAL LINES OF CODE: 0 ]

Filled in automatically the first time the workflow runs.

How It Works

This GitHub Action checks out the repository it is installed in, counts its lines of code with cloc via --vcs=git (so only git-tracked files count and .gitignore is honored — no node_modules, no build output), and rewrites the README.md breakdown between two markers. It runs every Sunday at midnight UTC, on push to main, and on manual dispatch. Because it only touches this one repo, it authenticates with the runner's built-in GITHUB_TOKEN and needs no Personal Access Token.

Usage

Setting Up the GitHub Action

  1. Add the Workflow File
    Copy the analyze-code.yml file into your repository at:

    .github/workflows/analyze-code.yml
    

    Then commit and push the changes.

  2. Allow Actions to write to the repo
    The workflow already declares permissions: contents: write, which is enough on its own. If your org sets Actions to read-only by default, also flip it at Settings → Actions → General → Workflow permissions → "Read and write permissions". No secret or token is required.

  3. Trigger the Workflow

    • It runs every Sunday at midnight UTC and on push to main.
    • To run manually, go to GitHub Actions → Select Workflow → Run Workflow.
  4. Wait for Processing
    Counting a single repository takes seconds. Once done, your README.md is updated with the latest lines of code breakdown.

  5. Ensure Placeholders Are Present
    To allow automatic updates, your README.md must include the following placeholders:

     <!-- LANGUAGES BREAKDOWN START -->
    
[ LANGUAGES BREAKDOWN ]

TypeScript   --> 338,462 lines
JavaScript   --> 123,742 lines
JSX          --> 20,576 lines
PHP          --> 5,248 lines
Others       --> 9,942 lines

[ TOTAL LINES OF CODE: 497,970 ]
<!-- LANGUAGES BREAKDOWN END -->
The workflow will update the stats between these markers.  
*Remove `(STATIC EXAMPLE)` when adding it in your README, as it's just a placeholder. It's included here only to prevent automatic updates in this README.*

### Configure languages

The workflow uses cloc **language names** (not file extensions).

- **HIGHLIGHT_LANGS** → languages shown individually in the README; everything else is grouped under **Others**  
- **IGNORE_LANGS** → languages dropped completely (not shown, not counted)

Edit these in `.github/workflows/analyze-code.yml` under the job `env:` block:

```yaml
env:
# Use cloc LANGUAGE NAMES (not extensions). Example: "Vuejs Component" for .vue, "C#" for C#
# HIGHLIGHT_LANGS: show these languages individually; everything else goes to "Others"
HIGHLIGHT_LANGS: "JavaScript,TypeScript,JSX,Vuejs Component,PHP,C#"

# IGNORE_LANGS: drop these languages entirely (not shown and not counted)
IGNORE_LANGS: "JSON,HTML,CSS,SCSS,Sass,Markdown,SVG,XML,YAML,TOML,CSV,Text,Properties"

Configure Language Detection

The workflow counts only git-tracked files and excludes languages using cloc’s own filter, so totals match cloc’s SUM:

cloc --vcs=git --json --report-file=output/cloc-output.json --exclude-lang="${IGNORE_LANGS}"

--vcs=git runs git ls-files under the hood, which is what keeps the count to this repository's tracked source and honors .gitignore. For a complete list of language names supported by cloc, see the cloc documentation.

Contributing

Contributions are welcome! Feel free to fork the repository, submit a PR, or open an issue.

About

Code Analyzer for GitHub automatically retrieves all your repositories, analyzes code using CLOC, and updates statistics. It provides a detailed breakdown of the number of lines per language across your repositories and refreshes the README file accordingly.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors