gpt4 book ai didi

github-actions - 如何在github Action 表达式中进行数学比较

转载 作者:行者123 更新时间:2023-12-05 05:58:18 27 4
gpt4 key购买 nike

对于 GitHub 操作工作流程,我想比较 if 条件中的两个变量以确定是否应运行某个步骤。但是,比较似乎是作为字符串比较发生的,例如,8060 的计算结果大于 65536。我如何强制将这些作为数学比较?

jobs:
generate-report:
runs-on: ubuntu-latest
name: Generate update review report
outputs:
update-report: ${{ steps.set-update-report.outputs.report }}
update-report-length: ${{ steps.set-update-report.outputs.length }}
steps:
- name: Get depdive update report
id: set-update-report
run: |
output="$(depdive update-review paths ./base/ ./)"
echo "::set-output name=report::${output}"
length=$(echo ${output} | wc -c )
echo "::set-output name=length::${length}"


make-pr-comment:
runs-on: ubuntu-latest
name: Comment on PR
needs: generate-report
env:
MAX_ALLOWED_CHARS: 65536
steps:
- name: make valid comment
if: ${{ needs.generate-report.outputs.update-report && needs.generate-report.outputs.update-report-length < env.MAX_ALLOWED_CHARS }}
# expects mathematical comparison here
run: |
echo "valid"
- name: make comment when output too big
if: ${{ needs.generate-report.outputs.update-report && needs.generate-report.outputs.update-report-length >= env.MAX_ALLOWED_CHARS }}
# expects mathematical comparison here
run: |
echo "invalid"

最佳答案

Context and expression syntax for GitHub Actions / Operator”文档指出:

If the types do not match, GitHub coerces the type to a number.

因此,尽量使用数字字面量:

if {{ aVariable + 0 < anotherVariable + 0 }}

关于github-actions - 如何在github Action 表达式中进行数学比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68553401/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com