Skip to content

Commit f2b903f

Browse files
authored
Create dotnet.yml
1 parent 2825faa commit f2b903f

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed

.github/workflows/dotnet.yml

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# This workflow will build a .NET project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
3+
4+
name: .NET
5+
6+
env:
7+
registryName: {your_registry_name}.azurecr.io
8+
repositoryName: techexcel/dotnetcoreapp
9+
dockerFolderPath: ./src/Application/src/RazorPagesTestSample
10+
tag: ${{github.run_number}}
11+
12+
on:
13+
push:
14+
branches: [ "main" ]
15+
paths: src/Application/**
16+
pull_request:
17+
branches: [ "main" ]
18+
paths: src/Application/**
19+
20+
jobs:
21+
build:
22+
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- uses: actions/checkout@v4
27+
- name: Setup .NET
28+
uses: actions/setup-dotnet@v4
29+
with:
30+
dotnet-version: 8.0.x
31+
- name: Restore dependencies
32+
run: dotnet restore ./src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj
33+
- name: Build
34+
run: dotnet build --no-restore ./src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj
35+
- name: Test
36+
run: dotnet test --no-build --verbosity normal ./src/Application/tests/RazorPagesTestSample
37+
- uses: actions/github-script@v6
38+
if: failure()
39+
with:
40+
github-token: ${{secrets.GITHUB_TOKEN}}
41+
script: |
42+
let body = "${{ env.build_name }} Workflow Failure \n Build Number: ${{ github.run_number }} \n Build Log: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} \n SHA: [${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) \n";
43+
github.issues.create({
44+
owner: context.repo.owner,
45+
repo: context.repo.repo,
46+
title: "${{ env.build_name }} Workflow ${{ github.run_number }} Failed! ",
47+
body: body
48+
});
49+
50+
dockerBuildPush:
51+
runs-on: ubuntu-latest
52+
needs: build
53+
54+
steps:
55+
- uses: actions/checkout@v3
56+
57+
- name: Docker Login
58+
# You may pin to the exact commit or the version.
59+
# uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
60+
uses: docker/[email protected]
61+
with:
62+
# Server address of Docker registry. If not set then will default to Docker Hub
63+
registry: ${{ secrets.ACR_LOGIN_SERVER }}
64+
# Username used to log against the Docker registry
65+
username: ${{ secrets.ACR_USERNAME }}
66+
# Password or personal access token used to log against the Docker registry
67+
password: ${{ secrets.ACR_PASSWORD }}
68+
# Log out from the Docker registry at the end of a job
69+
logout: true
70+
71+
- name: Docker Build
72+
run: docker build -t $registryName/$repositoryName:$tag --build-arg build_version=$tag $dockerFolderPath
73+
74+
- name: Docker Push
75+
run: docker push $registryName/$repositoryName:$tag
76+
77+
deploy-to-dev:
78+
79+
runs-on: ubuntu-latest
80+
needs: dockerBuildPush
81+
environment:
82+
name: dev
83+
url: https://{your_prefix}-dev.azurewebsites.net/
84+
85+
steps:
86+
- name: 'Login via Azure CLI'
87+
uses: azure/[email protected]
88+
with:
89+
creds: ${{ secrets.AZURE_CREDENTIALS }}
90+
91+
- uses: azure/webapps-deploy@v2
92+
with:
93+
app-name: '{your_prefix}-dev'
94+
images: {your_registry_name}.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}}
95+
96+
deploy-to-test:
97+
98+
runs-on: ubuntu-latest
99+
needs: deploy-to-dev
100+
environment:
101+
name: test
102+
url: https://{your_prefix}-test.azurewebsites.net/
103+
104+
steps:
105+
- uses: actions/checkout@v3
106+
107+
- name: 'Login via Azure CLI'
108+
uses: azure/[email protected]
109+
with:
110+
creds: ${{ secrets.AZURE_CREDENTIALS }}
111+
112+
- uses: azure/webapps-deploy@v2
113+
with:
114+
app-name: '{your_prefix}-test'
115+
images: {your_registry_name}.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}}
116+
117+
deploy-to-prod:
118+
119+
runs-on: ubuntu-latest
120+
needs: deploy-to-test
121+
environment:
122+
name: prod
123+
url: https://{your_prefix}-prod.azurewebsites.net/
124+
125+
steps:
126+
- uses: actions/checkout@v3
127+
128+
- name: 'Login via Azure CLI'
129+
uses: azure/[email protected]
130+
with:
131+
creds: ${{ secrets.AZURE_CREDENTIALS }}
132+
133+
- uses: azure/webapps-deploy@v2
134+
with:
135+
app-name: '{your_prefix}-prod'
136+
images: {your_registry_name}.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}}

0 commit comments

Comments
 (0)