Felix 11 improvement refactor code core #80
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: π©πΌβπΎ Code Checker | |
on: | |
pull_request: | |
branches: | |
- master | |
- develop | |
push: | |
branches: | |
- master | |
- develop | |
paths: | |
- './config/linter/revive.toml' | |
env: | |
TESTCOVERAGE_THRESHOLD: 20 | |
jobs: | |
lint: | |
name: Lint and Test | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: π§ Print current working dir | |
run: | | |
ls -la $PWD | |
ls -la $GITHUB_WORKSPACE | |
- uses: actions/setup-go@v2 | |
with: | |
go-version: '1.21.1' | |
- name: βοΈ Setup GO environment | |
run: | | |
go mod download | |
- name: π· Build | |
run: go build ./cmd/main.go | |
- name: π§ͺ Run Unit tests | |
run: | | |
sudo go test ./... -coverprofile coverage.out -covermode count | |
sudo go tool cover -func coverage.out | |
- name: π Quality Gate - Test coverage | |
run: | | |
echo "Quality Gate: checking test coverage is above threshold ..." | |
echo "Threshold : $TESTCOVERAGE_THRESHOLD %" | |
totalCoverage=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+'` | |
# Set totalCoverage as an environment variable | |
echo "totalCoverage=$totalCoverage" >> $GITHUB_ENV | |
if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 > $2)}') )); then | |
echo "β Test coverage is above the threshold. Great job!" | |
else | |
echo "β Current test coverage is below the threshold. Please add more unit tests or adjust the threshold to a lower value." | |
fi | |
- name: π¬ PR comment with reactions - Above Threshold | |
uses: thollander/actions-comment-pull-request@v2 | |
if: ${{ github.event_name == 'pull_request' && env.totalCoverage >= env.TESTCOVERAGE_THRESHOLD }} | |
with: | |
message: | | |
β Test coverage is above the threshold. Good job! | |
- **Coverage: ${{env.totalCoverage}}%, Threshold: ${{env.TESTCOVERAGE_THRESHOLD}}%** | |
reactions: rocket | |
- name: π¬ PR comment with reactions - Below Threshold | |
uses: thollander/actions-comment-pull-request@v2 | |
if: ${{ github.event_name == 'pull_request' && env.totalCoverage < env.TESTCOVERAGE_THRESHOLD }} | |
with: | |
message: | | |
β Test coverage is below the threshold. Please add more unit tests. | |
- **Coverage: ${{env.totalCoverage}}%, Threshold: ${{env.TESTCOVERAGE_THRESHOLD}}%** | |
reactions: eyes | |
- name: π§ Gate Keeper - Test coverage | |
if: ${{ github.event_name == 'pull_request' && env.totalCoverage < env.TESTCOVERAGE_THRESHOLD }} | |
run: exit 1 | |
- name: π¨βπ€ Run Revive Action | |
uses: docker://morphy/revive-action:v2 | |
with: | |
config: ./config/linter/revive.toml | |
continue-on-error: false |