-
Notifications
You must be signed in to change notification settings - Fork 1
126 lines (105 loc) · 3.87 KB
/
Copy pathbuild.yml
File metadata and controls
126 lines (105 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
name: Web Build and Deploy
on:
workflow_dispatch:
push:
branches:
- main
pull_request:
branches:
- main
env:
DOTNET_VERSION: "10.x"
MIN_LINE_COVERAGE: "70"
WEB_SOLUTION_FILE: SchoolAccount.Web.slnx
MAIN_BRANCH: refs/heads/main
IMAGE_NAME: ghcr.io/dfe-digital/schoolaccount-web
CONTAINERAPP_RESOURCE_GROUP: s268d01rg-uks-sa-poc
CONTAINERAPP_NAME: schoolaccount-web-app
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
checks: write
pull-requests: write
steps:
- uses: actions/checkout@v6
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore
run: dotnet restore ${{ env.WEB_SOLUTION_FILE }}
- name: Check formatting
run: |
dotnet tool restore
dotnet csharpier check .
- name: Build
run: dotnet build ${{ env.WEB_SOLUTION_FILE }} --configuration Release --no-restore
- name: Test
run: dotnet test ${{ env.WEB_SOLUTION_FILE }} --configuration Release --no-restore --no-build -- --report-trx --coverage --coverage-output-format cobertura --coverage-settings ${{ github.workspace }}/coverage.config
- name: Test report
uses: EnricoMi/publish-unit-test-result-action@v2
if: ${{ !cancelled() }}
with:
files: "TestResults/*.trx"
- name: Merge coverage reports and enforce threshold
if: ${{ !cancelled() }}
uses: danielpalme/ReportGenerator-GitHub-Action@5
with:
reports: "TestResults/*.cobertura.xml"
targetdir: TestResults/Merged
reporttypes: "Cobertura;MarkdownSummaryGithub"
customSettings: "minimumCoverageThresholds:lineCoverage=${{ env.MIN_LINE_COVERAGE }}"
- name: Write coverage job summary
if: ${{ !cancelled() }}
run: cat TestResults/Merged/SummaryGithub.md >> "$GITHUB_STEP_SUMMARY"
- name: Add coverage comment to PR
if: ${{ !cancelled() && github.event_name == 'pull_request' }}
uses: marocchino/sticky-pull-request-comment@v3
with:
path: TestResults/Merged/SummaryGithub.md
- name: Log in to GHCR
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=sha
type=raw,value=latest,enable=${{ github.ref == env.MAIN_BRANCH }}
type=ref,event=branch
- name: Get SHA image tag
id: image
run: |
IMAGE=$(echo "${{ steps.meta.outputs.tags }}" | grep "sha-" | head -n 1)
echo "image=$IMAGE" >> $GITHUB_OUTPUT
- name: Build & Push Docker image
uses: docker/build-push-action@v7
with:
context: .
file: src/SchoolAccount.Web.Mvc/Dockerfile
target: final
push: ${{ github.ref == env.MAIN_BRANCH }}
tags: ${{ steps.meta.outputs.tags }}
- name: Publish
run: dotnet publish ${{ env.WEB_SOLUTION_FILE }} --configuration Release --no-restore --no-build
- name: Azure Login
if: github.event_name == 'push' && github.ref == env.MAIN_BRANCH
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Update ACA Image
if: github.event_name == 'push' && github.ref == env.MAIN_BRANCH
run: |
az containerapp update \
--name ${{ env.CONTAINERAPP_NAME }} \
--resource-group ${{ env.CONTAINERAPP_RESOURCE_GROUP }} \
--image ${{ steps.image.outputs.image }}