Updated build.yml #103
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build | |
env: | |
PACKAGES: ${{ github.workspace }}\.nuget\packages | |
VERSION: 0.0.1-alpha | |
# these are all set in the set-vars step | |
ARTIFACT_NAME: '' | |
BUILD_DATE: '' | |
BUILD_DATE_LONG: '' | |
BUILD_TYPE: '' | |
on: | |
workflow_call: | |
inputs: | |
is_release: | |
description: 'True if this build is for a release, false otherwise' | |
default: false | |
type: boolean | |
version: | |
description: 'The semantic version number (e.g. "2.0.1-beta")' | |
default: '0.0.1' | |
required: false | |
type: string | |
workflow_dispatch: | |
push: | |
branches: [ "main", "master" ] | |
tags-ignore: | |
- v* | |
paths-ignore: | |
- 'resources/*' | |
- 'README.md' | |
- 'CHANGELOG.md' | |
- '.gitignore' | |
- '.gitattributes' | |
pull_request: | |
branches: [ "main", "master" ] | |
concurrency: | |
group: ${{ github.workflow }} | |
jobs: | |
build: | |
runs-on: windows-latest | |
steps: | |
- name: Checkout | |
id: git-checkout | |
uses: actions/checkout@v4 | |
- name: Setup .NET | |
id: setup-dotnet | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: 8.0.x | |
- name: Cache Restore | |
id: cache-restore | |
uses: actions/cache/restore@v4 | |
with: | |
path: ${{ env.PACKAGES }} | |
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} | |
- name: Restore dependencies | |
id: dotnet-restore | |
run: dotnet restore .\src\SAM_NoTests.slnf --packages ${{ env.PACKAGES }} | |
- name: Cache Save | |
id: cache-save | |
uses: actions/cache/save@v4 | |
if: steps.cache-restore.outputs.cache-hit != 'true' | |
with: | |
path: ${{ env.PACKAGES }} | |
key: ${{ steps.cache-restore.outputs.cache-primary-key }} | |
- name: Set Vars | |
id: set-vars | |
run: | | |
$now = Get-Date | |
$longTs = $now.ToString('yyyy-MM-dd') | |
$ts = $now.ToString('yyMMdd') | |
$buildType = "${{ inputs.is_release && 'release' || 'debug' }}" | |
$artifactName = $releaseType -eq 'release' ? "SAM_${{ inputs.version }}" : "SAM_$ts_${{ github.run_number }}_$buildType" | |
Write-Host "Build Date : " -NoNewLine | |
Write-Host "$($PSStyle.Foreground.BrightCyan)$longTs ($ts)$($PSStyle.Reset)" | |
Write-Host "Build Type : " -NoNewLine | |
Write-Host "$($PSStyle.Foreground.BrightCyan)$buildType$($PSStyle.Reset)" | |
Write-Host "Artifact Name : " -NoNewLine | |
Write-Host "$($PSStyle.Foreground.BrightCyan)$artifactName$($PSStyle.Reset)" | |
echo "BUILD_DATE=$ts" >> $env:GITHUB_ENV | |
echo "BUILD_DATE_LONG=$longTs" >> $env:GITHUB_ENV | |
echo "BUILD_TYPE=$buildType" >> $env:GITHUB_ENV | |
echo "ARTIFACT_NAME=$artifactName" >> $env:GITHUB_ENV | |
- name: Publish SAM | |
id: dotnet-publish | |
run: dotnet publish .\src\SAM\SAM.csproj -o publish -c Release -a x86 --no-restore /p:Version=${{ inputs.version || env.VERSION }} | |
- name: Stage Artifacts | |
id: stage-artifacts | |
run: | | |
$samDir = Get-Item publish | Select-Object -ExpandProperty FullName | |
$stagedFiles = gci $samDir -Recurse -File | select -ExpandProperty FullName | Sort-Object | |
Write-Host "" | |
Write-Host "::group::Staged Artifacts" | |
foreach ($stagedFile in $stagedFiles) | |
{ | |
$relPath = [System.IO.Path]::GetRelativePath($samDir, $stagedFile) | |
$ext = [System.IO.Path]::GetExtension($stagedFile) | |
$color = '' | |
if ($ext -eq '.exe') { | |
$color = $PSStyle.Foreground.BrightCyan | |
} | |
elseif ($ext -eq '.dll') { | |
$color = $PSStyle.Foreground.BrightMagenta | |
} | |
elseif ($ext -eq '.pdb') { | |
$color = $PSStyle.Foreground.BrightGreen | |
} | |
elseif ($ext -eq '.json' -or $ext -eq '.config') { | |
$color = $PSStyle.Foreground.BrightBlue | |
} | |
else { | |
$color = $PSStyle.Foreground.BrightWhite | |
} | |
Write-Host "- $color$relPath$($PSStyle.Reset)" | |
} | |
Write-Host "::endgroup::" | |
- name: Upload a Build Artifact | |
id: artifact-upload | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.ARTIFACT_NAME }} | |
path: publish | |
if-no-files-found: error |