Videos
From this post you can create a step that set its output with the value $(date +'%Y-%m-%d')
Then use this output using ${{ steps.date.outputs.date }}. The following show an example for environment variables and for inputs :
on: [push, pull_request]
name: build
jobs:
build:
name: Example
runs-on: ubuntu-latest
steps:
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
- name: Test with environment variables
run: echo $TAG_NAME - $RELEASE_NAME
env:
TAG_NAME: nightly-tag-${{ steps.date.outputs.date }}
RELEASE_NAME: nightly-release-${{ steps.date.outputs.date }}
- name: Test with input
uses: actions/hello-world-docker-action@master
with:
who-to-greet: Mona-the-Octocat-${{ steps.date.outputs.date }}
Outputs :
* Test with environment variables
nightly-tag-2020-03-31 - nightly-release-2020-03-31
* Test with input
Hello Mona-the-Octocat-2020-03-31
Here's another way to do this via environment variables (from this post):
name: deploy
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Set current date as env variable
run: echo "NOW=$(date +'%Y-%m-%dT%H:%M:%S')" >> $GITHUB_ENV
- name: Echo current date
run: echo $NOW # Gives "2022-12-11T01:42:20"
This sets the date as an environment variable, which is useful if you want to consume it in scripts / programs in subsequent steps.
My experience has been the opposite of what was described here on the forum. When tested:
- If the release is created from "Draft a new release" button on the
/releasespage, both events will trigger, as the release goes from state "draft" to "published". - If the release is created by scripts like
release-it, bypassing "draft" stage and becoming "published" directly, onlyrelease:publishedwill trigger
So apparently a release can be published without being created. Weird indeed. I'd go with published.
In case you are trying to capture the creation and publishing of a release triggered from a Github Action into another workflow, then it is not gonna work.
The solution is to unify both workflows into a single one so that after the release is created the next workflow continues.
Source: https://twitter.com/ethomson/status/1183838077166477316
Example:
name: Create Release and Publish
# Trigger the create release workflow
on:
push:
tags:
- 'v*'
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
publish-gpr:
needs: release # After release is created then run the second workflow
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 10
registry-url: https://npm.pkg.github.com/
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}