Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Build, Publish, and Release .NET App #11

Build, Publish, and Release .NET App

Build, Publish, and Release .NET App #11

Workflow file for this run

name: Build, Publish, and Release .NET App
on:
push:
tags:
- 'v*' # Trigger the action when you push a tag (e.g., v1.0.0)
jobs:
build:
runs-on: ubuntu-latest # This will be overridden by the matrix strategy
strategy:
matrix:
os: [win-x64, linux-x64, linux-arm64, osx-x64, osx-arm64] # Define OS/Arch targets
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up .NET 8.0
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0' # .NET 8.0 version
- name: Restore dependencies
run: dotnet restore
- name: Build the project
run: dotnet build --configuration Release
- name: Publish the application as a single file (self-contained)
run: |
dotnet publish -c Release -r ${{ matrix.os }} --self-contained true /p:PublishSingleFile=true -o ./publish/${{ matrix.os }}
- name: Archive published files
run: |
cd ./publish/${{ matrix.os }}
tar -czvf ../${{ matrix.os }}.tar.gz .
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: publish-${{ matrix.os }}
path: publish/${{ matrix.os }}.tar.gz # Upload the .tar.gz file for this platform
release:
needs: build
if: startsWith(github.ref, 'refs/tags/') # Ensures this job only runs when there is a tag
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Download build artifacts (Windows)
uses: actions/download-artifact@v4
with:
name: publish-win-x64 # Download the Windows artifact
- name: Download build artifacts (Linux x64)
uses: actions/download-artifact@v4
with:
name: publish-linux-x64 # Download the Linux x64 artifact
- name: Download build artifacts (Linux ARM64)
uses: actions/download-artifact@v4
with:
name: publish-linux-arm64 # Download the Linux ARM64 artifact
- name: Download build artifacts (macOS x64)
uses: actions/download-artifact@v4
with:
name: publish-osx-x64 # Download the macOS x64 artifact
- name: Download build artifacts (macOS ARM64)
uses: actions/download-artifact@v4
with:
name: publish-osx-arm64 # Download the macOS ARM64 artifact
- name: List all files
run: |
ls -la
tree
- name: Create a GitHub release
uses: softprops/action-gh-release@v1
with:
files: |
win-x64.tar.gz
linux-x64.tar.gz
linux-arm64.tar.gz
osx-x64.tar.gz
osx-arm64.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}