mirror of
https://github.com/mariocandela/beelzebub.git
synced 2025-07-01 18:47:26 -04:00
81 lines
2.2 KiB
YAML
81 lines
2.2 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
pull_request:
|
|
branches: [ main ]
|
|
|
|
jobs:
|
|
|
|
CI:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v3
|
|
with:
|
|
go-version: 1.20.0
|
|
|
|
- name: Dependencies
|
|
run: go mod download
|
|
|
|
- name: Vet
|
|
run: |
|
|
go vet ./...
|
|
|
|
- name: Build
|
|
run: go build -v ./...
|
|
|
|
- name: Unit tests
|
|
run: |
|
|
go test ./... -v -coverprofile coverage.tmp.out -covermode count
|
|
go tool cover -func coverage.tmp.out
|
|
|
|
- name: Quality Gate - Test coverage shall be above threshold
|
|
env:
|
|
TESTCOVERAGE_THRESHOLD: 65
|
|
run: |
|
|
echo "Quality Gate: checking test coverage is above threshold ..."
|
|
echo "Threshold : $TESTCOVERAGE_THRESHOLD %"
|
|
# Excluded the concrete strategy from the unit test coverage, because covered by integration tests
|
|
cat coverage.tmp.out | grep -v "ssh.go" | grep -v "http.go" | grep -v "tcp.go" > coverage.out
|
|
totalCoverage=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+'`
|
|
echo "Current test coverage : $totalCoverage %"
|
|
if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 > $2)}') )); then
|
|
echo "OK"
|
|
else
|
|
echo "Current test coverage is below threshold. Please add more unit tests or adjust threshold to a lower value."
|
|
echo "Failed"
|
|
exit 1
|
|
fi
|
|
|
|
- name: Upload coverage reports to Codecov
|
|
uses: codecov/codecov-action@v3
|
|
env:
|
|
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
|
|
|
- name: Start integration test dependencies
|
|
run: |
|
|
make test.dependencies.start
|
|
|
|
- name: Wait for RabbitMQ to be ready
|
|
run: |
|
|
sleep 2
|
|
count=0
|
|
until docker exec rabbitmq rabbitmqctl list_queues > /dev/null 2>&1; do
|
|
count=$((count+1))
|
|
if [ $count -gt 10 ]; then
|
|
echo "RabbitMQ did not start within the specified time"
|
|
exit 1
|
|
fi
|
|
echo "Waiting for RabbitMQ to start..."
|
|
sleep 5
|
|
done
|
|
|
|
- name: Integration tests
|
|
run: |
|
|
make test.integration.verbose
|
|
make test.dependencies.down
|