From 2f1da566e946a09dc4215758ead4ee07eb099efe Mon Sep 17 00:00:00 2001 From: yashranjan1 Date: Mon, 28 Jul 2025 17:00:36 +0530 Subject: [PATCH 1/2] added code coverage --- .github/workflows/ci.yml | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a98bfa8..179dcf0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: Go Build, Test, and Format +name: Go CI on: push: @@ -11,8 +11,8 @@ on: - 'v[0-9]+.[0-9]+.[0-9]+' jobs: - build-test: - name: Build and Test on ${{ matrix.os }} + test-matrix: + name: Test on ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: matrix: @@ -33,10 +33,33 @@ jobs: - name: Run Tests run: go test ./... + coverage: + name: Code Coverage + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.24.4' + + - name: Run tests with coverage + run: | + go test -coverprofile=coverage.out ./... + go tool cover -func=coverage.out + + - name: Upload coverage artifact + uses: actions/upload-artifact@v4 + with: + name: coverage-report + path: coverage.out + format: - name: Format + name: Format runs-on: ubuntu-latest - if: github.event_name == 'push' # only format on push events (not PRs from forks) steps: - name: Checkout code @@ -47,16 +70,15 @@ jobs: with: go-version: '1.24.4' - - name: Auto-format code with gofmt and commit changes + - name: Auto-format code and commit changes run: | gofmt -w . if [ -n "$(git status --porcelain)" ]; then - echo "Code was not formatted. Applying gofmt and committing changes..." + echo "Formatting changes detected. Committing..." git config user.name "github-actions" git config user.email "github-actions@github.com" git add . git commit -m "chore: auto-format Go code via gofmt" git push else - echo "Code already properly formatted." - fi + echo "Code is already formatted. No changes needed." From af148e9fc4c51ee1ee6fc97509198bc7ff1bb87e Mon Sep 17 00:00:00 2001 From: yashranjan1 Date: Mon, 28 Jul 2025 17:04:25 +0530 Subject: [PATCH 2/2] fix: unexpected eof --- .github/workflows/ci.yml | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 179dcf0..382dd52 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,8 +11,8 @@ on: - 'v[0-9]+.[0-9]+.[0-9]+' jobs: - test-matrix: - name: Test on ${{ matrix.os }} + build-test: + name: Build, Test & Coverage on ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: matrix: @@ -30,36 +30,23 @@ jobs: - name: Build run: go build ./... - - name: Run Tests - run: go test ./... - - coverage: - name: Code Coverage - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: '1.24.4' - - - name: Run tests with coverage + - name: Run Tests with Coverage run: | go test -coverprofile=coverage.out ./... go tool cover -func=coverage.out + shell: bash - - name: Upload coverage artifact + - name: Upload coverage report + if: matrix.os == 'ubuntu-latest' uses: actions/upload-artifact@v4 with: name: coverage-report path: coverage.out format: - name: Format + name: Auto-format with gofmt (Linux only) runs-on: ubuntu-latest + if: github.event_name == 'push' && github.repository_owner == github.actor steps: - name: Checkout code @@ -70,15 +57,16 @@ jobs: with: go-version: '1.24.4' - - name: Auto-format code and commit changes + - name: Run gofmt and commit changes if needed run: | gofmt -w . if [ -n "$(git status --porcelain)" ]; then - echo "Formatting changes detected. Committing..." + echo "Code was not formatted. Committing changes..." git config user.name "github-actions" git config user.email "github-actions@github.com" git add . git commit -m "chore: auto-format Go code via gofmt" git push else - echo "Code is already formatted. No changes needed." + echo "Code already properly formatted." + fi