我需要将 Windows 工作流程上的当前日期获取到环境变量中。
显然,这是行不通的:
- name: Set current date as env variable
run: echo "NOW=Get-Date -format "yyyy-MM-dd"" >> $GITHUB_ENV
我找到的所有示例都在 Linux 上运行:(
如何在 Windows 运行程序上执行此操作?
有一个简单的 GitHub Action,可以以指定格式返回当前日期和时间 - 当前日期时间。
例如:
- name: Test1
id: t1
uses: Kaven-Universe/github-action-current-date-time@v1
with:
format: "yyyy-MM-dd"
# Use the output from the `t1` step
- name: Output1
run: |
echo "The time was ${{ steps.t1.outputs.time }}"
echo "The year was ${{ steps.t1.outputs.year }}"
echo "The month was ${{ steps.t1.outputs.month }}"
echo "The day was ${{ steps.t1.outputs.day }}"
echo "The hours was ${{ steps.t1.outputs.hours }}"
echo "The minutes was ${{ steps.t1.outputs.minutes }}"
echo "The seconds was ${{ steps.t1.outputs.seconds }}"
echo "The milliseconds was ${{ steps.t1.outputs.milliseconds }}"
echo "The day_of_week was ${{ steps.t1.outputs.day_of_week }}"
echo "The week_of_year was ${{ steps.t1.outputs.week_of_year }}"
echo "The milliseconds_since_epoch was ${{ steps.t1.outputs.milliseconds_since_epoch }}"
上面的示例还演示了可用的操作输出。这些输出的值可以在当前作业中的其他步骤以及另一个作业中访问。有关更多详细信息,请参阅定义作业的输出。
- name: Put current date into a variable
run: |
$NOW=& Get-Date -format yyyy-MM-dd
echo "NOW=$NOW" >> $env:GITHUB_ENV