2022-06-17 14:12:49 +00:00
|
|
|
name: Functional tests (MySQL)
|
2022-03-18 16:36:51 +00:00
|
|
|
|
|
|
|
on:
|
2022-04-05 09:00:11 +00:00
|
|
|
workflow_call:
|
|
|
|
inputs:
|
|
|
|
database_image:
|
|
|
|
required: true
|
|
|
|
type: string
|
2022-03-18 16:36:51 +00:00
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
env:
|
|
|
|
PREFIX_TEST_NAMES_WITH_FILE: true
|
|
|
|
|
2022-03-18 16:36:51 +00:00
|
|
|
jobs:
|
|
|
|
build:
|
2023-02-28 16:25:09 +00:00
|
|
|
strategy:
|
|
|
|
matrix:
|
2023-06-15 21:18:57 +00:00
|
|
|
go-version: ["1.20.5"]
|
2023-02-28 16:25:09 +00:00
|
|
|
|
2022-04-01 12:12:03 +00:00
|
|
|
name: "Build + tests"
|
2022-03-18 16:36:51 +00:00
|
|
|
runs-on: ubuntu-latest
|
2023-04-05 13:15:33 +00:00
|
|
|
timeout-minutes: 30
|
2022-03-18 16:36:51 +00:00
|
|
|
services:
|
2022-04-01 12:12:03 +00:00
|
|
|
database:
|
2022-04-05 09:00:11 +00:00
|
|
|
image: ${{ inputs.database_image }}
|
2022-03-18 16:36:51 +00:00
|
|
|
env:
|
2022-09-01 14:49:12 +00:00
|
|
|
MYSQL_ROOT_PASSWORD: "secret"
|
2022-03-18 16:36:51 +00:00
|
|
|
ports:
|
|
|
|
- 3306:3306
|
2022-04-13 13:44:23 +00:00
|
|
|
|
2022-03-18 16:36:51 +00:00
|
|
|
steps:
|
|
|
|
|
2022-03-22 11:33:36 +00:00
|
|
|
- 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
|
2022-03-18 16:36:51 +00:00
|
|
|
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-02-28 16:25:09 +00:00
|
|
|
with:
|
2023-06-27 12:50:45 +00:00
|
|
|
go-version: ${{ matrix.go-version }}
|
|
|
|
cache-dependency-path: "**/go.sum"
|
2023-02-28 16:25:09 +00:00
|
|
|
|
2022-03-18 16:36:51 +00:00
|
|
|
- name: "Install bats dependencies"
|
2023-02-15 13:27:47 +00:00
|
|
|
env:
|
|
|
|
GOBIN: /usr/local/bin
|
2022-03-18 16:36:51 +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-03-18 16:36:51 +00:00
|
|
|
|
2022-04-01 12:12:03 +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-03-18 16:36:51 +00:00
|
|
|
env:
|
|
|
|
DB_BACKEND: mysql
|
|
|
|
MYSQL_HOST: 127.0.0.1
|
|
|
|
MYSQL_PORT: 3306
|
2022-09-01 14:49:12 +00:00
|
|
|
MYSQL_PASSWORD: "secret"
|
2022-03-18 16:36:51 +00:00
|
|
|
MYSQL_USER: root
|
|
|
|
|
2022-04-01 12:12:03 +00:00
|
|
|
- name: "Run tests"
|
2022-03-18 16:36:51 +00:00
|
|
|
run: make bats-test
|
|
|
|
env:
|
|
|
|
DB_BACKEND: mysql
|
|
|
|
MYSQL_HOST: 127.0.0.1
|
|
|
|
MYSQL_PORT: 3306
|
2022-09-01 14:49:12 +00:00
|
|
|
MYSQL_PASSWORD: "secret"
|
2022-03-18 16:36:51 +00:00
|
|
|
MYSQL_USER: root
|
2022-03-25 11:17:28 +00:00
|
|
|
|
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
|
2023-03-03 14:54:49 +00:00
|
|
|
run: ./test/instance-db dump /dev/fd/1
|
2022-06-17 14:12:49 +00:00
|
|
|
env:
|
|
|
|
DB_BACKEND: mysql
|
|
|
|
MYSQL_HOST: 127.0.0.1
|
|
|
|
MYSQL_PORT: 3306
|
2022-09-01 14:49:12 +00:00
|
|
|
MYSQL_PASSWORD: "secret"
|
2022-06-17 14:12:49 +00:00
|
|
|
MYSQL_USER: root
|
|
|
|
if: ${{ always() }}
|
|
|
|
|
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-04-01 12:12:03 +00:00
|
|
|
- name: "Show database logs"
|
|
|
|
run: docker logs "${{ job.services.database.id }}"
|
2022-03-25 11:17:28 +00:00
|
|
|
if: ${{ always() }}
|