2022-06-17 14:12:49 +00:00
|
|
|
name: Functional tests (sqlite)
|
2022-04-05 09:00:11 +00:00
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_call:
|
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
env:
|
|
|
|
PREFIX_TEST_NAMES_WITH_FILE: true
|
|
|
|
TEST_COVERAGE: true
|
|
|
|
|
2022-04-05 09:00:11 +00:00
|
|
|
jobs:
|
|
|
|
build:
|
2023-03-01 09:56:25 +00:00
|
|
|
strategy:
|
|
|
|
matrix:
|
2023-10-12 14:28:24 +00:00
|
|
|
go-version: ["1.21.3"]
|
2023-03-01 09:56:25 +00:00
|
|
|
|
2022-04-05 09:00:11 +00:00
|
|
|
name: "Build + tests"
|
|
|
|
runs-on: ubuntu-latest
|
2022-04-13 13:44:23 +00:00
|
|
|
timeout-minutes: 20
|
|
|
|
|
2022-04-05 09:00:11 +00:00
|
|
|
steps:
|
|
|
|
|
|
|
|
- name: "Force machineid"
|
|
|
|
run: |
|
|
|
|
sudo chmod +w /etc/machine-id
|
|
|
|
echo githubciXXXXXXXXXXXXXXXXXXXXXXXX | sudo tee /etc/machine-id
|
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
- name: "Check out CrowdSec repository"
|
2022-04-05 09:00:11 +00:00
|
|
|
uses: actions/checkout@v3
|
|
|
|
with:
|
|
|
|
fetch-depth: 0
|
|
|
|
submodules: true
|
|
|
|
|
2023-06-27 12:50:45 +00:00
|
|
|
- name: "Set up Go ${{ matrix.go-version }}"
|
|
|
|
uses: actions/setup-go@v4
|
2023-03-01 09:56:25 +00:00
|
|
|
with:
|
2023-06-27 12:50:45 +00:00
|
|
|
go-version: ${{ matrix.go-version }}
|
2023-03-01 09:56:25 +00:00
|
|
|
|
2022-04-05 09:00:11 +00:00
|
|
|
- name: "Install bats dependencies"
|
2023-02-15 13:27:47 +00:00
|
|
|
env:
|
|
|
|
GOBIN: /usr/local/bin
|
2022-04-05 09:00:11 +00:00
|
|
|
run: |
|
2023-06-23 12:25:29 +00:00
|
|
|
sudo apt -qq -y -o=Dpkg::Use-Pty=0 install build-essential daemonize jq netcat-openbsd libre2-dev
|
2022-04-05 09:00:11 +00:00
|
|
|
|
|
|
|
- name: "Build crowdsec and fixture"
|
2022-06-17 14:12:49 +00:00
|
|
|
run: |
|
2023-06-23 12:25:29 +00:00
|
|
|
make clean bats-build bats-fixture BUILD_STATIC=1
|
2022-04-05 09:00:11 +00:00
|
|
|
|
2022-04-13 13:44:23 +00:00
|
|
|
- name: "Run tests"
|
2022-06-17 14:12:49 +00:00
|
|
|
run: make bats-test
|
|
|
|
|
2023-03-30 13:05:09 +00:00
|
|
|
- name: "Collect coverage data"
|
|
|
|
run: |
|
|
|
|
go tool covdata textfmt -i test/coverage -o coverage-bats-raw.out
|
|
|
|
# filter out unwanted packages, should match the argument to "go-acc --ignore"
|
|
|
|
grep -v \
|
|
|
|
-e '/pkg/database' \
|
|
|
|
-e '/plugins/notifications' \
|
|
|
|
-e '/pkg/protobufs' \
|
|
|
|
-e '/pkg/cwversions' \
|
|
|
|
-e '/pkg/models' \
|
|
|
|
< coverage-bats-raw.out \
|
|
|
|
> coverage-bats.out
|
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
#
|
|
|
|
# In case you need to inspect the database status after the failure of a given test
|
|
|
|
#
|
|
|
|
# - name: "Run specified tests"
|
2023-03-03 14:54:49 +00:00
|
|
|
# run: ./test/run-tests test/bats/<filename>.bats -f "<test name>"
|
2022-06-17 14:12:49 +00:00
|
|
|
|
|
|
|
- name: "Show database dump"
|
2022-04-13 13:44:23 +00:00
|
|
|
run: |
|
2023-03-03 14:54:49 +00:00
|
|
|
./test/instance-crowdsec stop
|
|
|
|
sqlite3 ./test/local/var/lib/crowdsec/data/crowdsec.db '.dump'
|
2022-06-17 14:12:49 +00:00
|
|
|
if: ${{ always() }}
|
2022-04-13 13:03:37 +00:00
|
|
|
|
2022-11-25 11:02:38 +00:00
|
|
|
- name: "Show stack traces"
|
|
|
|
run: for file in $(find /tmp/crowdsec-crash.*.txt); do echo ">>>>> $file"; cat $file; echo; done
|
|
|
|
if: ${{ always() }}
|
|
|
|
|
2022-04-13 13:03:37 +00:00
|
|
|
- name: "Show crowdsec logs"
|
2023-03-03 14:54:49 +00:00
|
|
|
run: for file in $(find ./test/local/var/log -type f); do echo ">>>>> $file"; cat $file; echo; done
|
2022-04-13 13:03:37 +00:00
|
|
|
if: ${{ always() }}
|
2022-05-24 15:22:08 +00:00
|
|
|
|
|
|
|
- name: Upload crowdsec coverage to codecov
|
2022-10-24 10:48:25 +00:00
|
|
|
uses: codecov/codecov-action@v3
|
2022-05-24 15:22:08 +00:00
|
|
|
with:
|
2023-03-30 13:05:09 +00:00
|
|
|
files: ./coverage-bats.out
|
|
|
|
flags: bats
|