Github Actions复用工作流无法检出仓库及调用脚本求助
问题原因
被调用工作流中的actions/checkout@v3默认只会检出触发当前工作流的仓库(即actions_param),而xml-functions.ps1实际存储在包含被调用工作流的betech仓库里,因此脚本路径${{ github.workspace }}\betech\scripts不存在,导致报错。
解决方案
有两种可行的修改方式,任选其一即可:
方式1:指定检出betech仓库到指定路径
修改被调用工作流extractxmldata.yml中的actions/checkout@v3步骤,明确指定要检出的仓库和路径:
jobs: Extract-keys: runs-on: 'windows-latest' steps: - uses: actions/checkout@v3 with: repository: ${{ github.repository }} # 动态获取当前被调用工作流所属的仓库(即betech) ref: ${{ github.ref }} # 动态获取当前分支(即feature365) path: betech # 将仓库检出到github.workspace/betech目录下 - name: Get present dir run: | Get-Location - name: List dir run: | dir - name: Call power shell for extract XML values run: | set-location "${{ github.workspace }}\betech\scripts" ./xml-functions.ps1 "${{ inputs.xml_Path }}" "${{ inputs.key_name }}"
方式2:直接检出betech仓库到当前工作目录
如果不需要保留调用方仓库的代码,可以直接将betech仓库检出到默认工作目录,简化脚本路径:
jobs: Extract-keys: runs-on: 'windows-latest' steps: - uses: actions/checkout@v3 with: repository: ${{ github.repository }} ref: ${{ github.ref }} - name: Get present dir run: | Get-Location - name: List dir run: | dir - name: Call power shell for extract XML values run: | ./scripts/xml-functions.ps1 "${{ inputs.xml_Path }}" "${{ inputs.key_name }}"
补充说明
${{ github.repository }}和${{ github.ref }}是GitHub Actions内置变量,能动态获取当前被调用工作流所属的仓库和分支,避免硬编码仓库名、分支名,提升配置灵活性。- 两种方式都能确保
xml-functions.ps1被正确检出到Runner环境中,彻底解决路径不存在的问题。
内容的提问来源于stack exchange,提问作者Ashar
相关产品推荐
相关产品推荐

