Fix migration fail to create entry in gofr_migrations #1881
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Workflow-Pipeline | |
on: | |
push: | |
branches: | |
- main | |
- development | |
paths-ignore: | |
- 'docs/**' | |
pull_request: | |
branches: | |
- main | |
- development | |
paths-ignore: | |
- 'docs/**' | |
jobs: | |
MIGRATION-Unit-Testing: | |
name: Migration Unit Testing (v${{ matrix.go-version }})🛠 | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
go-version: ['1.21', '1.20'] | |
steps: | |
- name: Checkout code into go module directory | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Go ${{ matrix.go-version }} | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ matrix.go-version }} | |
id: Go | |
- name: Get dependencies | |
run: | | |
go mod download | |
- name: Test | |
run: | | |
export APP_ENV=test | |
go test gofr.dev/pkg/gofr/migration... -v -short -coverprofile profile.cov -coverpkg=gofr.dev/pkg/gofr/migration... | |
go tool cover -func profile.cov | |
- name: Upload Test Coverage | |
if: ${{ matrix.go-version == '1.21'}} | |
uses: actions/upload-artifact@v3 | |
with: | |
name: MIGRATION-Coverage-Report | |
path: profile.cov | |
Example-Unit-Testing: | |
name: Example Unit Testing (v${{ matrix.go-version }})🛠 | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
go-version: ['1.21', '1.20'] | |
services: | |
zookeeper: | |
image: wurstmeister/zookeeper | |
ports: | |
- "2181:2181" | |
kafka: | |
image: wurstmeister/kafka | |
ports: | |
- "9092:9092" | |
env: | |
KAFKA_ADVERTISED_LISTENERS: 'PLAINTEXT://localhost:9092' | |
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: 'PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT' | |
KAFKA_INTER_BROKER_LISTENER_NAME: 'PLAINTEXT' | |
KAFKA_ADVERTISED_HOST_NAME: 'localhost' | |
KAFKA_LISTENERS: 'PLAINTEXT://0.0.0.0:9092' | |
KAFKA_AUTO_CREATE_TOPICS_ENABLE: true | |
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181' | |
redis: | |
image: redis:7.0.5 | |
ports: | |
- "2002:6379" | |
options: "--entrypoint redis-server" | |
mysql: | |
image: mysql:8.2.0 | |
ports: | |
- "2001:3306" | |
env: | |
MYSQL_ROOT_PASSWORD: "password" | |
MYSQL_DATABASE: "test" | |
steps: | |
- name: Checkout code into go module directory | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Go ${{ matrix.go-version }} | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ matrix.go-version }} | |
id: Go | |
- name: Get dependencies | |
run: | | |
go mod download | |
- name: Start Zipkin | |
run: docker run -d -p 2005:9411 openzipkin/zipkin:latest | |
- name: Test | |
run: | | |
export APP_ENV=test | |
go test gofr.dev/examples/... -v -short -coverprofile packageWithpbgo.cov -coverpkg=gofr.dev/examples/... | |
grep -vE '^gofr\.dev\/.*\.pb\.go' packageWithpbgo.cov > profile.cov | |
go tool cover -func profile.cov | |
- name: Upload Test Coverage | |
if: ${{ matrix.go-version == '1.21'}} | |
uses: actions/upload-artifact@v3 | |
with: | |
name: Example-Test-Report | |
path: profile.cov | |
PKG-Unit-Testing: | |
name: PKG Unit Testing (v${{ matrix.go-version }})🛠 | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
go-version: ['1.21', '1.20'] | |
steps: | |
- name: Checkout code into go module directory | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Go ${{ matrix.go-version }} | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ matrix.go-version }} | |
id: Go | |
- name: Get dependencies | |
run: | | |
go mod download | |
- name: Test | |
run: | | |
export APP_ENV=test | |
go test gofr.dev/pkg/... -tags migration -v -short -coverprofile packageWithMigration.cov -coverpkg=gofr.dev/pkg/... | |
grep -v 'gofr.dev/pkg/gofr/migration' packageWithMigration.cov > packageWithoutMigration.cov | |
grep -v 'gofr.dev/pkg/gofr/migration/mock_datasources.go' packageWithoutMigration.cov > packageWithoutMockMigrationDatasource.cov | |
grep -v 'gofr.dev/pkg/gofr/container/mock_datasources.go' packageWithoutMockMigrationDatasource.cov > packageWithoutMockDatasource.cov | |
grep -v 'google/mock_interfaces\.go' packageWithoutMockDatasource.cov > profile.cov | |
go tool cover -func profile.cov | |
- name: Upload Test Coverage | |
if: ${{ matrix.go-version == '1.21'}} | |
uses: actions/upload-artifact@v3 | |
with: | |
name: PKG-Coverage-Report | |
path: profile.cov | |
parse_coverage: | |
name: Code Coverage | |
runs-on: ubuntu-latest | |
needs: [ Example-Unit-Testing,PKG-Unit-Testing,MIGRATION-Unit-Testing ] | |
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}' ./Example-Test-Report/profile.cov > merged_profile.cov | |
tail -n +2 ./PKG-Coverage-Report/profile.cov >> merged_profile.cov | |
tail -n +2 ./MIGRATION-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,MIGRATION-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}' ./Example-Test-Report/profile.cov > merged_profile.cov | |
tail -n +2 ./PKG-Coverage-Report/profile.cov >> merged_profile.cov | |
- name: Upload | |
uses: paambaati/codeclimate-action@v5.0.0 | |
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 --timeout 9m0s |