Search code examples
tagsgithub-actionsversioning

Bump date-based tag in GitHub Actions


I'm trying to create automatic releases of a project using GitHub Actions where the release tag is based on the date. I don't want to use standard semantic versioning because this project is a fork of another project that uses date-based versioning. I've found posts about the getting the date in a workflow and have this so far:

name: Publish

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  publish:
    name: Publish release of font files
    runs-on: ubuntu-latest
    steps:
      - name: Create foo file
        run: |
          mkdir cascadios
          > cascadios/foo.txt
          
      - name: Get tag name from date
        id: tag_name
        run: echo "::set-output name=date::$(date +'%y%m.%d')"

      - name: Zip font files
        run: |
          cd cascadios
          zip ../cascadios-${{ steps.tag_name.outputs.date }}.zip *
          cd ..

      - name: Create tag
        uses: mathieudutour/github-tag-action@v6.0
        id: tag_version
        with:
          github_token: ${{ github.token }}
          custom_tag: ${{ steps.tag_name.outputs.date }}

Note: I have it creating a blank file to release to save the 15 minutes of building.

This works great until I have two releases in one day (such as today where I am testing this workflow a lot). How can I get it so I can add a dynamic patch number to the tag, so it doesn't cause a conflict? An example might look like v2112.13.0.


Solution

  • You can use our versioning library - https://github.com/relizaio/versioning

    Then you can declare version pattern to be something like: YYYY.0M.0D.Micro

    Then the following command would produce a base version:

    docker run --rm relizaio/versioning -s YYYY.0M.0D.Micro
    

    Now, if you already have a version say 2021.12.14.1 and want to bump it up, you would do

    docker run --rm relizaio/versioning -s YYYY.0M.0D.Micro -v 2021.12.14.1 -a bump
    

    This would produce 2021.12.14.2 if you call it on December 14th, or something 2021.12.15.0 if you call this command on the December 15th.