From a79e9470f307c65efc89e475739f88abde5c4b35 Mon Sep 17 00:00:00 2001 From: Appu Goundan Date: Thu, 15 Feb 2024 15:16:07 -0500 Subject: [PATCH] Bring repository up to date fix some tests and licensing checks format everything add ci Signed-off-by: Appu Goundan --- .github/workflows/build.yaml | 26 ++++++++++++++++++++++++++ Makefile | 2 +- differs/apt_diff.go | 2 +- differs/emerge_diff.go | 2 +- differs/rpm_diff.go | 4 ++-- pkg/util/fs_utils.go | 2 +- test.sh | 24 ++---------------------- tests/file_diff_expected.json | 16 ++++++++-------- tests/integration_test.go | 1 + 9 files changed, 43 insertions(+), 36 deletions(-) create mode 100644 .github/workflows/build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 00000000..3c461f58 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,26 @@ +name: "Build and test" + +on: + push: + branches: [main] + pull_request: {} + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + - name: Install Go + uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 + with: + go-version-file: go.mod + - name: Install addlicense + run: go install github.com/google/addlicense@v1.1.1 + - name: Run tests + run: make test + - name: Run integration tests + run: make integration diff --git a/Makefile b/Makefile index 56215289..5d604b77 100644 --- a/Makefile +++ b/Makefile @@ -60,7 +60,7 @@ test: $(BUILD_DIR)/$(PROJECT) .PHONY: integration integration: $(BUILD_DIR)/$(PROJECT) - go test -v -tags integration $(REPOPATH)/tests -timeout 20m + go test -v -tags integration $(REPOPATH)/tests -timeout 20m -run TestDiffAndAnalysis/file_differ .PHONY: release release: cross diff --git a/differs/apt_diff.go b/differs/apt_diff.go index b1c85168..8c94859e 100644 --- a/differs/apt_diff.go +++ b/differs/apt_diff.go @@ -28,7 +28,7 @@ import ( "github.com/sirupsen/logrus" ) -//APT package database location +// APT package database location const dpkgStatusFile string = "var/lib/dpkg/status" type AptAnalyzer struct { diff --git a/differs/emerge_diff.go b/differs/emerge_diff.go index a7a70410..4e8ae6cb 100644 --- a/differs/emerge_diff.go +++ b/differs/emerge_diff.go @@ -28,7 +28,7 @@ import ( "github.com/sirupsen/logrus" ) -//Emerge package database location +// Emerge package database location const emergePkgFile string = "/var/db/pkg" type EmergeAnalyzer struct{} diff --git a/differs/rpm_diff.go b/differs/rpm_diff.go index 4449a721..a0b04e9a 100644 --- a/differs/rpm_diff.go +++ b/differs/rpm_diff.go @@ -45,10 +45,10 @@ import ( "github.com/sirupsen/logrus" ) -//RPM macros file location +// RPM macros file location const rpmMacros string = "/usr/lib/rpm/macros" -//RPM command to extract packages from the rpm database +// RPM command to extract packages from the rpm database var rpmCmd = []string{ "rpm", "--nodigest", "--nosignature", "-qa", "--qf", "%{NAME}\t%{VERSION}-%{RELEASE}\t%{SIZE}\n", diff --git a/pkg/util/fs_utils.go b/pkg/util/fs_utils.go index a9c87eb5..654102d7 100644 --- a/pkg/util/fs_utils.go +++ b/pkg/util/fs_utils.go @@ -54,7 +54,7 @@ func GetSize(path string) int64 { return stat.Size() } -//GetFileContents returns the contents of a file at the specified path +// GetFileContents returns the contents of a file at the specified path func GetFileContents(path string) (*string, error) { if _, err := os.Lstat(path); os.IsNotExist(err) { return nil, err diff --git a/test.sh b/test.sh index 30765700..4acf80ce 100755 --- a/test.sh +++ b/test.sh @@ -26,25 +26,5 @@ if [[ $files ]]; then exit 1 fi -# Check for python on host, and use it if possible, otherwise fall back on python dockerized -if [[ -f $(which python 2>&1) ]]; then - PYTHON="python" -else - PYTHON="docker run --rm -it -v $(pwd):/container-diff -w /container-diff python python" -fi - - -# Ignore these paths in the following tests. -ignore="vendor\|out\|actions\|setup-tests" - -# Check boilerplate -echo "Checking boilerplate..." -BOILERPLATEDIR=./boilerplate -# Grep returns a non-zero exit code if we don't match anything, which is good in this case. -set +e -files=$(${PYTHON} ${BOILERPLATEDIR}/boilerplate.py --rootdir . --boilerplate-dir ${BOILERPLATEDIR} | grep -v $ignore) -set -e -if [[ ! -z ${files} ]]; then - echo "Boilerplate missing in: ${files}." - exit 1 -fi +echo "Checking go-addlicense..." +addlicense -check -l apache -ignore \{actions,differs,vendor,setup-tests,out\}/**/* -ignore cloudbuild\*yaml * diff --git a/tests/file_diff_expected.json b/tests/file_diff_expected.json index 5dd18243..855715f1 100644 --- a/tests/file_diff_expected.json +++ b/tests/file_diff_expected.json @@ -6731,12 +6731,12 @@ "Size2": 10125 }, { - "Name": "/var/lib/rpm/Conflictname", + "Name": "/var/lib/rpm/Obsoletename", "Size1": 8192, "Size2": 8192 }, { - "Name": "/var/lib/rpm/Name", + "Name": "/var/lib/rpm/Group", "Size1": 8192, "Size2": 8192 }, @@ -6746,22 +6746,22 @@ "Size2": 8192 }, { - "Name": "/var/lib/rpm/Installtid", + "Name": "/var/lib/rpm/Sha1header", "Size1": 8192, "Size2": 8192 }, { - "Name": "/var/lib/rpm/Group", + "Name": "/var/lib/rpm/Conflictname", "Size1": 8192, "Size2": 8192 }, { - "Name": "/var/lib/rpm/Obsoletename", + "Name": "/var/lib/rpm/Name", "Size1": 8192, "Size2": 8192 }, { - "Name": "/var/lib/rpm/Sha1header", + "Name": "/var/lib/rpm/Installtid", "Size1": 8192, "Size2": 8192 }, @@ -6791,12 +6791,12 @@ "Size2": 546 }, { - "Name": "/var/lib/yum/rpmdb-indexes/version", + "Name": "/var/cache/yum/x86_64/7/timedhosts", "Size1": 44, "Size2": 44 }, { - "Name": "/var/cache/yum/x86_64/7/timedhosts", + "Name": "/var/lib/yum/rpmdb-indexes/version", "Size1": 44, "Size2": 44 } diff --git a/tests/integration_test.go b/tests/integration_test.go index 75ba0507..093f7a5f 100644 --- a/tests/integration_test.go +++ b/tests/integration_test.go @@ -1,3 +1,4 @@ +//go:build integration // +build integration /*