Skip to content

core-service (CI/CD) #3

core-service (CI/CD)

core-service (CI/CD) #3

name: core-service (CI/CD)
on:
# push:
# branches:
# - main
# pull_request:
# branches:
# - main
workflow_dispatch:
jobs:
build:
runs-on: self-hosted
environment: Default
outputs:
image-tag: ${{ steps.gitversion.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Restore
run: dotnet restore
- name: Build
run: dotnet build --no-restore --configuration Release
- name: Run Unit Tests
run: |
dotnet test --filter "Tests.Units" \
--results-directory ./tests/reports/ \
--logger "trx;LogFileName=unit-tests.trx"
- name: Run Integration Tests
run: |
dotnet test --filter "Tests.Integrations" \
/p:CollectCoverage=true \
/p:CoverletOutputFormat=cobertura \
/p:CoverletOutput=./reports/code-coverage.xml
- name: Upload Unit Tests
uses: actions/upload-artifact@v4
with:
name: unit-test-results
path: ./tests/reports/unit-tests.trx
- name: Upload Code Coverage
uses: actions/upload-artifact@v4
with:
name: code-coverage-results
path: ./tests/reports/code-coverage.xml
- name: Login Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Install GitVersion
id: gitversion
uses: codacy/git-version@2.7.1
- name: Build Docker Image
run: docker build -t ${{ github.repository }}:latest .
- name: Tag Docker Image
run: |
docker tag ${{ github.repository }}:latest ${{ github.repository }}:${{ steps.gitversion.outputs.version }}
echo "Image tagged as ${{ github.repository }}:${{ steps.gitversion.outputs.version }}"
- name: Push Docker Image
run: docker push ${{ github.repository }}:${{ steps.gitversion.outputs.version }}
deploy:
runs-on: self-hosted
environment: Default
needs: build
steps:
- name: Configure kubectl
run: echo "${{ secrets.KUBECONFIG }}" | base64 --decode > $HOME/.kube/config
- name: Deploy with Helm
run: |
helm upgrade --install core-service ./helm-chart/core-service \
--set deployment.image.tag=${{ needs.build.outputs.image-tag }}