Update ci.yml #3
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: CI | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| build-test-docker: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write # for GHCR pushes (optional) | |
| actions: read | |
| env: | |
| DOTNET_VERSION: "8.0.x" | |
| PUSH_DOCKER: "true" # set to "true" to push image to GHCR | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup .NET SDK | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Restore | |
| run: dotnet restore DevOpsGuard.sln | |
| - name: Build (Release) | |
| run: dotnet build DevOpsGuard.sln -c Release --no-restore | |
| - name: Test | |
| run: dotnet test DevOpsGuard.sln -c Release --no-build --logger "trx;LogFileName=test-results.trx" | |
| - name: Upload test results (always) | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-results | |
| path: '**/TestResults/*.trx' | |
| if-no-files-found: ignore | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GHCR (optional) | |
| if: env.PUSH_DOCKER == 'true' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Compute lowercase image name | |
| id: img | |
| run: | | |
| echo "IMAGE_NAME=ghcr.io/${GITHUB_REPOSITORY,,}/devopsguard-api" >> $GITHUB_ENV | |
| echo "Computed IMAGE_NAME=$IMAGE_NAME" | |
| - name: Build API image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: src/DevOpsGuard.Api/Dockerfile | |
| build-args: | | |
| DOTNET_ENVIRONMENT=Production | |
| push: ${{ env.PUSH_DOCKER == 'true' }} | |
| tags: | | |
| ${{ env.IMAGE_NAME }}:sha-${{ github.sha }} | |
| ${{ env.IMAGE_NAME }}:latest | |
| - name: Upload API image digest (artifact) | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: docker-digest | |
| path: | | |
| **/build-metadata.json | |
| if-no-files-found: ignore |