service (CI/CD) #30
This file contains 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: service | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: self-hosted | |
environment: Default | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- 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@v2 | |
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 }} |