A GitHub Actions equivalent to Azure DevOps Pipelines $(rev:r) revisions

The Issue

In Azure DevOps Pipelines there is a feature to dynamically configure the build number e.g. at the top of a YAML build add the following to get a version in the form 1.2.25123.1

name: $(major).$(minor).$(year:YY)$(dayofyear).$(rev:r)
  • Major & Minor are user created and managed variables
  • Year, Dayofyear and Rev are built in Azure DevOps pre-defined variables. The first two are obviously based on the current date, the rev is the number of times a pipeline has been run on the current date.

The problem is that there is no equivalent feature to name in GitHub Actions as build names/numbers are not really a thing in Actions.

However, there are use cases where you want to use some or part of this dynamic build number for other purposes such as version stamping a file.

The Solution

The date related parts of the build number are easy to recreate with PowerShell get-date,

The revision takes a bit more work, but can be done with more PowerShell and the GitHub CLI.

For the original version of this post see Richard Fennell's personal blog at A GitHub Actions equivalent to Azure DevOps Pipelines $(rev:r) revisions