forked from MicrosoftLearning/eShopOnWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
27 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,93 @@ | ||
name: eShopOnWeb Build and Deploy | ||
name: eShopOnWeb Build and Test | ||
|
||
on: | ||
workflow_dispatch: | ||
#Triggers (uncomment line below to use it) | ||
#on: [push, workflow_dispatch] | ||
|
||
#Environment variables https://docs.github.com/en/actions/learn-github-actions/environment-variables | ||
env: | ||
RESOURCE_GROUP_NAME: rg-az400-eshoponweb-westeurope | ||
RESOURCE-GROUP: rg-az400-eshoponweb-NAME | ||
LOCATION: westeurope | ||
TEMPLATE-FILE: .azure/bicep/webapp.bicep | ||
SUBSCRIPTION-ID: 4930a01d-2f40-471e-a925-1d63f6482128 | ||
SUBSCRIPTION-ID: YOUR-SUBS-ID | ||
WEBAPP-NAME: az400-webapp-NAME | ||
|
||
|
||
jobs: | ||
#Build, test and publish .net web project in repository | ||
buildandtest: | ||
runs-on: ubuntu-latest | ||
steps: | ||
#checkout the repository | ||
- uses: actions/checkout@v2 | ||
|
||
#prepare runner for desired .net version SDK | ||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: '7.0.x' | ||
include-prerelease: true | ||
|
||
#Build/Test/Publish the .net project | ||
- name: Build with dotnet | ||
run: dotnet build ./eShopOnWeb.sln --configuration Release | ||
|
||
- name: Test with dotnet | ||
run: dotnet test ./eShopOnWeb.sln --configuration Release | ||
- name: dotnet publish | ||
run: dotnet publish ./src/Web/Web.csproj -c Release -o ${{env.DOTNET_ROOT}}/myapp | ||
|
||
# upload the published website code artifacts | ||
- name: Upload artifact for deployment job | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: .net-app | ||
path: ${{env.DOTNET_ROOT}}/myapp | ||
|
||
# upload the bicep template as artifacts for next job | ||
- name: Upload artifact for deployment job | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: bicep-template | ||
path: ${{ env.TEMPLATE-FILE }} | ||
|
||
|
||
# Use Bicep to deploy infrastructure + Publish webapp | ||
deploy: | ||
runs-on: ubuntu-latest | ||
needs: buildandtest | ||
environment: | ||
name: 'Development' | ||
steps: | ||
- name: Generate unique name | ||
id: generate_name | ||
run: | | ||
CONVERTED_NAME=$(echo "$RESOURCE_GROUP_NAME" | tr -dc '[:alnum:]' | tr '[:upper:]' '[:lower:]') | ||
HASH=$(echo -n "$CONVERTED_NAME" | md5sum | cut -c1-5) | ||
RANDOMIZED_NAME="az400webapp${HASH}" | ||
echo "Generated web app name: $RANDOMIZED_NAME" | ||
echo "WEBAPP_NAME=$RANDOMIZED_NAME" >> $GITHUB_ENV | ||
echo ${{ env.WEBAPP_NAME }} | ||
|
||
#Download the publish files created in previous job | ||
- name: Download artifact from build job | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: .net-app | ||
path: .net-app | ||
|
||
#Download the bicep templates from previous job | ||
- name: Download artifact from build job | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: bicep-template | ||
path: bicep-template | ||
|
||
#Login in your azure subscription using a service principal (credentials stored as GitHub Secret in repo) | ||
- name: Azure Login | ||
uses: azure/login@v1 | ||
with: | ||
creds: ${{ secrets.AZURE_CREDENTIALS }} | ||
|
||
# Deploy Azure WebApp using Bicep file | ||
- name: deploy | ||
uses: azure/arm-deploy@v1 | ||
with: | ||
subscriptionId: ${{ env.SUBSCRIPTION-ID }} | ||
resourceGroupName: ${{ env.RESOURCE_GROUP_NAME }} | ||
resourceGroupName: ${{ env.RESOURCE-GROUP }} | ||
template: bicep-template/webapp.bicep | ||
parameters: webAppName=${{ env.WEBAPP_NAME }} | ||
parameters: 'webAppName=${{ env.WEBAPP-NAME }} location=${{ env.LOCATION }}' | ||
failOnStdErr: false | ||
|
||
# Publish website to Azure App Service (WebApp) | ||
- name: Publish Website to WebApp | ||
uses: Azure/webapps-deploy@v2 | ||
with: | ||
app-name: $WEBAPP_NAME | ||
app-name: ${{ env.WEBAPP-NAME }} | ||
package: .net-app | ||
|