GitHub跨仓库PR触发Playwright测试遇Artifact下载错误求助
跨仓库获取GitHub Action工件的解决方案
你遇到的错误根源是:你用的View Test Results Action根本不支持repository这个输入参数,而官方默认的actions/download-artifact也只允许在同仓库内下载工件。下面是几个能实现跨仓库访问工件的可行方案:
方案一:用GitHub API手动下载
生成一个带有repo权限的Personal Access Token(PAT),把它存在应用仓库(kegthat-headless)的Secrets里,命名为REPO_ACCESS_TOKEN。然后在应用仓库的Action中用GitHub CLI下载测试仓库的工件。
示例代码:
- name: 安装GitHub CLI run: sudo apt-get install gh -y - name: 下载最新Playwright测试报告 env: GH_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} run: | # 获取最新的playwright-report工件ID ARTIFACT_ID=$(gh api repos/你的用户名/kegthat-automation-tests/actions/artifacts \ --jq '.artifacts[] | select(.name == "playwright-report") | .id' | head -n1) # 下载工件压缩包 gh api repos/你的用户名/kegthat-automation-tests/actions/artifacts/$ARTIFACT_ID/zip \ --output playwright-report.zip # 解压报告 unzip playwright-report.zip
方案二:测试仓库跑完后同步报告到应用仓库PR分支
在测试仓库(kegthat-automation-tests)的Action里,跑完测试后直接把playwright-report推送到应用仓库对应的PR分支,这样应用仓库的Action就能直接读取本地文件。
测试仓库Action添加同步步骤:
- name: 推送测试报告到应用仓库PR分支 env: GH_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} PR_NUMBER: ${{ github.event.inputs.pr_number }} # 从应用仓库触发时传入PR号 run: | git clone https://x-access-token:${GH_TOKEN}@github.com/你的用户名/kegthat-headless.git cd kegthat-headless git checkout refs/pull/$PR_NUMBER/head rm -rf playwright-report cp -r ../playwright-report . git config user.name "GitHub Action" git config user.email "action@github.com" git add playwright-report git commit -m "同步Playwright测试报告到PR #$PR_NUMBER" git push
应用仓库Action触发测试时传入PR号:
- name: 触发自动化测试工作流 uses: benc-uk/workflow-dispatch@v1 with: repo: 你的用户名/kegthat-automation-tests workflow: 你的Playwright测试工作流名称 token: ${{ secrets.REPO_ACCESS_TOKEN }} inputs: '{"pr_number": "${{ github.event.pull_request.number }}"}'
方案三:用支持跨仓库的第三方下载Action
使用dawidd6/action-download-artifact这个第三方Action,它明确支持repo参数,能直接跨仓库下载工件。
应用仓库Action中的示例代码:
- name: 跨仓库下载Playwright测试报告 uses: dawidd6/action-download-artifact@v2 with: name: playwright-report repo: 你的用户名/kegthat-automation-tests workflow: 你的Playwright测试工作流名称 token: ${{ secrets.REPO_ACCESS_TOKEN }} path: ./playwright-report
内容的提问来源于stack exchange,提问作者Ben
相关产品推荐
相关产品推荐

