Skip to content

Commit

Permalink
Fix/gofr (#180)
Browse files Browse the repository at this point in the history
* Update Workflow
* Fixed Linters
* Fixed Tests
* Update to latest go version
* Update module name

---------

Co-authored-by: aryan-mehrotra-zs <[email protected]>
Co-authored-by: vipul-rawat-zs <[email protected]>
Co-authored-by: umang01-hash <[email protected]>
  • Loading branch information
4 people authored Jan 4, 2024
1 parent 64a375b commit 0d51eae
Show file tree
Hide file tree
Showing 37 changed files with 380 additions and 241 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "weekly"
37 changes: 37 additions & 0 deletions .github/workflows/changes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

filename="$1"

# Create or clear the coveragetable.md file
touch build/coveragetable.md

# Append total coverage information to coveragetable.md
echo -n "### Total coverage : " >> build/coveragetable.md
# Filter and assign files to trimmed_content based on conditions:
# - Files ending with ".go" are considered.
# - Files with status "A" or "M" are included.
# - Files with status "RXXX" are included, except for "R100".
go tool cover -func build/coverage.out | grep 'total' | awk '{print $3}' >> build/coveragetable.md

# Extract changed file paths from the provided file
trimmed_content=$(grep -E '\.go$' "$filename" | awk '{ if ($1 ~ /^R/ && $1 !~ /^R100/) print $3; else if ($1 ~ /^[AM]/) print $2 }')

if [[ -z "$trimmed_content" ]]; then
echo "### No Files Are Changed." >> build/coveragetable.md
else
echo "List of changed files" >> build/coveragetable.md
echo -e "\n" >> build/coveragetable.md
echo "| Path | Function | Coverage |" >> build/coveragetable.md
echo "|------|----------|----------|" >> build/coveragetable.md

while IFS= read -r line; do
echo "$line"
if [[ $line == *.go ]]; then
# Extract coverage information for each changed file and append to coveragetable.md
go tool cover -func=build/coverage.out | grep "$line" | awk 'BEGIN{OFS=" | "} {print "|" $1, $2, $3 "|"}' >> build/coveragetable.md
fi
done <<< "$trimmed_content"
fi

# Append the content of coveragetable.md to the GITHUB_STEP_SUMMARY file
cat build/coveragetable.md >> "$GITHUB_STEP_SUMMARY"
70 changes: 0 additions & 70 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

211 changes: 159 additions & 52 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,71 +1,178 @@
name: Go
name: Workflow-Pipeline

on:
push:
branches: [ "main", "dev"]
branches:
- main
- development
pull_request:
branches: [ "main", "dev"]
branches:
- main
- development

jobs:
test:
name: Test
Example-Unit-Testing:
name: Example Unit Testing🛠
runs-on: ubuntu-latest
services:
redis:
image: redis
image: redis:7.0.5
ports:
- 6379:6379
options: --entrypoint redis-server
- "6379:6379"
options: "--entrypoint redis-server"

mysql:
image: mysql
image: mysql:8.0.30
ports:
- 3306:3306
- "3306:3306"
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: test
MYSQL_ROOT_PASSWORD: "password"
MYSQL_DATABASE: "test"

steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.13
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Get dependencies
run: |
go get -v -t -d ./...
- name: Test
run: |
go test ./... -v -coverprofile profile.cov -coverpkg=./...
go tool cover -func profile.cov
- name: Send coverage to coveralls
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: profile.cov
parallel: true

- name: Send coverage to CodeClimate
uses: paambaati/[email protected]
env:
CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
with:
debug: true
coverageLocations: profile.cov:gocov
prefix: github.com/vikash/gofr

code_quality:
name: Code Quality
- name: Checkout code into go module directory
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go 1.21
uses: actions/setup-go@v4
with:
go-version: 1.21
id: Go

- name: Get dependencies
run: |
go mod download
- name: Test
run: |
export GOFR_ENV=test
go test gofr.dev/examples/... -v -short -coverprofile profile.cov -coverpkg=gofr.dev/examples/...
go tool cover -func profile.cov
- name: Upload Test Coverage
uses: actions/upload-artifact@v3
with:
name: Example-Test-Report
path: profile.cov

PKG-Unit-Testing:
name: PKG Unit Testing🛠
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0.30
ports:
- "3306:3306"
env:
MYSQL_ROOT_PASSWORD: "password"

redis:
image: redis:7.0.5
ports:
- "6379:6379"
options: "--entrypoint redis-server"

steps:
- name: Checkout code into go module directory
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go 1.21
uses: actions/setup-go@v4
with:
go-version: 1.21
id: Go

- name: Get dependencies
run: |
go mod download
- name: Test
run: |
export GOFR_ENV=test
go test gofr.dev/pkg/... -v -short -coverprofile profile.cov -coverpkg=gofr.dev/pkg/...
go tool cover -func profile.cov
- name: Upload Test Coverage
uses: actions/upload-artifact@v3
with:
name: PKG-Coverage-Report
path: profile.cov

parse_coverage:
name: Code Coverage
runs-on: ubuntu-latest
container: golangci/golangci-lint:v1.37.1
needs: [Example-Unit-Testing,PKG-Unit-Testing]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Download Coverage Report
uses: actions/download-artifact@v3
with:
path: artifacts

- name: golangci-lint
- name: Merge Coverage Files
working-directory: artifacts
run: |
awk '!/^mode: / && FNR==1{print "mode: set"} {print}' ./Example-Test-Report/profile.cov > merged_profile.cov
tail -n +2 ./PKG-Coverage-Report/profile.cov >> merged_profile.cov
- name: Parse code-coverage value
working-directory: artifacts
run: |
codeCoverage=$(go tool cover -func=merged_profile.cov | grep total | awk '{print $3}')
codeCoverage=${codeCoverage%?}
echo "CODE_COVERAGE=$codeCoverage" >> $GITHUB_ENV
# - name: Check if code-coverage is greater than threshold
# run: |
# codeCoverage=${{ env.CODE_COVERAGE }}
# codeCoverage=${codeCoverage%??}
# if [[ $codeCoverage -lt 92 ]]; then echo "code coverage cannot be less than 92%, currently its ${{ env.CODE_COVERAGE }}%" && exit 1; fi;

upload_coverage:
name: Upload Coverage📊
runs-on: ubuntu-latest
needs: [Example-Unit-Testing,PKG-Unit-Testing]
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/development' }}
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Download Coverage Report
uses: actions/download-artifact@v3
with:
path: artifacts

- name: Merge Coverage Files
working-directory: artifacts
run: |
awk '!/^mode: / && FNR==1{print "mode: set"} {print}' ./CMD-Test-Report/profile.cov > merged_profile.cov
tail -n +2 ./Example-Test-Report/profile.cov >> merged_profile.cov
tail -n +2 ./PKG-Coverage-Report/profile.cov >> merged_profile.cov
- name: Upload
uses: paambaati/[email protected]
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
with:
coverageLocations: artifacts/merged_profile.cov:gocov
prefix: gofr.dev

code_quality:
name: Code Quality🎖️
runs-on: ubuntu-latest
container: "golangci/golangci-lint:v1.55.2"
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
- name: Get dependencies
run: go get -v -t -d ./...
- name: GolangCI-Lint
run: |
golangci-lint run
golangci-lint run --timeout 9m0s
7 changes: 3 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ linters-settings:
lines: 100
statements: 50
gci:
local-prefixes: github.com/vikash/gofr
local-prefixes: gofr.dev
goconst:
min-len: 2
min-occurrences: 2
Expand Down Expand Up @@ -40,8 +40,8 @@ linters-settings:
settings:
printf:
funcs:
- (github.com/vikash/gofr/pkg/gofr/Logger).Logf
- (github.com/vikash/gofr/pkg/gofr/Logger).Errorf
- (gofr.dev/pkg/gofr/Logger).Logf
- (gofr.dev/pkg/gofr/Logger).Errorf
lll:
line-length: 140
maligned:
Expand All @@ -62,7 +62,6 @@ linters:
- asciicheck
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
- errcheck
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
FROM golang:1.16

RUN mkdir -p /go/src/github.com/vikash/gofr
WORKDIR /go/src/github.com/vikash/gofr
RUN mkdir -p /go/src/gofr.dev
WORKDIR /go/src/gofr.dev
COPY . .

RUN go build -ldflags "-linkmode external -extldflags -static" -a examples/simple-api/main.go

FROM alpine:latest
RUN apk add --no-cache tzdata ca-certificates
COPY --from=0 /go/src/github.com/vikash/gofr/main /main
COPY --from=0 /go/src/gofr.dev/main /main
EXPOSE 8000
CMD ["/main"]
Loading

0 comments on commit 0d51eae

Please sign in to comment.