diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 618bb2d..96d7de8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,8 +44,32 @@ jobs: push: true tags: ${{ env.TEST_TAG }} - - name: Run the Container - id: run + - name: No issues in a healthy package + id: test-healthy + working-directory: ./tests/healthypkg run: | + echo "Running Docker command in the current directory: $(pwd)" + docker run \ - --rm ${{ env.TEST_TAG }} || true \ No newline at end of file + -v .:/github/workspace \ + -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 + + 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" + exit 1 + else + echo "Container failed as expected" + exit 0 + fi 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/.*' 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 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