Skip to content

Update create_release.yml #111

Update create_release.yml

Update create_release.yml #111

Workflow file for this run

name: Build
env:
PACKAGES: ${{ github.workspace }}\.nuget\packages
VERSION: 0.0.1
# 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
outputs:
artifact-name:
description: 'The name of the build artifact'
value: ${{ jobs.build.outputs.artifact-name }}
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
outputs:
artifact-name: ${{ steps.set-vars.outputs.artifact-name }}
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('yy.MM.dd')
$buildType = "${{ inputs.is_release && 'release' || 'debug' }}"
$artifactName = $releaseType -eq 'release' ? "SAM_${{ inputs.version }}" : [string]::Format('SAM_{0}_{1}.{2}', $buildType, $ts, '${{ github.run_number }}')
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
echo "artifact-name=$artifactName" >> $env:GITHUB_OUTPUT
- 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@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: publish
if-no-files-found: error