Githubcicheck #285
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 | ||
- name: Setup Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: ${{matrix.go-version}} | ||
- name: Build | ||
run: | | ||
cd src/product-catalog | ||
go mod download | ||
go build -o product-catalog-service main.go | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
steps: | ||
- name: checkout code | ||
uses: actions/checkout@v4 | ||
- name: Setup Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{matrix.go-version}} | ||
- name: Run golangci-lint | ||
uses: golangci/golangci-lint-action@v6 | ||
with: | ||
version: v1.54.2 | ||
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 | ||
- 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 | ||
docker: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
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.run_id }} | ||
updatek8: | ||
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-service:'"${{ github.run_id }}"'|' kubernetes/productcatalog/deploy.yaml | ||
- 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 | ||
m |