Wow*_*nch 24 github github-api github-actions
我有一个用于发布存储库夜间快照的 GitHub 工作流程。它使用create-release 操作。这是工作流文件现在的样子:
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
Run Code Online (Sandbox Code Playgroud)
我想要tag_name
并release_name
使用当前日期和时间,而不是硬编码值。但是,我找不到任何关于它的文档。我该怎么做?
Ber*_*tel 49
从这篇文章中,您可以创建一个步骤,用值设置其输出$(date +'%Y-%m-%d')
然后使用此输出使用${{ 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 "::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 }}
Run Code Online (Sandbox Code Playgroud)
输出:
* Test with environment variables
nightly-tag-2020-03-31 - nightly-release-2020-03-31
* Test with input
Hello Mona-the-Octocat-2020-03-31
Run Code Online (Sandbox Code Playgroud)
130*_*agR 31
一个干净的解决方案是使用 ${{ github.event.repository.updated_at}}
非常接近当前日期时间的$(date +%Y%m%d%H%M)
格式为ISO 8601
\ne.g 2022-05-15T23:33:38Z
优点:
\n缺点:
\necho ${{ github.event.repository.updated_at}} | sed \'s/:/./g\'
参考文献:
\n Github 上下文
\n事件对象
cre*_*ers 14
这是通过环境变量执行此操作的另一种方法(来自这篇文章):
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
Run Code Online (Sandbox Code Playgroud)
这将日期设置为环境变量,如果您想在后续步骤的脚本/程序中使用它,这将非常有用。
更新
该set-output
命令已弃用并将很快被禁用。请升级为使用环境文件。
文档可以在这里找到
name: deploy
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Get current date
id: date
run: |
echo "{date}={$(date +'%Y-%m-%d')}" >> $GITHUB_STATE
- name: Test with environment variables
run: echo $TAG_NAME - $RELEASE_NAME
env:
TAG_NAME: nightly-tag-${{ env.date }}
RELEASE_NAME: nightly-release-${{ env.date }}
Run Code Online (Sandbox Code Playgroud)
# Set the date time
- name: Retrieve current Date Time in Singapore TimeZone
shell: bash
run: echo "START_TIME=$(TZ=":Asia/Singapore" date -R|sed 's/.....$//')" >> $GITHUB_ENV
# Fetch the date time as Github ENV variable
- name: print date
run: echo ${{ env.START_TIME }}
Run Code Online (Sandbox Code Playgroud)
输出-
Mon, 21 Aug 2023 15:34:24
Run Code Online (Sandbox Code Playgroud)
**您可以根据需要更改时区
归档时间: |
|
查看次数: |
10368 次 |
最近记录: |