GitHub Actions Workflow
I will break down the YAML file I created for the GitHub actions workflow into the relevant parts to explain what is going on.
You can find the full YAML file as a GitHub Gist here.
At the beginning of the file we tell GitHub to monitor the main branch for commits, whenever there is a push to this branch it will trigger a run of the build workflow.
Next we set some environment variables to be used later by the dotnet build command.
on:
push:
branches: [ main ]
env:
SolutionName: ${{ secrets.SOLUTION_NAME }}
BuildPlatform: Any CPU
BuildConfiguration: Release
The final configuration step before we add the build steps is to set the build agent type to be used, as we needed to use Web Deploy, we must set the build agent to be Windows based.
runs-on: windows-latest
The first build step is to tell the agent to clone down the repository
- name: Checkout
uses: actions/checkout@v3
To speed up future builds, we want to make use of the caching feature, we are using the previously configured RestorePackagesWithLockFile for the caching, this will mean that for the next build, just as long as there are no NuGet package changes, the build agent won't need to query NuGet for each of the packages, download them and extract, instead it will download a single compressed file and extract that.
- uses: actions/cache@v3
id: cache-nuget-umbhost
with:
path: |
~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-umbhost
Next we create a folder to contain the generated zip file from msbuild
- name: Create Build Directory
run: mkdir _build
Now we need to build the package, in the command below we are passing in the SolutionName, BuildConfiguration and BuildPlatform environment variables set earlier.
You can read about the parameters used below with msbuild on the Microsoft Learn website.
- name: Build Solution
run: |
dotnet build ${{env.SolutionName}} /nologo /nr:false /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:DeleteExistingFiles=True /p:SkipInvalidConfigurations=true /p:IncludeSetAclProviderOnDestination=False /p:AutoParameterizationWebConfigConnectionStrings=False /p:platform="${{env.BuildPlatform}}" /p:configuration="${{env.BuildConfiguration}}" /p:PackageLocation="../_build"
Finally once the build has finished we need to deploy this out to the server, below we are passing in the repository secrets we set earlier, as well as the source-path to the package and the package name, the package name is the same name as the Web .csproj filename.
- name: Deploy to UmbHost
uses: UmbHost/umbhost-web-deploy@v1.0.1
with:
website-name: ${{ secrets.WEBSITE_NAME }}
server-computer-name: ${{ secrets.SERVER_COMPUTER_NAME }}
server-username: ${{ secrets.USERNAME }}
server-password: ${{ secrets.PASSWORD }}
source-path: '_build'
source-fileName: Umbootstrap.Web.zip