我有一个 github 操作,我有一个这样的单词列表:
'["alpha", "beta", "preview", "experiment"]'
我有一个像这样的后缀字符串:
suffix = steps.get-version.outputs.version-suffix
现在我想检查列表中的任何单词是否存在于后缀中? 目前我正在使用这个:
- run: echo "IS_PRE_RELEASE=true" >> $env:GITHUB_ENV
if: contains(fromJson('["alpha", "beta", "preview", "experiment"]'), steps.get-version.outputs.version-suffix)
但是有一个问题:
如果
suffix = beta
output: IS_PRE_RELEASE updated to true
如果
suffix = beta1
output: IS_PRE_RELEASE does not set
所以问题是,仅接受beta(alpha,...),不接受其他类型的字符串(beta1,beta.1,....)
我尝试将
contains
更改为 startsWith
但我得到了相同的结果。
我该如何解决这个问题?
如果您在操作中使用 Windows 操作系统,则可以使用 powershell 命令:
名称:运行PowerShell脚本 运行: | # 定义字符串列表 $list = @("测试版", "阿尔法", "预览版")
# Define the suffix variable
$suffix = "Beta134"
# Loop through the list and check if the suffix starts with any item
foreach ($item in $list) {
# Convert both strings to lower case for case-insensitive comparison
if ($suffix.ToLower().StartsWith($item.ToLower())) {
# Set the PREX environment variable to true and exit the loop
echo "IS_PRE_RELEASE=true" >> $env:GITHUB_ENV
break
}
}