|
| 1 | +name: Build, Test, Publish Image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + paths: |
| 7 | + - 'Homeworks/06 Настройка CI/**' |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: ci-main |
| 11 | + cancel-in-progress: false |
| 12 | + |
| 13 | +env: |
| 14 | + REGISTRY: ghcr.io |
| 15 | + IMAGE_NAME: ${{ github.repository }} |
| 16 | + PROJECT_DIR: 'Homeworks/06 Настройка CI/src' |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: read |
| 20 | + packages: write |
| 21 | + |
| 22 | +jobs: |
| 23 | + build-test-push: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + defaults: |
| 26 | + run: |
| 27 | + working-directory: ${{ env.PROJECT_DIR }} |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Checkout |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Check working directory |
| 34 | + run: pwd |
| 35 | + |
| 36 | + - name: Build-dotnet |
| 37 | + uses: ./.github/actions/build-dotnet |
| 38 | + with: |
| 39 | + project-dir: ${{ env.PROJECT_DIR }} |
| 40 | + |
| 41 | + - name: Run tests |
| 42 | + run: | |
| 43 | + dotnet test --configuration Release --no-build --no-restore --collect:"XPlat Code Coverage" \ |
| 44 | + --settings "PromoCodeFactory.UnitTests/coverage.runsettings" --logger "trx" |
| 45 | +
|
| 46 | + - name: Generate HTML Coverage Report |
| 47 | + uses: danielpalme/ReportGenerator-GitHub-Action@5 |
| 48 | + with: |
| 49 | + reports: '${{ env.PROJECT_DIR }}/*/TestResults/*/coverage.cobertura.xml' |
| 50 | + targetdir: '${{ env.PROJECT_DIR }}/coveragereport' |
| 51 | + reporttypes: 'Html' |
| 52 | + |
| 53 | + - name: Upload coverage report |
| 54 | + uses: actions/upload-artifact@v4 |
| 55 | + with: |
| 56 | + name: coverage-html |
| 57 | + path: '${{ env.PROJECT_DIR }}/coveragereport/' |
| 58 | + |
| 59 | + - name: Publish test results |
| 60 | + if: always() |
| 61 | + uses: actions/upload-artifact@v4 |
| 62 | + with: |
| 63 | + name: test-results |
| 64 | + path: '${{ env.PROJECT_DIR }}/*/TestResults/*.trx' |
| 65 | + |
| 66 | + - name: Log in to container registry |
| 67 | + uses: docker/login-action@v3 |
| 68 | + with: |
| 69 | + registry: ${{ env.REGISTRY }} |
| 70 | + username: ${{ github.actor }} |
| 71 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 72 | + |
| 73 | + - name: Extract metadata (tags, labels) |
| 74 | + id: meta |
| 75 | + uses: docker/metadata-action@v5 |
| 76 | + with: |
| 77 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 78 | + tags: | |
| 79 | + type=sha |
| 80 | + type=ref,event=branch |
| 81 | + type=ref,event=tag |
| 82 | + type=raw,value=latest,enable={{is_default_branch}} |
| 83 | +
|
| 84 | + - name: Build and push Docker image |
| 85 | + uses: docker/build-push-action@v6 |
| 86 | + with: |
| 87 | + context: '${{ env.PROJECT_DIR }}' |
| 88 | + file: '${{ env.PROJECT_DIR }}/Dockerfile.ci' |
| 89 | + push: true |
| 90 | + tags: ${{ steps.meta.outputs.tags }} |
| 91 | + labels: ${{ steps.meta.outputs.labels }} |
0 commit comments