This repo contains a sample WPF application to demonstrate how to create CI/CD pipelines using GitHub Actions.
This repo contains a sample WPF application to demonstrate how to create CI/CD pipelines using GitHub Actions.
This repo contains a sample application to demonstrate how to create CI/CD pipelines using GitHub Actions.
With GitHub Actions, you can quickly and easily automate your software workflows with CI/CD.
Build, test, and deploy your code entirely within GitHub.
| Workflow | Status |
|---|---|
| WPF - CI | |
| WPF - CD | |
| WPF - CI (.NET 6 experimental) |
To take advantage of GitHub Actions, workflows are defined in YAML files that are in the .github/workflows folder. In the project, there are two workflows defined:
The ci.yml file defines the continuous integration workflow which is used to build, test, and create a package every time a developer pushes code to the repo.
The benefits of kicking off a CI run on every push are multi-fold:
The cd.yml file defines our continuous delivery workflow used to build, sign, package and archive release assets for every configuration that is planned for release.
The CI workflow defines the Package.Identity.Name in the Windows Application Packaging project’s Package.appxmanifest to identify the application as "MyWPFApp.DevOpsDemo.Local." By suffixing the application name with ".Local," developers are able to install it side by side with other channels of the app.
On every push to the repo, take advantage of the setup-dotnet GitHub Action and install the dotnet core cli environment. Then add MSBuild to the PATH and execute unit tests using the dotnet test runner console application.
- name: Install .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.100
# Add MsBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/[email protected]
# Test
- name: Execute Unit Tests
run: dotnet test $env:Test_Project_PathAs mentioned above, you can target multiple platforms by authoring the workflow file to define a build matrix, a set of different configurations that are each run in a fresh instance of a virtual environment by the GitHub-hosted runner.
In the continuous integration workflow, create a release build for x86 and x64 that runs on the latest windows OS installed on the GitHub-hosted runners. Then, define environment variables that are common to all the runs in the matrix such as the signing certificate name, the relative path to the solution file and the Windows Application Packaging project name.
strategy:
matrix:
targetplatform: [x86, x64]
runs-on: windows-latest
env:
SigningCertificate: GitHubActionsDemo.pfx
Solution_Path: MyWpfApp.sln
Test_Project_Path: MyWpfApp.Tests\MyWpfApp.Tests.csproj
Wpf_Project_Path: MyWpfApp\MyWpfApp.csproj
Wap_Project_Directory: MyWpfApp.Package
Wap_Project_Name: MyWpfApp.Package.wapprojNext, execute the unit tests in MYWPFApp.Tests by calling ‘donet test’.
# Test
- name: Execute Unit Tests
run: dotnet test $env:Test_Project_PathAfter executing the tests, restore the application while passing in the RuntimeIdentifier parameter in order to populate the obj folder with the appropriate platform dependencies for use during build.
# Restore the application
- name: Restore the Wpf application to populate the obj folder
run: msbuild $env:Solution_Path /t:Restore /p:Configuration=$env:Configuration /p:RuntimeIdentifier=$env:RuntimeIdentifier
env:
Configuration: Debug
RuntimeIdentifier: win-${{ matrix.targetplatform }}Once the application has been restored, build and create the MSIX. Rather than build each project separately, simply build the solution, making sure to pass the target platform, configuration, build mode, whether to produce an app bundle, the signing certificate, and certificate password as parameters.
# Build the Windows Application Packaging project
- name: Build the Windows Application Packaging Project (wapproj)
run: msbuild $env:Solution_Path /p:Platform=$env:TargetPlatform /p:Configuration=$env:Configuration /p:UapAppxPackageBuildMode=$env:BuildMode /p:AppxBundle=$env:AppxBundle /p:PackageCertificateKeyFile=$env:SigningCertificate /p:PackageCertificatePassword=${{ secrets.Pfx_Key }}
env:
AppxBundle: Never
BuildMode: SideLoadOnly
Configuration: Release
TargetPlatform: ${{ matrix.targetplatform }}Once the app package has been created, take advantage of the upload-artifact GitHub Action to save the artifact. You have the option to download the artifact to test the build or upload the artifact to a website or file share to distribute the application.
# Upload the MSIX package: https://github.com/marketplace/actions/upload-artifact
- name: Upload build artifacts
uses: actions/upload-artifact@v1
with:
name: MSIX Package
path: MyWpfApp.Package\AppPackages\To find the artifact, navigate to "Actions," select the workflow, then download the artifact on the right side of the window.
In the CD workflow, you can build, package and distribute code built for multiple channels such as “Dev”, “Prod_Sideload” and “Prod_Store.” During every workflow run, the applications’ Package.Identity.Name, Package.Identity.Version and Package.Properties.DisplayName are changed according to which channel of the build matrix will be built. We use a Powershell script to overwrite these values in the Windows Application Packaging project's Package.appxmanifest. By doing so, we change the identity of the application to MyWPFApp.DevOpsDemo.Dev, MyWPFApp.DevOpsDemo.ProdSideload, or MyWPFApp.DevOpsDemo.ProdStore depending on which matrix channel is built, thus enabling multiple channels of the application.
…On every push to the repo with a tag matching the pattern *, the workflow will build the solution, create a release and upload the release asset. For more information on how to configure a workflow to run on specific branches or tags, see GitHub Workflow syntax for GitHub Actions - on...
on:
push:
tags:
- '*'To create a git tag, run the following commands on the branch you wish to release:
git tag 1.0.0.0
git push origin --tagsThe above commands will add the tag "1.0.0.0" and then push the branch and tag to the repo. Learn more about Git Tagging.
Channels and environment variables used during the run are defined in the build matrix and will build and create app packages for development (Dev), production sideload (Prod_Sideload), and also production for the Microsoft Store (Prod_Store). In this example, each channel is built for two configurations: x86 and x64. However, arm or arm64 are valid configurations as well.
A build matrix can be created to execute jobs across multiple operating systems, build configurations or different supported versions of a programming language. With GitHub Actions, you can define incredibly complex build matrices that can generate up to 256 builds per run! Learn how to configure a build matrix.
…Just like the CI workflow, restore the solution.
# Restore the application
- name: Restore the Wpf application to populate the obj folder
run: msbuild $env:Solution_Path /t:Restore /p:Configuration=$env:Configuration /p:RuntimeIdentifier=$env:RuntimeIdentifier
env:
Configuration: Debug
RuntimeIdentifier: win-${{ matrix.targetplatform }}This time, however, use GitHub’s if conditional to build and package the MSIX for Dev and Prod_Sideload (which requires an AppInstaller Uri and Signing Certificate) or for Prod_Store.
We pass different parameters depending on which channel we are building for.
…Once the MSIX is created for each channel, the agent archives the AppPackages folder then creates a Release with the specified git release tag. The archive is uploaded to the release as an asset for storage or distribution. It’s important to note that release names must be unique or an error will be generated. This is why tag_name and release_name include the github reference, channel name and target platform.
…To find the Release artifacts, navigate to the "Releases" link in the repo.
Find the release and asset location.
Creating channels for the application is a powerful way to create multiple distributions of an application in the same CD pipeline.
In both workflows, one of the first things to do is create a version and store version information as environment variables. Having a different version for every push is especially important when a release is created as each release must have a unique release_name.
The Nerdbank.GitVersioning GitHub Action sets the build version based on a combination of the included version.json file, and the git height of the version.
# Use Nerdbank.GitVersioning to set version variables: https://github.com/AArnott/nbgv
- name: Use Nerdbank.GitVersioning to set version variables
uses: aarnott/[email protected]
with:
setAllVars: trueOnce the action runs, a number of environment variables are available for use, such as:
A list of all the environment variables available to use in the run are shown below.
See the Nerdbank.GitVersioning package for more inform
No open issues yet, or sync has not completed.