[英]How to test input that should fail for a custom GitHub action in a workflow?
我有一個自定義的 GitHub 操作,它使用 Dockerfile 封裝了一個 linter。在推送時,我想驗證 linter 是否正常工作,即它應該在正確輸入時成功並在錯誤輸入時失敗:
name: Test Action
on:
workflow_dispatch:
push:
branches:
- master
jobs:
test-correct:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Lint correct input
uses: ./
with:
file: should-succeed.ex
test-incorrect:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Lint incorrect input
uses: ./
with:
file: should-fail.ex
但是,在 GitHub 下,例如https://github.com/myorg/myrepo/actions/runs/123456789 ,這當然會將成功的作業着色為綠色,將不成功的作業着色為紅色。 我如何告訴 GitHub 反轉顏色,以便失敗導致成功,成功導致失敗?
編輯:我嘗試了以下但它不起作用,因為那樣的話if: failure()
將不會觸發:
[...]
- name: Lint incorrect input
uses: ./
continue-on-error: true
with:
file: should-fail.ex
- if: failure()
run: true
- if: success()
run: false
另一方面,如果我刪除continue-on-error: true
行,那么它也不會工作,因為即使我返回 true,整個作業也會被計為失敗。
jobs:
test-correct:
[...]
test-incorrect:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: This should fail
id: lint-incorrect
uses: ./
continue-on-error: true
with:
file: should-fail.ex
- name: Invert success and failure
run: if [[ ${{ steps.lint-incorrect.outcome }} == "failure" ]]; then exit 0; else exit 1; fi
將continue-on-error: true
與不隨continue-on-error
改變的outcome
屬性結合使用似乎可以解決問題。 現在唯一缺少的是我只想將退出代碼 2(驗證錯誤)報告為成功,同時將退出代碼 1(運行時錯誤)保持為錯誤,但這似乎無法通過此方法實現。
有不同級別的測試:系統、集成、系統。
您的方法 - 它正在 GitHub 上運行系統測試。明顯的缺點是您無法在本地測試您的操作,並且您有一個很長的反饋循環提交並將每個更改推送到回購協議,錯誤的嘗試使其膨脹。
我在文章中描述了我的方法。 主要思想是:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.