-
Notifications
You must be signed in to change notification settings - Fork 21
164 lines (140 loc) · 5.73 KB
/
main_build-blazor.yml
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# This workflow has three examples (one for IIS, two using containers)
# [Option A] Typical IIS build & publish
# [Option B] DOCKER FILE BUILD - publishes the image to ghcr.io (GitHub container registry)
# [Option C] .NET SDK CONTAINER BUILD - publishes the image to Docker Hub
name: Blazor (with Reporting)
on:
workflow_dispatch:
push:
branches:
- main
- "blazor/*"
paths:
- 'src/Blazor/**/*'
- '.github/workflows/main_build-blazor.yml'
env:
CONFIGURATION: Release
BLAZOR_PROJ_PATH: src/Blazor/MyBlazorApp/MyBlazorApp.csproj
TEST_PROJ_PATH: src/Blazor/MyBlazorApp.Tests/MyBlazorApp.Tests.csproj
NUGET_CONFIG_PATH: src/NuGet.Config
DOTNET_VERSION: "9.0.x"
jobs:
#####################################################
######### [Option A] WINDOWS BUILD (IIS) ############
#####################################################
build_windows:
runs-on: windows-2022
env:
RID: win-x64
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{env.DOTNET_VERSION}}
- name: Restore NuGet Packages
run: |
dotnet restore ${{env.BLAZOR_PROJ_PATH}} --configfile ${{env.NUGET_CONFIG_PATH}} -r ${{env.RID}}
dotnet restore ${{env.TEST_PROJ_PATH}} --configfile ${{env.NUGET_CONFIG_PATH}} -r ${{env.RID}}
env:
TELERIK_USERNAME: "api-key"
TELERIK_PASSWORD: ${{secrets.TELERIK_NUGET_KEY}}
- name: Build Test Project
run: dotnet build ${{env.TEST_PROJ_PATH}} -c ${{env.CONFIGURATION}} -r ${{env.RID}} --no-restore
- name: Run Tests
run: dotnet test ${{env.TEST_PROJ_PATH}} -r ${{env.RID}}
######################################################
############ [Option B] DOCKER FILE BUILD ############
######################################################
# Publishes to ghcr.io!
build_container_with_dockerfile:
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate tag version
id: tag-creator
run: |
buildDay=`date +%Y.%m.%d`
tags="$buildDay.$GITHUB_RUN_NUMBER"
echo "VERSION_TAG=$tags" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}
- name: Build and Publish Container Images
uses: docker/build-push-action@v5
with:
context: src/Blazor/MyBlazorApp
platforms: linux/arm64,linux/amd64
push: true
secrets: |
telerik_key=${{secrets.TELERIK_NUGET_KEY}}
tags: |
"ghcr.io/lancemccarthy/myblazorapp:${{steps.tag-creator.outputs.VERSION_TAG}}"
"ghcr.io/lancemccarthy/myblazorapp:latest"
##########################################################
######### [Option C] .NET SDK CONTAINER BUILD ############
##########################################################
# Publishes to registry.hub.docker.com!
build_container_with_dotnet:
runs-on: ubuntu-22.04
permissions:
id-token: write
contents: read
env:
RID: linux-x64
CONTAINER_BASE_IMAGE: "mcr.microsoft.com/dotnet/aspnet:9.0"
CONTAINER_IMAGE_NAME: "lancemccarthy/myblazorapp"
CONTAINER_IMAGE_REGISTRY: "registry.hub.docker.com"
CONTAINER_RID: "linux-x64"
CONTAINER_ARCH: "x64"
CONTAINER_OS: "linux"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{env.DOTNET_VERSION}}
- name: Restore NuGet Packages
run: |
# In this special case, we're using the project's nested nuget.config file (instead of the global src/nuget.config)
dotnet restore ${{env.BLAZOR_PROJ_PATH}} --configfile ${{env.NUGET_CONFIG_PATH}} -r ${{env.RID}}
dotnet restore ${{env.TEST_PROJ_PATH}} --configfile ${{env.NUGET_CONFIG_PATH}} -r ${{env.RID}}
env:
TELERIK_USERNAME: "api-key"
TELERIK_PASSWORD: ${{secrets.TELERIK_NUGET_KEY}}
- name: Build Unit Test Project
run: dotnet build ${{env.TEST_PROJ_PATH}} -c ${{env.CONFIGURATION}} -r ${{env.RID}} --no-restore
- name: Run Unit Tests
run: dotnet test ${{env.TEST_PROJ_PATH}} -r ${{env.RID}}
- name: Fetch secrets from AKeyless
id: akeyless
uses: LanceMcCarthy/akeyless-action@v3
with:
access-id: ${{secrets.AKEYLESS_JWT_ID}}
static-secrets: '{"/personal-keys/mccarthy/DOCKER_HUB_USERNAME":"DOCKER_HUB_USERNAME", "/personal-keys/mccarthy/DOCKER_HUB_PAT":"DOCKER_HUB_PAT"}'
export-secrets-to-outputs: true
export-secrets-to-environment: false
- name: Login to Docker Hub
run: docker login ${{env.CONTAINER_IMAGE_REGISTRY}} -u ${{steps.akeyless.outputs.DOCKER_HUB_USERNAME}} -p ${{steps.akeyless.outputs.DOCKER_HUB_PAT}}
# https://learn.microsoft.com/en-us/dotnet/core/docker/publish-as-container
- name: Publish Blazor Project to Docker Hub
run: dotnet publish ${{env.BLAZOR_PROJ_PATH}} -c ${{env.CONFIGURATION}} --no-build --os ${{env.CONTAINER_OS}} --arch ${{env.CONTAINER_ARCH}} -p PublishProfile=DefaultContainer -p ContainerRuntimeIdentifier=${{env.CONTAINER_RID}} -p ContainerRegistry=${{env.CONTAINER_IMAGE_REGISTRY}} -p ContainerRepository=${{env.CONTAINER_IMAGE_NAME}} -p ContainerImageTag="latest" -p ContainerBaseImage=${{env.CONTAINER_BASE_IMAGE}}