我正在使用github操作,在我的测试中,当我的代码覆盖率低于80%时,我需要让myt构建失败。我在github市场上查找了一些github动作,但什么也找不到。我能做吗?我正在链接我的工作流文件,如果它有帮助的话
---
name: lint build and test
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Super-Linter
uses: github/super-linter@v3.14.0
env:
VALIDATE_GO: false
VALIDATE_JSCPD: false
VALIDATE_ALL_CODEBASE: true
DEFAULT_BRANCH: master
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.29
- name: Build
run: go build -o apiDateTime -v ./...
- name: Test
run: go test ./... -coverprofile cover.out -covermode atomic
- name: Coverage result
run: go tool cover -func cover.out发布于 2021-02-17 19:16:53
我将把对go test的调用替换为对shell脚本的调用,就像解释的这里一样。
shell脚本应该如下所示
!#/bin/sh
set -e -u
go test ./... -coverprofile cover.out -covermode atomic
perc=`go tool cover -func=cover.out | tail -n 1 | sed -Ee 's!^[^[:digit:]]+([[:digit:]]+(\.[[:digit:]]+)?)%$!\1!'`
res=`echo "$perc >= 80.0" | bc`
test "$res" -eq 1 && exit 0
echo "Insufficient coverage: $perc" >&2
exit 1其中:
sed的覆盖提取覆盖率(参见这里)。这个脚本期望工具安装在ubuntu-latest包中(我不知道)。
如果不是,则可以用映像中的任何语言编写脚本,比如Perl或Python。
https://stackoverflow.com/questions/66246460
复制相似问题