diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 37a13a8f08..d0d6fde125 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,108 +1,95 @@ -# CI for Product Catalog Service +# est-harshname: product-catalog-ci -name: product-catalog-ci - -on: - pull_request: - branches: - - main +on: + pull_request: + branches: + - main jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: checkout code - uses: actions/checkout@v4 - - - name: Setup Go 1.22 - uses: actions/setup-go@v2 - with: - go-version: 1.22 - - - name: Build - run: | - cd src/product-catalog - go mod download - go build -o product-catalog-service main.go - - - name: unit tests - run: | - cd src/product-catalog - go test ./... - - code-quality: - runs-on: ubuntu-latest - - steps: - - name: checkout code - uses: actions/checkout@v4 - - - name: Setup Go 1.22 - uses: actions/setup-go@v2 - with: - go-version: 1.22 - - - name: Run golangci-lint - uses: golangci/golangci-lint-action@v6 - with: - version: v1.55.2 - run: golangci-lint run - working-directory: src/product-catalog - - docker: - runs-on: ubuntu-latest - - needs: build - - steps: - - name: checkout code - uses: actions/checkout@v4 - - - name: Install Docker - uses: docker/setup-buildx-action@v1 - - - name: Login to Docker - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_TOKEN }} - - - name: Docker Push - uses: docker/build-push-action@v6 - with: - context: src/product-catalog - file: src/product-catalog/Dockerfile - push: true - tags: ${{ secrets.DOCKER_USERNAME }}/product-catalog:${{github.run_id}} - - - updatek8s: - runs-on: ubuntu-latest - - needs: docker - - steps: - - name: checkout code - uses: actions/checkout@v4 - with: - token: ${{ secrets.GITHUB_TOKEN }} - - - name: Update tag in kubernetes deployment manifest - run: | - sed -i "s|image: .*|image: ${{ secrets.DOCKER_USERNAME }}/product-catalog:${{github.run_id}}|" kubernetes/productcatalog/deploy.yaml - - - name: Commit and push changes - run: | - git config --global user.email "estharsh@gmail.com" - git config --global user.name "Harsh Pratap" - git add kubernetes/productcatalog/deploy.yaml - git commit -m "[CI]: Update product catalog image tag" - git push origin HEAD:main -f - - - - + build: + runs-on: ubuntu-latest + steps: + - name: checkout code + uses: actions/checkout@v4 + + - name: Setup Go 1.22 + uses: actions/setup-go@v5 # Using a more recent version + with: + go-version: '1.22' + + - name: Build + run: | + cd src/product-catalog + go mod download + go build -o product-catalog-service main.go + + - name: unit tests + run: | + cd src/product-catalog + go test ./... + + code-quality: + runs-on: ubuntu-latest + steps: + - name: checkout code + uses: actions/checkout@v4 + + - name: Setup Go 1.22 + uses: actions/setup-go@v5 # Using a more recent version + with: + go-version: '1.22' + + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.55.2 + # 'run:' is not a valid parameter for this action, the command runs by default + working-directory: src/product-catalog + + docker: + runs-on: ubuntu-latest + needs: build + steps: + - name: checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 # Using a more recent version + + - name: Login to Docker + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + + - name: Docker Push + uses: docker/build-push-action@v6 + with: + context: src/product-catalog + file: src/product-catalog/Dockerfile + push: true + tags: ${{ secrets.DOCKER_USERNAME }}/product-catalog:${{ github.run_id }} + + updatek8s: + runs-on: ubuntu-latest + needs: docker + steps: + - name: checkout code + uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Update tag in kubernetes deployment manifest + run: | + sed -i "s|image: .*|image: ${{ secrets.DOCKER_USERNAME }}/product-catalog:${{ github.run_id }}|" kubernetes/productcatalog/deploy.yaml - + + + - name: Commit and push changes + run: | + git config --global user.email "estharsh@gmail.com" + git config --global user.name "Harsh Pratap" + git add kubernetes/productcatalog/deploy.yaml + git commit -m "[CI]: Update product catalog image tag" + git push origin HEAD:main -f \ No newline at end of file diff --git a/src/product-catalog/main.go b/src/product-catalog/main.go index f62c3c0d94..dc48cec9ca 100644 --- a/src/product-catalog/main.go +++ b/src/product-catalog/main.go @@ -320,3 +320,27 @@ func createClient(ctx context.Context, svcAddr string) (*grpc.ClientConn, error) + + + + + + + + + + + + + + + + + + + + + + + +