我正在为 Selenium 网格实例创建一个操作,只有当 $READY 返回 false 时它才会退出,$READY 为 true 并且我们仍然得到失败的作业!
- name: Get Selenium Grid status variables
run: |
echo "READY=$(cURL 'http://localhost:4444/status' | jq '.value.ready')" >> $GITHUB_ENV
NODE_COUNT=$(cURL 'http://localhost:4444/status' | jq '.value.nodes' | jq 'length')
- name: (DEBUG) Print variables
env:
ENV_CONTEXT: ${{ toJson(env) }}
STEP_CONTEXT: ${{ toJson(steps) }}
run: |
echo "$READY" # true
echo "${{env.READY}}" # true
cURL http://localhost:4444/status
- name: Confirm Grid is up
if: ${{ env.READY }} == true
run: echo "Selenium Grid is Ready"
- name: Exit if Grid is down
if: ${{ env.READY }} != true
run: echo "Selenium Grid wasn't ready, ending action" && exit 1
如有任何帮助,我们将不胜感激
如果相关的话,跑步者也是 Macmini
您必须使用 @GuiFalourd 提到的
if: ${{ env.READY == 'true' }}
和 if: ${{ env.READY != 'true' }}
。
我也想发表一下我的意见,在复杂的github工作流程中存储环境变量不容易管理,如果我出错了,必须重新编辑工作流程文件,再次测试工作流程。通常我会将其包装到
bash
脚本来运行复杂的作业。
作为例子
name: Test
on:
workflow_dispatch
jobs:
testing:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Validating Task
run: |
# Run some validation task, then store at $GITHUB_ENV
echo "READY=true" >> $GITHUB_ENV
- name: Execute task if ready
if: ${{ env.READY == 'true' }}
run: |
echo "Executing task !"
bash ./tools.sh update
id
- name: Execute task if not ready
if: ${{ env.READY != 'true' }}
run: |
echo "Not ready!"
bash ./tools.sh notify
id
我还在 github 代码空间中使用 https://github.com/nektos/act 测试工作流程文件。
只需安装并运行
act -W test.yaml
输出:
@anasfanani ➜ /workspaces/act (master) $ act -W test.yaml
INFO[0000] Using docker host 'unix:///var/run/docker.sock', and daemon socket 'unix:///var/run/docker.sock'
[Greeting on variable day/testing] 🚀 Start image=catthehacker/ubuntu:act-latest
INFO[0000] Parallel tasks (0) below minimum, setting to 1
[Greeting on variable day/testing] 🐳 docker pull image=catthehacker/ubuntu:act-latest platform= username= forcePull=true
[Greeting on variable day/testing] using DockerAuthConfig authentication for docker pull
INFO[0002] Parallel tasks (0) below minimum, setting to 1
[Greeting on variable day/testing] 🐳 docker create image=catthehacker/ubuntu:act-latest platform= entrypoint=["tail" "-f" "/dev/null"] cmd=[] network="host"
[Greeting on variable day/testing] 🐳 docker run image=catthehacker/ubuntu:act-latest platform= entrypoint=["tail" "-f" "/dev/null"] cmd=[] network="host"
[Greeting on variable day/testing] ⭐ Run Main actions/checkout@v4
[Greeting on variable day/testing] 🐳 docker cp src=/workspaces/act/. dst=/workspaces/act
[Greeting on variable day/testing] ✅ Success - Main actions/checkout@v4
[Greeting on variable day/testing] ⭐ Run Main Validating Task
[Greeting on variable day/testing] 🐳 docker exec cmd=[bash --noprofile --norc -e -o pipefail /var/run/act/workflow/1] user= workdir=
[Greeting on variable day/testing] ✅ Success - Main Validating Task
[Greeting on variable day/testing] ⚙ ::set-env:: READY=true
[Greeting on variable day/testing] ⭐ Run Main Execute task if ready
[Greeting on variable day/testing] 🐳 docker exec cmd=[bash --noprofile --norc -e -o pipefail /var/run/act/workflow/2] user= workdir=
| Executing task !
| TOOLS SH CALLED
| uid=0(root) gid=0(root) groups=0(root)
[Greeting on variable day/testing] ✅ Success - Main Execute task if ready
[Greeting on variable day/testing] Cleaning up container for job testing
[Greeting on variable day/testing] 🏁 Job succeeded
@anasfanani ➜ /workspaces/act (master) $