name: Questions API on: push: branches: [main] paths: - "api/QuestionsApi/**" - ".github/workflows/questions-api.yml" pull_request: paths: - "api/QuestionsApi/**" - ".github/workflows/questions-api.yml" env: DOTNET_VERSION: "8.0.x" IMAGE_NAME: ghcr.io/${{ github.repository }}/questions-api jobs: build: runs-on: ubuntu-latest permissions: contents: read packages: write steps: - name: Checkout uses: actions/checkout@v4 - name: Setup .NET uses: actions/setup-dotnet@v4 with: dotnet-version: ${{ env.DOTNET_VERSION }} - name: Restore run: dotnet restore api/QuestionsApi/QuestionsApi.csproj - name: Build run: dotnet build api/QuestionsApi/QuestionsApi.csproj --configuration Release --no-restore - name: Publish run: dotnet publish api/QuestionsApi/QuestionsApi.csproj --configuration Release --no-build --output publish/questions-api - name: Upload publish artifact uses: actions/upload-artifact@v4 with: name: questions-api-publish path: publish/questions-api - name: Log in to GitHub Container Registry if: github.event_name == 'push' uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push Docker image if: github.event_name == 'push' uses: docker/build-push-action@v6 with: context: api/QuestionsApi push: true tags: | ${{ env.IMAGE_NAME }}:${{ github.sha }} ${{ env.IMAGE_NAME }}:latest