|
1 | | -name: Go |
| 1 | +name: Workflow-Pipeline |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | | - branches: [ "main", "dev"] |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - development |
6 | 8 | pull_request: |
7 | | - branches: [ "main", "dev"] |
| 9 | + branches: |
| 10 | + - main |
| 11 | + - development |
8 | 12 |
|
9 | 13 | jobs: |
10 | | - test: |
11 | | - name: Test |
| 14 | + Example-Unit-Testing: |
| 15 | + name: Example Unit Testing🛠 |
12 | 16 | runs-on: ubuntu-latest |
13 | 17 | services: |
14 | 18 | redis: |
15 | | - image: redis |
| 19 | + image: redis:7.0.5 |
16 | 20 | ports: |
17 | | - - 6379:6379 |
18 | | - options: --entrypoint redis-server |
| 21 | + - "6379:6379" |
| 22 | + options: "--entrypoint redis-server" |
| 23 | + |
19 | 24 | mysql: |
20 | | - image: mysql |
| 25 | + image: mysql:8.0.30 |
21 | 26 | ports: |
22 | | - - 3306:3306 |
| 27 | + - "3306:3306" |
23 | 28 | env: |
24 | | - MYSQL_ROOT_PASSWORD: password |
25 | | - MYSQL_DATABASE: test |
| 29 | + MYSQL_ROOT_PASSWORD: "password" |
| 30 | + MYSQL_DATABASE: "test" |
26 | 31 |
|
27 | 32 | steps: |
28 | | - - name: Set up Go 1.x |
29 | | - uses: actions/setup-go@v2 |
30 | | - with: |
31 | | - go-version: ^1.13 |
32 | | - id: go |
33 | | - |
34 | | - - name: Check out code into the Go module directory |
35 | | - uses: actions/checkout@v2 |
36 | | - |
37 | | - - name: Get dependencies |
38 | | - run: | |
39 | | - go get -v -t -d ./... |
40 | | -
|
41 | | - - name: Test |
42 | | - run: | |
43 | | - go test ./... -v -coverprofile profile.cov -coverpkg=./... |
44 | | - go tool cover -func profile.cov |
45 | | - |
46 | | - - name: Send coverage to coveralls |
47 | | - uses: shogo82148/actions-goveralls@v1 |
48 | | - with: |
49 | | - path-to-profile: profile.cov |
50 | | - parallel: true |
51 | | - |
52 | | - - name: Send coverage to CodeClimate |
53 | | - |
54 | | - env: |
55 | | - CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}} |
56 | | - with: |
57 | | - debug: true |
58 | | - coverageLocations: profile.cov:gocov |
59 | | - prefix: github.com/vikash/gofr |
60 | | - |
61 | | - code_quality: |
62 | | - name: Code Quality |
| 33 | + - name: Checkout code into go module directory |
| 34 | + uses: actions/checkout@v4 |
| 35 | + with: |
| 36 | + fetch-depth: 0 |
| 37 | + |
| 38 | + - name: Set up Go 1.21 |
| 39 | + uses: actions/setup-go@v4 |
| 40 | + with: |
| 41 | + go-version: 1.21 |
| 42 | + id: Go |
| 43 | + |
| 44 | + - name: Get dependencies |
| 45 | + run: | |
| 46 | + go mod download |
| 47 | +
|
| 48 | + - name: Test |
| 49 | + run: | |
| 50 | + export GOFR_ENV=test |
| 51 | + go test gofr.dev/examples/... -v -short -coverprofile profile.cov -coverpkg=gofr.dev/examples/... |
| 52 | + go tool cover -func profile.cov |
| 53 | +
|
| 54 | + - name: Upload Test Coverage |
| 55 | + uses: actions/upload-artifact@v3 |
| 56 | + with: |
| 57 | + name: Example-Test-Report |
| 58 | + path: profile.cov |
| 59 | + |
| 60 | + PKG-Unit-Testing: |
| 61 | + name: PKG Unit Testing🛠 |
| 62 | + runs-on: ubuntu-latest |
| 63 | + services: |
| 64 | + mysql: |
| 65 | + image: mysql:8.0.30 |
| 66 | + ports: |
| 67 | + - "3306:3306" |
| 68 | + env: |
| 69 | + MYSQL_ROOT_PASSWORD: "password" |
| 70 | + |
| 71 | + redis: |
| 72 | + image: redis:7.0.5 |
| 73 | + ports: |
| 74 | + - "6379:6379" |
| 75 | + options: "--entrypoint redis-server" |
| 76 | + |
| 77 | + steps: |
| 78 | + - name: Checkout code into go module directory |
| 79 | + uses: actions/checkout@v4 |
| 80 | + with: |
| 81 | + fetch-depth: 0 |
| 82 | + |
| 83 | + - name: Set up Go 1.21 |
| 84 | + uses: actions/setup-go@v4 |
| 85 | + with: |
| 86 | + go-version: 1.21 |
| 87 | + id: Go |
| 88 | + |
| 89 | + - name: Get dependencies |
| 90 | + run: | |
| 91 | + go mod download |
| 92 | +
|
| 93 | + - name: Test |
| 94 | + run: | |
| 95 | + export GOFR_ENV=test |
| 96 | + go test gofr.dev/pkg/... -v -short -coverprofile profile.cov -coverpkg=gofr.dev/pkg/... |
| 97 | + go tool cover -func profile.cov |
| 98 | +
|
| 99 | + - name: Upload Test Coverage |
| 100 | + uses: actions/upload-artifact@v3 |
| 101 | + with: |
| 102 | + name: PKG-Coverage-Report |
| 103 | + path: profile.cov |
| 104 | + |
| 105 | + parse_coverage: |
| 106 | + name: Code Coverage |
63 | 107 | runs-on: ubuntu-latest |
64 | | - container: golangci/golangci-lint:v1.37.1 |
| 108 | + needs: [Example-Unit-Testing,PKG-Unit-Testing] |
65 | 109 | steps: |
66 | | - - name: Checkout code |
67 | | - uses: actions/checkout@v2 |
| 110 | + - name: Check out code into the Go module directory |
| 111 | + uses: actions/checkout@v4 |
| 112 | + |
| 113 | + - name: Download Coverage Report |
| 114 | + uses: actions/download-artifact@v3 |
| 115 | + with: |
| 116 | + path: artifacts |
68 | 117 |
|
69 | | - - name: golangci-lint |
| 118 | + - name: Merge Coverage Files |
| 119 | + working-directory: artifacts |
| 120 | + run: | |
| 121 | + awk '!/^mode: / && FNR==1{print "mode: set"} {print}' ./Example-Test-Report/profile.cov > merged_profile.cov |
| 122 | + tail -n +2 ./PKG-Coverage-Report/profile.cov >> merged_profile.cov |
| 123 | + |
| 124 | + - name: Parse code-coverage value |
| 125 | + working-directory: artifacts |
| 126 | + run: | |
| 127 | + codeCoverage=$(go tool cover -func=merged_profile.cov | grep total | awk '{print $3}') |
| 128 | + codeCoverage=${codeCoverage%?} |
| 129 | + echo "CODE_COVERAGE=$codeCoverage" >> $GITHUB_ENV |
| 130 | + |
| 131 | +# - name: Check if code-coverage is greater than threshold |
| 132 | +# run: | |
| 133 | +# codeCoverage=${{ env.CODE_COVERAGE }} |
| 134 | +# codeCoverage=${codeCoverage%??} |
| 135 | +# if [[ $codeCoverage -lt 92 ]]; then echo "code coverage cannot be less than 92%, currently its ${{ env.CODE_COVERAGE }}%" && exit 1; fi; |
| 136 | + |
| 137 | + upload_coverage: |
| 138 | + name: Upload Coverage📊 |
| 139 | + runs-on: ubuntu-latest |
| 140 | + needs: [Example-Unit-Testing,PKG-Unit-Testing] |
| 141 | + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/development' }} |
| 142 | + steps: |
| 143 | + - name: Check out code into the Go module directory |
| 144 | + uses: actions/checkout@v4 |
| 145 | + |
| 146 | + - name: Download Coverage Report |
| 147 | + uses: actions/download-artifact@v3 |
| 148 | + with: |
| 149 | + path: artifacts |
| 150 | + |
| 151 | + - name: Merge Coverage Files |
| 152 | + working-directory: artifacts |
| 153 | + run: | |
| 154 | + awk '!/^mode: / && FNR==1{print "mode: set"} {print}' ./CMD-Test-Report/profile.cov > merged_profile.cov |
| 155 | + tail -n +2 ./Example-Test-Report/profile.cov >> merged_profile.cov |
| 156 | + tail -n +2 ./PKG-Coverage-Report/profile.cov >> merged_profile.cov |
| 157 | +
|
| 158 | +
|
| 159 | + - name: Upload |
| 160 | + |
| 161 | + env: |
| 162 | + CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} |
| 163 | + with: |
| 164 | + coverageLocations: artifacts/merged_profile.cov:gocov |
| 165 | + prefix: gofr.dev |
| 166 | + |
| 167 | + code_quality: |
| 168 | + name: Code Quality🎖️ |
| 169 | + runs-on: ubuntu-latest |
| 170 | + container: "golangci/golangci-lint:v1.55.2" |
| 171 | + steps: |
| 172 | + - name: Check out code into the Go module directory |
| 173 | + uses: actions/checkout@v4 |
| 174 | + - name: Get dependencies |
| 175 | + run: go get -v -t -d ./... |
| 176 | + - name: GolangCI-Lint |
70 | 177 | run: | |
71 | | - golangci-lint run |
| 178 | + golangci-lint run --timeout 9m0s |
0 commit comments