windows-latest 上的 GitHub Actions 工作流程中的退出命令

问题描述 投票:0回答:1

我正在尝试将一个简单的 GitHub Actions 工作流程从在

ubuntu-latest
上运行转换为
windows-latest

---
name: Run extract_members.py on a schedule

on:
  workflow_dispatch:
  schedule:
    - cron:  '0 6 * * *'

jobs:
  extract:
    runs-on: windows-latest
    steps:
      - name: Check out repo
        uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.12'
      - name: Install requirements
        run: pip install -r requirements.txt
      - name: Run script
        run: python github_actions_test.py
      - name: Commit and push if the data has changed
        run: |-
          git config user.name "Automated"
          git config user.email "[email protected]"
          git add -A
          git commit -m "Updated data" || exit 0
          git push
...

但是如果没有任何更改会提交工作流程错误,则具有以下信息:

The term 'exit' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

我认为

exit
是Windows Server上的合法命令,就像在Ubuntu上一样。我应该用什么来代替?

command-line github-actions windows-server
1个回答
0
投票
在 Windows 上运行使用 powershell 核心 (

pwsh

),而不是默认的 Windows 命令行。

因此,这行内容可能应该是这样的:

& git commit test if ($LASTEXITCODE -ne 0) { exit 0; }
其中 

exit 0;

 也可以是 
return;
 以跳过脚本的其余部分。

如果你想将其作为 Windows shell 脚本运行,请添加:

- name: Commit and push if the data has changed run: |- git config user.name "Automated" git config user.email "[email protected]" git add -A git commit -m "Updated data" || exit 0 git push shell: cmd # <-- Specify the Windows Commandline explicitly
    
© www.soinside.com 2019 - 2024. All rights reserved.