From 8bec06b771575245eb3faaab2563fa4841e45ac2 Mon Sep 17 00:00:00 2001 From: Daniel Gospodinow Date: Sat, 27 Jan 2024 09:05:17 +0000 Subject: [PATCH 01/10] Add tests in CI --- .github/workflows/ci.yml | 30 ++++++++++++++++++++++++++++-- tests/healthypkg/cmd/main.go | 7 +++++++ tests/healthypkg/go.mod | 3 +++ tests/unhealthypkg/cmd/main.go | 28 ++++++++++++++++++++++++++++ tests/unhealthypkg/go.mod | 3 +++ 5 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 tests/healthypkg/cmd/main.go create mode 100644 tests/healthypkg/go.mod create mode 100644 tests/unhealthypkg/cmd/main.go create mode 100644 tests/unhealthypkg/go.mod diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 618bb2d..8ac78a9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,8 +44,34 @@ jobs: push: true tags: ${{ env.TEST_TAG }} - - name: Run the Container + - name: Run the Container successfully id: run run: | docker run \ - --rm ${{ env.TEST_TAG }} || true \ No newline at end of file + --rm ${{ env.TEST_TAG }} + + - name: Run successfully against a healthy package + id: test-healthy + working-directory: ./tests/healthy + run: | + docker run \ + -e PACKAGE_TO_SCAN="./..." + --rm ${{ env.TEST_TAG }} + + - name: Spot issues against an unhealthy package + id: test-unhealthy + working-directory: ./tests/unhealthy + run: | + set +e + + docker run \ + -e PACKAGE_TO_SCAN="./..." + --rm ${{ env.TEST_TAG }} + + if [[ $? -eq 0 ]]; then + echo "Container didn't fail when it should've" + exit 1 + else + echo "Container failed as expected" + exit 0 + fi diff --git a/tests/healthypkg/cmd/main.go b/tests/healthypkg/cmd/main.go new file mode 100644 index 0000000..4d4e58a --- /dev/null +++ b/tests/healthypkg/cmd/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("I haven't been using shampoo since 2016. 🥚") +} diff --git a/tests/healthypkg/go.mod b/tests/healthypkg/go.mod new file mode 100644 index 0000000..679bc73 --- /dev/null +++ b/tests/healthypkg/go.mod @@ -0,0 +1,3 @@ +module healthypkg + +go 1.21.0 diff --git a/tests/unhealthypkg/cmd/main.go b/tests/unhealthypkg/cmd/main.go new file mode 100644 index 0000000..b3db013 --- /dev/null +++ b/tests/unhealthypkg/cmd/main.go @@ -0,0 +1,28 @@ +package main + +import "log" + +type BaldGuy struct { + Name string + HairCount int +} + +func fetchABaldBuy() *BaldGuy { + baldBuy := &BaldGuy{ + Name: "Daniel Gospodinow", + HairCount: 0, + } + + // Doing the nasty thing. + baldBuy = nil + + return baldBuy +} + +func main() { + baldGuy := fetchABaldBuy() + + if baldGuy.HairCount > 0 { + log.Printf("Bald guy %s has %d hairs, he's surely been on a trip to Turkey!", baldGuy.Name, baldGuy.HairCount) + } +} diff --git a/tests/unhealthypkg/go.mod b/tests/unhealthypkg/go.mod new file mode 100644 index 0000000..23df511 --- /dev/null +++ b/tests/unhealthypkg/go.mod @@ -0,0 +1,3 @@ +module unhealthypkg + +go 1.21.0 From 383c3fda66d1ba8d0dda11109b62fd7576050659 Mon Sep 17 00:00:00 2001 From: Daniel Gospodinow Date: Sat, 27 Jan 2024 09:05:55 +0000 Subject: [PATCH 02/10] Update version file --- .version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version b/.version index 05b19b1..fa3de58 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.0.4 \ No newline at end of file +0.0.5 \ No newline at end of file From 00a0bae2e8ac145df12f0c0405b8a026978f9234 Mon Sep 17 00:00:00 2001 From: Daniel Gospodinow Date: Sat, 27 Jan 2024 09:07:13 +0000 Subject: [PATCH 03/10] Remove useless step --- .github/workflows/ci.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ac78a9..4464979 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,12 +44,6 @@ jobs: push: true tags: ${{ env.TEST_TAG }} - - name: Run the Container successfully - id: run - run: | - docker run \ - --rm ${{ env.TEST_TAG }} - - name: Run successfully against a healthy package id: test-healthy working-directory: ./tests/healthy From ff4b672399a32a0db3c8ed7c727c4ca6f7f38c70 Mon Sep 17 00:00:00 2001 From: Daniel Gospodinow Date: Sat, 27 Jan 2024 09:11:01 +0000 Subject: [PATCH 04/10] Update step names and working dirs --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4464979..f24a996 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,17 +44,17 @@ jobs: push: true tags: ${{ env.TEST_TAG }} - - name: Run successfully against a healthy package + - name: No issues in a healthy package id: test-healthy - working-directory: ./tests/healthy + working-directory: ./tests/healthypkg run: | docker run \ -e PACKAGE_TO_SCAN="./..." --rm ${{ env.TEST_TAG }} - - name: Spot issues against an unhealthy package + - name: Spot issues in an unhealthy package id: test-unhealthy - working-directory: ./tests/unhealthy + working-directory: ./tests/unhealthypkg run: | set +e From 3cb770b06605f40d5d610c73e7e5494354d32ff1 Mon Sep 17 00:00:00 2001 From: Daniel Gospodinow Date: Sat, 27 Jan 2024 09:12:56 +0000 Subject: [PATCH 05/10] Add missing backslashes in commands in CI --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f24a996..ddd0472 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,7 +49,7 @@ jobs: working-directory: ./tests/healthypkg run: | docker run \ - -e PACKAGE_TO_SCAN="./..." + -e PACKAGE_TO_SCAN="./..." \ --rm ${{ env.TEST_TAG }} - name: Spot issues in an unhealthy package @@ -59,7 +59,7 @@ jobs: set +e docker run \ - -e PACKAGE_TO_SCAN="./..." + -e PACKAGE_TO_SCAN="./..." \ --rm ${{ env.TEST_TAG }} if [[ $? -eq 0 ]]; then From 90250180e6851692c6f494b259616578c1127a60 Mon Sep 17 00:00:00 2001 From: Daniel Gospodinow Date: Sat, 27 Jan 2024 09:22:33 +0000 Subject: [PATCH 06/10] Fix linting issue and dir selection --- .github/workflows/ci.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ddd0472..1998ed4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,23 +46,19 @@ jobs: - name: No issues in a healthy package id: test-healthy - working-directory: ./tests/healthypkg run: | docker run \ - -e PACKAGE_TO_SCAN="./..." \ + -e PACKAGE_TO_SCAN="./tests/healthypkg/..." \ --rm ${{ env.TEST_TAG }} - name: Spot issues in an unhealthy package id: test-unhealthy - working-directory: ./tests/unhealthypkg run: | set +e - docker run \ - -e PACKAGE_TO_SCAN="./..." \ - --rm ${{ env.TEST_TAG }} - - if [[ $? -eq 0 ]]; then + if docker run \ + -e PACKAGE_TO_SCAN="./tests/unhealthypkg/..." \ + --rm ${{ env.TEST_TAG }}; then echo "Container didn't fail when it should've" exit 1 else From 430d091a00a8ae78be7a2a2bf59fff62bc29afb6 Mon Sep 17 00:00:00 2001 From: Daniel Gospodinow Date: Sat, 27 Jan 2024 09:54:50 +0000 Subject: [PATCH 07/10] Exclude tests dir from super linter --- .github/workflows/linter.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 09a8374..6ff039a 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -28,3 +28,4 @@ jobs: DEFAULT_BRANCH: main GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} VALIDATE_ALL_CODEBASE: false + FILTER_REGEX_EXCLUDE: 'tests/.*' From d6b702b509805743e84592800d0f12594149497b Mon Sep 17 00:00:00 2001 From: Daniel Gospodinow Date: Sat, 27 Jan 2024 09:57:17 +0000 Subject: [PATCH 08/10] Update scan dirs --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1998ed4..16dede1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,18 +46,20 @@ jobs: - name: No issues in a healthy package id: test-healthy + working-directory: ./tests/healthypkg run: | docker run \ - -e PACKAGE_TO_SCAN="./tests/healthypkg/..." \ + -e PACKAGE_TO_SCAN="./..." \ --rm ${{ env.TEST_TAG }} - name: Spot issues in an unhealthy package id: test-unhealthy + working-directory: ./tests/unhealthypkg run: | set +e if docker run \ - -e PACKAGE_TO_SCAN="./tests/unhealthypkg/..." \ + -e PACKAGE_TO_SCAN="./..." \ --rm ${{ env.TEST_TAG }}; then echo "Container didn't fail when it should've" exit 1 From edb83d1bc04fafd9d7e29bcbb7bb23d075537d07 Mon Sep 17 00:00:00 2001 From: Daniel Gospodinow Date: Sat, 27 Jan 2024 10:04:20 +0000 Subject: [PATCH 09/10] Add verbosity to steps --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 16dede1..57bdacc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,6 +48,8 @@ jobs: id: test-healthy working-directory: ./tests/healthypkg run: | + echo "Running Docker command in the current directory: $(pwd)" + docker run \ -e PACKAGE_TO_SCAN="./..." \ --rm ${{ env.TEST_TAG }} @@ -58,6 +60,8 @@ jobs: run: | set +e + echo "Running Docker command in the current directory: $(pwd)" + if docker run \ -e PACKAGE_TO_SCAN="./..." \ --rm ${{ env.TEST_TAG }}; then From d2d07c2f2a1edac69e8f9a2d77b5ab0a2e7b68d6 Mon Sep 17 00:00:00 2001 From: Daniel Gospodinow Date: Sat, 27 Jan 2024 10:11:40 +0000 Subject: [PATCH 10/10] Mount directory to workflow --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 57bdacc..96d7de8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,6 +51,7 @@ jobs: echo "Running Docker command in the current directory: $(pwd)" docker run \ + -v .:/github/workspace \ -e PACKAGE_TO_SCAN="./..." \ --rm ${{ env.TEST_TAG }} @@ -63,6 +64,7 @@ jobs: echo "Running Docker command in the current directory: $(pwd)" if docker run \ + -v .:/github/workspace \ -e PACKAGE_TO_SCAN="./..." \ --rm ${{ env.TEST_TAG }}; then echo "Container didn't fail when it should've"