DEV Community

Cover image for How to change GitHub Actions run_number
Andrei Fedotov
Andrei Fedotov

Posted on • Updated on

How to change GitHub Actions run_number

Hello everyone!

What we have

We use the well-known schema for versioning the product builds:


For example: 3.2.1234.0.

We use GitHub Actions for CI/CD needs. We use GitHub's run_number value as a build number.

The challenge

Recently we faced a challenge to set an offset for different types of build (e.g. production/test builds).

Searching over the internet had a lack of answers to the question of how to change run_number or how to increment it.

The solution

After a good bit of time spent on documentation investigation, we came up with a solution. Assume run_number is 1000. And we want the build number to be 5000. And the final product version we want to have 3.2.5000.0 We can do the following as separate step in the workflow:

    - name: Set version number
      run: |
        $version = "3.2."+(4000+$($Env:GITHUB_RUN_NUMBER))+".0"
        echo $version
        echo "VERSION_NUMBER=$version" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
Enter fullscreen mode Exit fullscreen mode

That's it. Now the variable VERSION_NUMBER contains the value 3.2.5000.0.

And we can use that value across the workflow like this (e.g. we construct installer package name that containing the version):

MyProduct.${{ env.VERSION_NUMBER }}.msi.

Hope this would be helpful for you.


Top comments (2)

antebios profile image
Richard Nunez

Why not just use the GitVersion action? It produces the same Semantic versioning that you are looking for, but this time it uses your git history and tags to produce a versioning system. You want a new major version? Just create a git tag. You did a commit on a dev branch? It's automatically a pre-release. You want to make it an official release? Just tag it. And let your CI/CD pipeline do the rest.

step 1 - setup:

  • name: Install GitVersion uses: gittools/actions/gitversion/setup@v0.9.7 with: versionSpec: '5.5.0'

step 2 - execute:

  • name: Run GitVersion uses: gittools/actions/gitversion/execute@v0.9.13 with: useConfigFile: true configFilePath: GitVersion.yml

Notice that I declared a GitVersion.yml file at the base of my repo with the following one line content: "mode: ContinuousDeployment". This config file is optional. It will produce MANY variables that you can use throughout your pipeline process across multiple jobs.

Read more here:

andreisfedotov profile image
Andrei Fedotov

It looks very interesting, thank you for sharing!