Skip to content

feat(finance): exclude MB products from generic calc engine and enfor… #78

feat(finance): exclude MB products from generic calc engine and enfor…

feat(finance): exclude MB products from generic calc engine and enfor… #78

name: Finance Cost Worker CI/CD
on:
push:
branches: [main, develop]
paths:
- 'services/finance-cost-worker/**'
- 'pkg/costcalc/**'
- 'gen/**'
- '.github/workflows/finance-cost-worker.yml'
pull_request:
branches: [main, develop]
paths:
- 'services/finance-cost-worker/**'
- 'pkg/costcalc/**'
- 'gen/**'
workflow_dispatch:
env:
GO_VERSION: '1.24'
SERVICE_NAME: finance-cost-worker
WORKING_DIR: ./services/finance-cost-worker
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
cache-dependency-path: '**/go.sum'
- name: Download dependencies
working-directory: ${{ env.WORKING_DIR }}
run: go mod download
- name: Vet
working-directory: ${{ env.WORKING_DIR }}
run: go vet ./...
- name: Run tests
working-directory: ${{ env.WORKING_DIR }}
run: go test -v -race -count=1 ./...
build:
name: Build
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
cache-dependency-path: '**/go.sum'
- name: Build binary
working-directory: ${{ env.WORKING_DIR }}
run: |
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags="-s -w -X main.Version=${{ github.sha }}" \
-o ./bin/${{ env.SERVICE_NAME }} \
./cmd/server
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.SERVICE_NAME }}-binary
path: ${{ env.WORKING_DIR }}/bin/${{ env.SERVICE_NAME }}
retention-days: 7
docker:
name: Docker Build & Push
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/${{ env.SERVICE_NAME }}
tags: |
type=sha,prefix=
type=ref,event=branch
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ${{ env.WORKING_DIR }}/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
VERSION=${{ github.sha }}
BUILD_TIME=${{ github.event.head_commit.timestamp }}