Githubcicheck #281
This file contains hidden or 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: product-catalog-ci | ||
on: | ||
push: | ||
branches: | ||
- main | ||
- githubcicheck # add more feature branches if needed | ||
pull_request: | ||
branches: | ||
- main | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
go-version: [1.21.x, 1.22.x, 1.23.x] # test against multiple Go versions | ||
name: Go ${{ matrix.go-version }} CI | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
- name: Install dependencies | ||
run: go mod tidy | ||
working-directory: src/product-catalog | ||
- name: Build | ||
run: go build ./... | ||
working-directory: src/product-catalog | ||
- name: Run tests | ||
run: go test -v ./... | ||
working-directory: src/product-catalog | ||
code-quality: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Run golangci-lint | ||
run: | | ||
go install github.com/golangci/golangci-lint/cmd/[email protected] | ||
export PATH=$PATH:$(go env GOPATH)/bin | ||
golangci-lint run ./... | ||
working-directory: src/product-catalog | ||
docker: | ||
runs-on: ubuntu-latest | ||
needs: [build, code-quality] | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Install Docker | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Login to Docker | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_TOKEN }} | ||
- name: Docker Build & 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-service:${{ github.sha }} | ||
updatek8: | ||
if: github.ref == 'refs/heads/main' | ||
runs-on: ubuntu-latest | ||
needs: docker | ||
- name: Commit and push changes | ||
run: | | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "shahipranav" | ||
git add kubernetes/productcatalog/deploy.yaml | ||
git commit -m "[CI]: update product catalog image tag" | ||
git push |