Github action未上传构建产物。

3

我在workflow中上传artifacts到github时遇到了问题。

这是我的yaml文件:


on:
  push:
      branches:
      - master

jobs:
    build:
      name: build and test
      runs-on: ubuntu-latest

      steps:
        - uses: actions/checkout@v1
        - name: Install robotframework and dependencies
          run: |
            pip install selenium
            pip install robotframework
            pip install robotframework-seleniumlibrary
            pip install robotframework-imaplibrary
            pip install robotframework-httplibrary
            pip install robotframework-requests
        - name: Download and install chromedriver
          run: |
            wget http://chromedriver.storage.googleapis.com/77.0.3865.10/chromedriver_linux64.zip
            sudo unzip chromedriver_linux64.zip -d /usr/local/bin
            export CHROME_BIN=chromium-browser
        - name: Run robot tests
          run: |
            cd robot/tests
            python -m robot -i ready bookingform.robot
        - name: publish test results
          uses: actions/upload-artifact@v1
          with:
            name: report
            path: report.html
        - name: clean up stuff
          run: |
            history
            pwd

在"发布测试结果"之前,一切都运行良好,但是在此时没有任何东西被写入日志,也没有上传任何工件。如果我查看工作流程日志,该步骤旁边会出现一个灰色图标(不是通常的检查或红色X),所以我真的很困惑发生了什么。 我添加了任意内容到“清理内容”步骤中,只是为了测试会发生什么,但是那一步也没有运行。
我尝试调整路径,认为可能与路径无效有关,但是这并没有帮助。无论我在文件底部添加什么,都会出现相同的行为。
我尝试运行另一个上传工件的工作流程文件,那个文件运行良好,日志显示上传操作被调用并保存了工件,但是当使用我的yaml文件时,我看不到类似的情况发生。

1
当我在上传构件时遇到问题时,我使用了 ls -la 命令来打印目录内容。也许你可以在 运行机器人测试 步骤中尝试一下这个命令,以确保你正在处理正确的目录结构? - bradj
3
记住,在每个步骤中,你都会被放回到根工作流目录;在发布步骤中,你不再处于 robot/tests/ 目录下。 - Samira
1
谢谢@Samira,那给了我一些指示。我也意识到另外一件事情;如果出现故障,步骤将被跳过,因此我在相关步骤中添加了if:always(),似乎解决了问题。 - Jason
2个回答

7

每个作业步骤都会重置工作路径为 GITHUB_WORKSPACE,在 actions/checkout 运行后,它将成为您的存储库根目录。

upload-artifact 动作最可能找不到 report.html,因为它不再位于正确的目录中。

请尝试按以下方式更改路径:

        - name: publish test results
          uses: actions/upload-artifact@v1
          with:
            name: report
            path: robot/tests/report.html

还有一个working-directory可以设置步骤的工作目录。但是,它似乎与使用操作uses不兼容。它只能应用于运行脚本步骤。

uses中使用working-directory无法生效:

        - name: publish test results
          working-directory: robot/tests
          uses: actions/upload-artifact@v1
          with:
            name: report
            path: report.html

使用run指令搭配working-directory选项可以正常工作:

        - name: print test results
          working-directory: robot/tests
          run: cat report.html

0

如果之前的任务失败了,那么后续的任务将不会被执行;请参考状态检查函数

使用if: ${{ failure() }},只有在前一个任务失败时,当前任务才会被执行。

因此,对我来说,添加if: ${{ failure() }}解决了问题:

      - name: Upload Cypress Artifacts
        if: ${{ failure() }}
        uses: actions/upload-artifact@v3
        with:
          path: ./cypress

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接