在GitHub动作中使用date作为ENV变量

编程入门 行业动态 更新时间:2024-10-27 12:37:28
本文介绍了在GitHub动作中使用date作为ENV变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是一个非常有趣但令人沮丧的问题.我正在使用一个ENV变量,它指定日期.我提供了符合ISO 8601的版本,在应用程序中,我对其进行检索和解析.当我在GH action工作流程中指定它时,它将被解析为日期(而不是字符串)并进行格式化.因此,我的应用程序解析失败.

This is very funny but very frustrating problem. I am using an ENV variable, which specifies date. I provide an ISO 8601 compliant version and in application, I retrieve it and parse. When I specify it in GH action workflow, it is get parsed as a date (rather than a string) and formatted. Therefore, my application parsing fails.

示例:.github/workflows/rust.yaml

Example: .github/workflows/rust.yaml

env: MY_DATE: '2020-10-07T12:00:00+01:00' run: echo $MY_DATE

结果(GH操作界面):

Result (GH action UI):

env: TMOU_GAME_END: 10/07/2020 11:00:00 10/07/2020 11:00:00

它特定于GitHub动作及其yaml解析,可在Heroku,各种本地设置等上正常运行.

It is specific to GitHub action and their yaml parsing, it works OK on Heroku, on various local setups, etc.

我尝试过但无法使用的东西:

Things I tried and they don't work:

  • 不使用引号,单引号('),双引号(')
  • 将另一个ENV变量LC_TIME设置为en_DK.UTF-8
  • 使用!! str的简写形式(请参见 yaml/spec/1.2/spec.html ,示例2.23.各种显式标签);此操作失败并显示工作流程无效..github/workflows/rust.yml:意外标签'tag:yaml,2002:str'或使用工作流程无效..github/workflows/rust.yml:标量样式'DoubleQuoted |第29行和第24列上的单引号"对标签'tag:yaml,2002:str'
  • 无效
  • using no quotes, single quotes ('), double quotes (")
  • setting another ENV var, LC_TIME to en_DK.UTF-8
  • using !!str shorthand (see yaml/spec/1.2/spec.html, section Example 2.23. Various Explicit Tags); this one fails either with  The workflow is not valid. .github/workflows/rust.yml: Unexpected tag 'tag:yaml,2002:str' or with The workflow is not valid. .github/workflows/rust.yml: The scalar style 'DoubleQuoted | SingleQuoted' on line 29 and column 24 is not valid with the tag 'tag:yaml,2002:str'

有什么帮助吗?我可以打开任何秘密参数吗?有任何转义序列吗?我只是想用GH Actions yaml解析器将值视为字符串.

Is there any help? Any secret parameter I can turn on? Any escaping sequence? I just wanna GH Actions yaml parser to treat the value as a string.

推荐答案

令人惊讶的是,似乎GitHub Actions工作流YAML解析器没有完全实现该标准,使用显式键入(如 !! str )确实可以实现不行.但是,您可以通过以下方式解决此问题:将环境变量设置为所需的值,而不是在YAML文件本身中,而是使用专用工作流程命令:

Surprisingly, it seems GitHub Actions workflow YAML parser does not fully implement the standard and using explicit typing (like !!str) does not work. You can, however, workaround it by setting the environment variable to the desired value not in the YAML file itself but dynamically during a workflow execution using a dedicated workflow command:

steps: - name: Dynamically set MY_DATE environment variable run: echo "MY_DATE=2020-10-07T12:00:00+01:00" >> $GITHUB_ENV - name: Test MY_DATE variable run: echo ${{ env.MY_DATE }}

这应该可以解决问题.

更多推荐

在GitHub动作中使用date作为ENV变量

本文发布于:2023-11-23 17:33:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622305.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   动作   GitHub   ENV   date

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!