Skip to content

Add GitHub actions

Add GitHub actions #1

Workflow file for this run

name: Build .NET application
on:
push:
branches:
- main
tags:
- "v[0-9]+.[0-9]+.[0-9].*"
pull_request:
branches:
- main
workflow_dispatch:
jobs:
build:
strategy:
matrix:
configuration:
- Debug
- Release
runs-on: ubuntu-latest
outputs:
artifact_name: ${{ steps.artifact_name.outputs.ArtifactName }}
configuration: ${{ matrix.configuration }}
env:
ProjectPath: "src/XInputBatteryMeter"
CsprojFilename: "XInputBatteryMeter.csproj"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Mise and dependencies
uses: jdx/mise-action@v2
with:
cache: true
- name: Activate Mise
run: eval "$(mise activate bash)"
- name: Restore NuGet dependencies
run: dotnet restore $CsprojPath
env:
CsprojPath: "${{ env.ProjectPath }}/${{ env.CsprojFilename }}"
- name: Build
run: dotnet build $CsprojPath --configuration $Configuration --no-restore
env:
CsprojPath: "${{ env.ProjectPath }}/${{ env.CsprojFilename }}"
Configuration: ${{ matrix.configuration }}
- name: Build artifact name
id: artifact_name
run: |
TARGET_FRAMEWORK=$(ls $ProjectPath/bin/$Configuration | tail -n 1)
ARTIFACT_NAME="$Configuration-$TARGET_FRAMEWORK"
echo "TargetFramework=$TARGET_FRAMEWORK" >> $GITHUB_OUTPUT
echo "ArtifactName=$ARTIFACT_NAME" >> $GITHUB_OUTPUT
env:
ProjectPath: ${{ env.ProjectPath }}
Configuration: ${{ matrix.configuration }}
- name: Push build output to artifacts
uses: actions/upload-artifact@v4
env:
ProjectPath: ${{ env.ProjectPath }}
Configuration: ${{ matrix.configuration }}
TargetFramework: ${{ steps.artifact_name.outputs.TargetFramework }}
ArtifactName: ${{ steps.artifact_name.outputs.ArtifactName }}
with:
name: ${{ env.ArtifactName }}
path: "${{ env.ProjectPath }}/bin/${{ env.Configuration }}/${{ env.TargetFramework }}"
release:
runs-on: ubuntu-latest
needs:
- build
permissions:
contents: write
if: needs.build.outputs.configuration == 'Release' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
env:
ARTIFACT_NAME: ${{ needs.build.outputs.artifact_name }}
steps:
- name: Download artifacts from build job
uses: actions/download-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
- name: Create GitHub Release on Repo
uses: softprops/action-gh-release@v2
with:
files: ${{ env.ARTIFACT_NAME }}
generate_release_notes: true