From b09c6d56832eb1718c07d74abf3bc6ae3fe4e030 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:36:04 +0200 Subject: Adding upstream version 1.1.0. Signed-off-by: Daniel Baumann --- .github/workflows/compliance.yml | 20 ++++ .github/workflows/compliance/anonymize-license.pl | 11 +++ .github/workflows/compliance/check-licenses.sh | 72 +++++++++++++++ .github/workflows/compliance/ls-deps.pl | 24 +++++ .github/workflows/docker.yml | 21 +++++ .github/workflows/go.yml | 108 ++++++++++++++++++++++ .github/workflows/integration-tests.yml | 55 +++++++++++ .github/workflows/sql.yml | 58 ++++++++++++ .github/workflows/version.yml | 25 +++++ 9 files changed, 394 insertions(+) create mode 100644 .github/workflows/compliance.yml create mode 100755 .github/workflows/compliance/anonymize-license.pl create mode 100755 .github/workflows/compliance/check-licenses.sh create mode 100755 .github/workflows/compliance/ls-deps.pl create mode 100644 .github/workflows/docker.yml create mode 100644 .github/workflows/go.yml create mode 100644 .github/workflows/integration-tests.yml create mode 100644 .github/workflows/sql.yml create mode 100644 .github/workflows/version.yml (limited to '.github/workflows') diff --git a/.github/workflows/compliance.yml b/.github/workflows/compliance.yml new file mode 100644 index 0000000..c094754 --- /dev/null +++ b/.github/workflows/compliance.yml @@ -0,0 +1,20 @@ +name: Compliance +on: + push: + branches: + - master + pull_request: {} + +jobs: + licenses: + runs-on: ubuntu-latest + steps: + - run: sudo apt install -y moreutils + + - uses: actions/setup-go@v2 + with: + go-version: 1.18.x + + - uses: actions/checkout@v2 + + - run: .github/workflows/compliance/check-licenses.sh diff --git a/.github/workflows/compliance/anonymize-license.pl b/.github/workflows/compliance/anonymize-license.pl new file mode 100755 index 0000000..573eba6 --- /dev/null +++ b/.github/workflows/compliance/anonymize-license.pl @@ -0,0 +1,11 @@ +#!/usr/bin/perl -pi + +use warnings; +use strict; +use autodie qw(:all); + +if (/^ ?(?:\w+ )?Copyright / || /^All rights reserved\.$/ || /^(?:The )?\S+ License(?: \(.+?\))?$/ || /^$/) { + $_ = "" +} + +s/Google Inc\./the copyright holder/g diff --git a/.github/workflows/compliance/check-licenses.sh b/.github/workflows/compliance/check-licenses.sh new file mode 100755 index 0000000..63ff76f --- /dev/null +++ b/.github/workflows/compliance/check-licenses.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +set -eo pipefail + +find_license_file() { + MOD_NAME="$1" + LICENSE_DIR="vendor/$MOD_NAME" + LICENSE_FILES=({,../}{,UN}LICENSE{,.txt,.md}) + + for LICENSE_FILE in "${LICENSE_FILES[@]}"; do + LICENSE_FILE="${LICENSE_DIR}/$LICENSE_FILE" + + if [ -e "$LICENSE_FILE" ]; then + echo "$LICENSE_FILE" + return + fi + done + + echo "Module ${MOD_NAME}: license file missing in ${LICENSE_DIR}. Tried:" "${LICENSE_FILES[@]}" >&2 + false +} + +list_all_deps() { + for MAIN_MOD in ./cmd/*; do + go list -deps "$MAIN_MOD" + done +} + +COMPATIBLE_LINE=$(($LINENO + 2)) + +COMPATIBLE=( + # public domain + 3cee2c43614ad4572d9d594c81b9348cf45ed5ac # vendor/github.com/vbauerster/mpb/v6/UNLICENSE + # MIT + 66d504eb2f162b9cbf11b07506eeed90c6edabe1 # vendor/github.com/cespare/xxhash/v2/LICENSE.txt + 1513ff663e946fdcadb630bed670d253b8b22e1e # vendor/github.com/davecgh/go-spew/spew/../LICENSE + 90a1030e6314df9a898e5bfbdb4c6176d0a1f81c # vendor/github.com/jmoiron/sqlx/LICENSE + # BSD-2 + 8762249b76928cb6995b98a95a9396c5aaf104f3 # vendor/github.com/go-redis/redis/v8/LICENSE + d550c89174b585d03dc67203952b38372b4ce254 # vendor/github.com/pkg/errors/LICENSE + # BSD-3 + b23b967bba92ea3c5ccde9962027cd70400865eb # vendor/github.com/google/uuid/LICENSE + 604b38b184689a3db06a0617216d52a95aea10d8 # vendor/github.com/pmezard/go-difflib/difflib/../LICENSE + # MPLv2 + 0a2b84dd9b124c4d95dd24418c3e84fd870cc0ac # vendor/github.com/go-sql-driver/mysql/LICENSE +) + +MY_DIR="$(dirname "$0")" + +go mod vendor + +for MOD_NAME in $(list_all_deps | "${MY_DIR}/ls-deps.pl"); do + LICENSE_FILE="$(find_license_file "$MOD_NAME")" + + "${MY_DIR}/anonymize-license.pl" "$LICENSE_FILE" + tr -d ., <"$LICENSE_FILE" | tr \\n\\t ' ' | sponge "$LICENSE_FILE" + perl -p0 -i -e 's/ +/ /g; s/ +$//; $_ = lc' "$LICENSE_FILE" + + for SHA1 in "${COMPATIBLE[@]}"; do + if sha1sum -c <<<"$SHA1 $LICENSE_FILE" >/dev/null 2>&1; then + continue 2 + fi + done + + echo "Module ${MOD_NAME}: unknown license. Run 'go mod vendor' (or see below), verify by yourself whether" \ + "$LICENSE_FILE is GPLv2 compatible and (if yes) update the license text hashes list at ${0}:$COMPATIBLE_LINE" \ + "and eventually .github/workflows/compliance/anonymize-license.pl:7" >&2 + + sha1sum "$LICENSE_FILE" + head "$LICENSE_FILE" + false +done diff --git a/.github/workflows/compliance/ls-deps.pl b/.github/workflows/compliance/ls-deps.pl new file mode 100755 index 0000000..a7a033a --- /dev/null +++ b/.github/workflows/compliance/ls-deps.pl @@ -0,0 +1,24 @@ +#!/usr/bin/perl + +use warnings; +use strict; +use autodie qw(:all); + +my @mods = <>; +chomp @mods; +s~^vendor/~~ for @mods; + +@mods = grep m~^[^./]+\.~, @mods; +@mods = grep !m~^golang\.org/x(?:/|$)~, @mods; +@mods = grep !m~^github\.com/icinga/icingadb(?:/|$)~, @mods; +@mods = sort @mods; + +my $lastMod = undef; + +for (@mods) { + # prefixed with last mod (e.g. "go.uber.org/zap/buffer" after "go.uber.org/zap"), so redundant + next if defined($lastMod) && /$lastMod/; + + $lastMod = '^' . quotemeta("$_/"); + print "$_\n" +} diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..1469426 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,21 @@ +name: Docker image + +on: + pull_request: {} + push: + branches: + - master + release: + types: + - published + +jobs: + docker: + runs-on: ubuntu-latest + + steps: + - name: Docker image + uses: Icinga/docker-icingadb@master + env: + INPUT_TOKEN: '${{ github.token }}' + DOCKER_HUB_PASSWORD: '${{ secrets.DOCKER_HUB_PERSONAL_TOKEN }}' diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..de15521 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,108 @@ +name: Go +on: + push: + branches: + - master + pull_request: {} + +jobs: + build-test: + + strategy: + matrix: + os: [ macos-latest, ubuntu-latest ] + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-go@v2 + with: + go-version: 1.18.x + + - run: go build -gcflags="-m" ./... + + - run: go test -v -race ./... + + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-go@v2 + with: + go-version: 1.18.x + + - uses: dominikh/staticcheck-action@29e9b80fb8de0521ba4ed3fdf68fed5bbe82a2d2 # v1.1.0 + with: + install-go: false + + vet: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-go@v2 + with: + go-version: 1.18.x + + - run: go vet ./... + + fmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-go@v2 + with: + go-version: 1.18.x + + - name: Run gofmt -d . + run: | + fmtvar="$(gofmt -d .)" + echo "$fmtvar" + test -z "$fmtvar" + + modtidy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-go@v2 + with: + go-version: 1.18.x + + - name: Run go mod tidy + run: | + go mod tidy + gitdiff="$(git diff -U0)" + echo "$gitdiff" + test -z "$gitdiff" + + vendor-diff: + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v3 + with: + go-version: ^1.18 + + - name: Checkout base commit + uses: actions/checkout@v3 + with: + path: a + ref: ${{ github.base_ref }} + - name: Download dependencies of base commit + run: go mod vendor + working-directory: a + + - name: Checkout PR + uses: actions/checkout@v3 + with: + path: b + - name: Download dependencies of PR + run: go mod vendor + working-directory: b + + - name: Diff of dependencies + run: diff -ur --color=always a/vendor b/vendor || true diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml new file mode 100644 index 0000000..dff8112 --- /dev/null +++ b/.github/workflows/integration-tests.yml @@ -0,0 +1,55 @@ +name: Integration Tests + +on: + push: + branches: + - master + pull_request: {} + schedule: + - cron: '57 3 * * *' + +jobs: + integration-tests: + strategy: + fail-fast: false + matrix: + database: + - name: mysql + pretty_name: MySQL + - name: pgsql + pretty_name: PostgreSQL + + name: ${{ matrix.database.pretty_name }} + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Go + uses: actions/setup-go@v2 + with: + go-version: '^1.18' + - name: Build Icinga DB + run: go build ./cmd/icingadb + env: + CGO_ENABLED: 0 + - name: Build Integration Tests + run: go test -o ../icingadb-test -c . + working-directory: tests/ + - name: Run Integration Tests + run: ./icingadb-test -icingatesting.debuglog debug.log -test.v + env: + ICINGADB_TESTS_DATABASE_TYPE: ${{ matrix.database.name }} + ICINGA_TESTING_ICINGADB_BINARY: ${{ github.workspace }}/icingadb + ICINGA_TESTING_ICINGADB_SCHEMA_MYSQL: ${{ github.workspace }}/schema/mysql/schema.sql + ICINGA_TESTING_ICINGADB_SCHEMA_PGSQL: ${{ github.workspace }}/schema/pgsql/schema.sql + - name: Compress Debug Log + if: ${{ always() }} + run: xz -9 debug.log + - name: Upload Debug Log + if: ${{ always() }} + uses: actions/upload-artifact@v2 + with: + name: ${{ matrix.database.name }}-debug.log.xz + path: debug.log.xz + retention-days: 1 diff --git a/.github/workflows/sql.yml b/.github/workflows/sql.yml new file mode 100644 index 0000000..c5e4304 --- /dev/null +++ b/.github/workflows/sql.yml @@ -0,0 +1,58 @@ +name: SQL + +on: + push: + branches: + - master + pull_request: {} + +jobs: + sql: + name: ${{ matrix.database.name }} + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + database: + - {type: MYSQL, name: MySQL 5.5, image: "icinga/icingadb-mysql:5.5"} + - {type: MYSQL, name: MySQL 5.6, image: "icinga/icingadb-mysql:5.6"} + - {type: MYSQL, name: MySQL 5.7, image: "mysql:5.7"} + - {type: MYSQL, name: MySQL latest, image: "mysql:latest"} + - {type: MYSQL, name: MariaDB 10.1, image: "mariadb:10.1"} + - {type: MYSQL, name: MariaDB 10.2, image: "mariadb:10.2"} + - {type: MYSQL, name: MariaDB 10.3, image: "mariadb:10.3"} + - {type: MYSQL, name: MariaDB 10.4, image: "mariadb:10.4"} + - {type: MYSQL, name: MariaDB 10.5, image: "mariadb:10.5"} + - {type: MYSQL, name: MariaDB 10.6, image: "mariadb:10.6"} + - {type: MYSQL, name: MariaDB 10.7, image: "mariadb:10.7"} + - {type: MYSQL, name: MariaDB latest, image: "mariadb:latest"} + - {type: PGSQL, name: PostgreSQL 9.6, image: "postgres:9.6"} + - {type: PGSQL, name: PostgreSQL 10, image: "postgres:10"} + - {type: PGSQL, name: PostgreSQL 11, image: "postgres:11"} + - {type: PGSQL, name: PostgreSQL 12, image: "postgres:12"} + - {type: PGSQL, name: PostgreSQL 13, image: "postgres:13"} + - {type: PGSQL, name: PostgreSQL latest, image: "postgres:latest"} + + steps: + - name: Setup Go + uses: actions/setup-go@v1 + with: + go-version: '^1.16' + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Download dependencies + run: go get -v -t -d ./... + working-directory: tests/ + + - name: Run tests + env: + ICINGADB_TESTS_DATABASE_TYPE: ${{ matrix.database.type }} + ICINGA_TESTING_${{ matrix.database.type }}_IMAGE: ${{ matrix.database.image }} + ICINGA_TESTING_ICINGADB_SCHEMA_MYSQL: ${{ github.workspace }}/schema/mysql/schema.sql + ICINGA_TESTING_ICINGADB_SCHEMA_PGSQL: ${{ github.workspace }}/schema/pgsql/schema.sql + timeout-minutes: 10 + run: go test -v -timeout 5m ./sql + working-directory: tests/ diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml new file mode 100644 index 0000000..98d28c0 --- /dev/null +++ b/.github/workflows/version.yml @@ -0,0 +1,25 @@ +name: Version +on: + push: + branches: + - master + pull_request: {} + +jobs: + version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: actions/setup-go@v2 + with: + go-version: 1.18.x + - name: Check version + # TODO(elippmann): Needs adjustments as soon as we release from (support) branches too. + run: | + actual="$(go run cmd/icingadb/main.go --version | head -n1 | sed 's/Icinga DB version: \(.*\)/v\1/')" + expected="$(git describe --tags $(git rev-list --tags --max-count=1))" + echo "Actual version: $actual" + echo "Expected version: $expected" + test "$actual" = "$expected" || (echo "Versions do not match"; (exit 1)) -- cgit v1.2.3