11/28/2019 Admin

Deploying Your Blazor App Using GitHub Actions


image

You can easily deploy updates to your Blazor application to Azure using GitHub Actions.

 

Deploy Your Blazor Application To Azure

image

In the following example, we will assume you have already deployed your Blazor application to Azure.


 

Get The Azure Publishing Profile

image

The first step is to follow the directions here to download the Azure Publishing Profile for the Azure App Service, and use it to set the secret in GitHub.

Log into https://portal.azure.com/ and select the App Service you want to deploy to.

 

image

Select Get publish profile.

 

image

Download the file and open it in a text editor.

 

image

Log into the GitHub site you want to deploy from and select Settings.

 

image

Select Secrets, then Add a new secret.

 

image

 

  1. Name the secret: azureWebAppPublishProfile
  2. Paste in the contents of the Azure publishing profile in the Value box.
  3. Click Add secret.

 

image

The secret will be created.

 

Create GitHub Action

image

Select Actions, then New workflow.

 

 image

Select, Set up a workflow yourself.

 

image

We start with the script we grab from this link.

We alter it so this is the final script:

 

name: Deploy To Azure
on:
  push:
    branches:
      - master
jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
    # checkout the repo
    - uses: actions/checkout@master
    
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 3.0.100 # Replace with specific dotnet core version
    
    # dotnet build and publish
    - name: Build with dotnet
      run: dotnet build --configuration Release
    - name: dotnet publish
      run: |
        dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp 
    - name: 'Run Azure webapp deploy action using publish profile credentials'
      uses: azure/webapps-deploy@v1
      with: 
        app-name: mydotnetcoreapp # Replace with your app name
        publish-profile: ${{ secrets.azureWebAppPublishProfile }} 
        package: ${{env.DOTNET_ROOT}}/myapp 

 

Commit the file.

(Note: You literally can keep the name as mydotnetcoreapp and it will still work)

 

image

The file will show up in the /.github/workflows directory.

 

image

Note: The file is set to: on: [push]

 

image

We can always edit the file, by selecting it, and then selecting the edit button.

 

image

We could change it to only run when we push to the master branch.

We can see all the options at this link:

https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows

Now, every time we check in code to the master branch, it will be deployed to Azure.

 

Links

What happens to my app during deployment?

Investigating continuous deployment

GitHub Actions

How to get started with GitHub Actions for Azure (Video)

Awesome-Actions

GitHub Actions 2.0 IS HERE

Learn YAML in five minutes!

Workflow syntax for GitHub Actions


An error has occurred. This application may no longer respond until reloaded. Reload 🗙