Creates a new tag using the format Y.M.D
(using daily-version), but only if HEAD
isn’t already tagged.
Ideally used on schedule, but you could also change the suggested condition to only make it run on main
.
See usage real-world example on Refined GitHub’s repo
It expects git
to be configured to push to the same repo. The v2
and later of actions/checkout
automatically sets required token and, if not set, this action will use the git user daily-version-action <[email protected]>
to create the tag. This can be customized with something like setup-git-token.
See action.yml
Version:
steps:
- uses: actions/checkout@v4
- name: Create tag if necessary
uses: fregante/daily-version-action@v2
You can use the DAILY_VERSION_CREATED
and DAILY_VERSION
environment variables created by this action to test whether a new version has been created:
- name: Create tag if necessary
uses: fregante/daily-version-action@v2
- name: Created?
if: env.DAILY_VERSION_CREATED
runs: echo "Yes, created $DAILY_VERSION"
If you prefer, you can use its outputs too, which can also work across jobs:
- name: Create tag if necessary
id: version
uses: fregante/daily-version-action@v2
- name: Created?
if: steps.version.outputs.created
runs: echo "Created ${{ steps.version.outputs.version }}"
prefix
- Optional. You can specify what to prefix the tag name with. For example:
Version:
steps:
- uses: actions/checkout@v4
- name: Create tag if necessary
uses: fregante/daily-version-action@v2
with:
prefix: v # This will cause the tags to start with v, like "v20.12.31`
created
- If this output exists, this action created a new tag.version
- The latest tag, whether it already existed or if it just created one.
Outputs can be used across jobs as well.
Here's a complete workflow to create a nightly release, when necessary: (original here)
on:
schedule:
- cron: '59 23 * * *'
jobs:
Tag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: fregante/daily-version-action@v2
name: Create tag if necessary
id: daily-version
outputs: # Shares the action’s outputs to the Next jobs
created: ${{ steps.daily-version.outputs.created }}
version: ${{ steps.daily-version.outputs.version }}
Next:
needs: Tag
if: needs.Tag.outputs.created
runs-on: ubuntu-latest
steps:
- run: echo It looks like ${{ needs.Tag.outputs.version }} was created!
- 🛕 action-release - A workflow to help you release your actions.
- title-to-labels-action - Cleans up the titles of issues and PRs from common opening keywords.
- setup-git-user - GitHub Action that sets git user and email to enable committing.