How to set a date as tag in release-action?

I would like to set a date as tag in the release-action. But how?
This does not work:

    steps:
      - uses: ncipollo/release-action@v1
        with:
          artifacts: "my-artifact.zip"
          tag: ${{ env.NOW }}
          token: ${{ secrets.GITHUB_TOKEN }}
        env:
          NOW: $(date +'%Y-%m-%dT%H:%M:%S')

I get these errors:
Errors:

  • tag_name is not a valid tag
  • tag_name is not well-formed
  • Published releases must have a valid tag

You can’t use shell syntax in the env: definition. What you can do is use a set-env command in a previous step:

- name: set NOW
  run: |
    echo "::set-env name=NOW::$(date +'%Y-%m-%dT%H:%M:%S')"

After that env.NOW will be available. Note however that there’s a currently open bug that may lead to the date being reformatted, a workaround has been discussed on this forum: ISO 8601 string in job output is automatically parsed

1 Like

Did not work. Getting the same validation errors.
How do I have to reference variable NOW in tag property?

${{ env.NOW }}?
${{ NOW }}?
$NOW?
${{ $NOW }}?

${{ env.NOW }} should work, yes. Mind that it the step using the variable must be a separate step after the one setting the environment variable. Saying more about possible reasons isn’t really possible without the workflow code, I’m afraid.

@mwalter,

The expression syntax ${{ env.NOW }} is an correct way to access the custom env, just like @airtower-luna has suggested.

steps:
  - name: set env
    run: echo "::set-env name=NOW::$(date +'%Y-%m-%dT%H:%M:%S')"

  - name: create release
    uses: ncipollo/release-action@v1
    with:
      artifacts: my-artifact
      tag: ${{ env.NOW }}
      token: ${{ secrets.GITHUB_TOKEN }}

This expression can correctly pass the value of env.NOW into the action “ncipollo/release-action@v1”.

The root cause of you still get the invalid tag_name error is that the format (DateTime) of the tag_name you set is not supported on GitHub.

Errors:
- tag_name is not a valid tag
- tag_name is not well-formed
- Published releases must have a valid tag

I tried to manually create a release, and I used the same date-time format to set the tag (e.g. 2020-06-22T02:11:39), then I got the “Invalid tag name” error.


I recommend that you can reference to the “Tagging suggestions” to name the release tag.

Okay, thanks a lot! I just changed the pattern to:

echo "::set-env name=NOW::v$(date +'%Y%m%d.%H%M%S')"

This way the date is accepted by the release-action tag. It looks like that which satisfies my needs: v20200623.092227