Skip to content

Today I learned

How do I version builds by git commit count in GitHub Actions?

· updated #DevOps and tooling #Game development

I wanted versions nobody has to bump: <major.minor>.<commits>, the line from package.json, the patch from git rev-list --count HEAD. On CI every build came out as 0.1.1: actions/checkout clones with fetch-depth: 1, so there is one commit to count.

Fetch the whole history without file contents, which stays fast:

yaml
- uses: actions/checkout@v5
  with: { fetch-depth: 0, filter: "blob:none" }
- id: version
  run: |
    line=$(jq -r '.version | split(".")[:2] | join(".")' package.json)
    echo "game=$line.$(git rev-list --count HEAD)" >> "$GITHUB_OUTPUT"
  1. Docker has no .git. Count in the workflow, pass build-args: GAME_VERSION=${{ steps.version.outputs.game }}, read it with ARG GAME_VERSION.
  2. Guard against shallow clones. If git rev-parse --is-shallow-repository says true, fail or show <line>-dev, never a wrong number.
  3. A desktop client gets its own counter: <line>.${{ github.run_number }}, written into the app's package.json before packaging. A re-run keeps the same number.

Set this up for my Electron game on Steam: settings now show game: 0.1.191, steam: 0.1.30, patch: 5d4112a, and every bug report carries all three.

Docs: actions/checkout

The 30-second version

Share LinkedIn Post on X

Related notes

Newsletter

Occasional notes on engineering, game tech, and new tools — no spam, unsubscribe anytime.

Ravy

Engineering manager, founder, and software developer building web platforms, game systems, real-time services, and automation tools. 15 years of shipped work — currently at Gaijin.net.

Get in Touch

Building an MVP, shipping a game feature, or automating a team workflow? Open source or paid — let's talk.

Contact Me
© 2020-2026 XPLOIT FZE. All trademarks, names and logos belong to their respective copyright holders.