我有一个GitHub工作流,用于发布存储库的每晚快照。它使用the create-release action。这是工作流文件现在的外观:
name: Release Nightly Snapshot
on:
schedule:
- cron: "0 0 * * *"
jobs:
build:
name: Release Nightly Snapshot
runs-on: ubuntu-latest
steps:
- name: Checkout master Branch
uses: actions/checkout@v2
with:
ref: 'master'
- name: Create Release
id: nightly-snapshot
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: 'nightly snapshot'
release_name: 'nightly snapshot'
draft: false
prerelease: false
我希望tag_name
和release_name
使用当前日期和时间,而不是硬编码值。但是,我找不到任何文档。我该怎么办?
答案 0 :(得分:15)
在this post中,您可以创建一个值为$(date +'%Y-%m-%d')
的步骤set its output
然后使用${{ steps.date.outputs.date }}
使用此输出。下面显示了环境变量和输入的示例:
on: [push, pull_request]
name: build
jobs:
build:
name: Example
runs-on: ubuntu-latest
steps:
- name: Get current date
id: date
run: echo "name=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
- 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 }}
输出:
* Test with environment variables
nightly-tag-2020-03-31 - nightly-release-2020-03-31
* Test with input
Hello Mona-the-Octocat-2020-03-31
答案 1 :(得分:9)
这是通过环境变量(来自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
这会将日期设置为环境变量,如果您想在后续步骤中在脚本/程序中使用它,这将很有用。