GitHub .NET Build Action Example

Build Action

On a push or merge to main:

  1. Set up .NET
  2. Build (publish in this case) the project
  3. Compress the artifacts to a ZIP
  4. Download the archive
  5. Create a release for the build using that archive

This example is for Ups & Downs:

name: Build and Release WPF App
 
on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main
 
permissions:
  contents: write  # Grants the necessary permission to create a release
 
jobs:
  build:
    runs-on: windows-latest
 
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
 
      - name: Setup .NET 9.0
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: '9.0.x'
 
      - name: Publish artifacts
        run: dotnet publish -c Release -o ./publish
        working-directory: Ups & Downs
 
      - name: Compress build artifacts into a single zip
        run: Compress-Archive -Path "Ups & Downs/publish/*" -DestinationPath "Ups-Downs-Build.zip"
 
      - name: Upload build artifacts
        uses: actions/upload-artifact@v4
        with:
          name: WPF-Build
          path: Ups-Downs-Build.zip
 
  release:
    needs: build
    runs-on: windows-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
 
      - name: Download build artifacts
        uses: actions/download-artifact@v4
        with:
          name: WPF-Build
          path: ./release-artifacts
 
      - name: Create GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: v1.0.${{ github.run_number }}
          name: Release v1.0.${{ github.run_number }}
          draft: false
          prerelease: false
          files: ./release-artifacts/Ups-Downs-Build.zip
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

github yaml automation