Skip to content

Commit

Permalink
Add better error message and error case handling for when git_version…
Browse files Browse the repository at this point in the history
… script fails
  • Loading branch information
atruskie committed Jun 23, 2021
1 parent 3c2fd47 commit 02d6500
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
and improve on this.
[![codecov](https://codecov.io/gh/QutEcoacoustics/audio-analysis/branch/master/graph/badge.svg)](https://codecov.io/gh/QutEcoacoustics/audio-analysis)

## Required Software

## Required Software (<span id="AP003">AP003</span>)

The **required** software for developing new code (not running the program) includes:

Expand Down
20 changes: 14 additions & 6 deletions src/AP.VersionBuild.targets
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build"
<Project DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<!-- Register our task that as something to run before standard build target -->
<Target Name="APVersionBeforeBuild" BeforeTargets="PrepareForBuild">
<!-- <Message Text="[APVersionBeforeBuild] Debug: $(RuntimeIdentifier)" Importance="High" /> -->
<Exec Command="pwsh –NonInteractive -noprofile $(ProjectDir)../git_version.ps1 -configuration $(Configuration) -self_contained $(SelfContained) -runtime_identifier &quot;$(RuntimeIdentifier)&quot; -target_framework &quot;$(TargetFramework.ToLowerInvariant())&quot;" ConsoleToMSBuild="True" EchoOff="false" StandardOutputImportance="low">
<Exec Command="pwsh –NonInteractive -NoProfile $(ProjectDir)../git_version.ps1 -configuration $(Configuration) -self_contained $(SelfContained) -runtime_identifier &quot;$(RuntimeIdentifier)&quot; -target_framework &quot;$(TargetFramework.ToLowerInvariant())&quot;"
ConsoleToMSBuild="True" EchoOff="false" StandardOutputImportance="low"
ContinueOnError="ErrorAndContinue">

<Output TaskParameter="ConsoleOutput" ItemName="VersionMetadata" />
</Exec>
<!-- <Message Text="[APVersionBeforeBuild] %(VersionMetadata.Identity)" Importance="High" /> -->
<!-- <Message Text="[APVersionBeforeBuild::Debug] %(VersionMetadata.Identity)" Importance="High" /> -->

<!-- batch through returned metadata, then use ✨MAGIC✨ to convert subexpression to string, then split on key/value -->
<!-- and finally create each property -->
<CreateProperty Value="$([System.String]::Copy(`%(VersionMetadata.Identity)`).Split('=')[1].Trim())">
<CreateProperty
Condition="$([System.String]::Copy(`%(VersionMetadata.Identity)`).Contains('='))"
Value="$([System.String]::Copy(`%(VersionMetadata.Identity)`).Split('=')[1].Trim())">
<Output TaskParameter="Value" PropertyName="$([System.String]::Copy(`%(VersionMetadata.Identity)`).Split('=')[0].Trim())" />
</CreateProperty>



<Message Text="[APVersionBeforeBuild] Generated metadata file: $(GeneratedMetadata)" Importance="High" />
<Message Text="[APVersionBeforeBuild] Last Tag: $(LastTag), Hash: $(CommitHashShort), CommitCount: $(CommitsSinceLastTag)" Importance="High" />
<Message Text="[APVersionBeforeBuild] Using assembly version with: $(Version)!" Importance="High" />
<Message Text="[APVersionBeforeBuild] InformationalVersion: $(InformationalVersion)" Importance="High" />
<Message Text="[APVersionBeforeBuild] BuildDate: $(BuildDate)" Importance="High" />
<Message Text="[APVersionBeforeBuild] SelfContained: $(MsBuildSelfContained), Build RuntimeIdentifier:$(MsBuildRuntimeIdentifer)" Importance="High" />
<Message Text="[APVersionBeforeBuild] git_version.ps1 stdout: %(VersionMetadata.Identity)" Importance="High" Condition="$(GeneratedMetadata) == ''"/>
<Error Text="AP Version script failed to set MsBuildRuntimeIdentifer. This value is needed for correct function in compiled code" Condition="$(MsBuildRuntimeIdentifer) == '' And $(SelfContained)" />
<Error Text="AP Version metadata generation failed. Check you have PowerShell 6+ &amp; Git installed and available on the system PATH." Condition="$(GeneratedMetadata) == ''"/>
<Error Text="$(MSBuildThisFile):APVersion error AP004: AP Version script failed to set MsBuildRuntimeIdentifer. This value is needed for correct function in compiled code" Condition="$(MsBuildRuntimeIdentifer) == '' And $(SelfContained)" />
<Error Code="AP003" Text="AP Version metadata generation failed. Check you have PowerShell 6+ &amp; Git installed and available on the system PATH. https://github.com/QutEcoacoustics/audio-analysis/blob/master/CONTRIBUTING.md#AP003" Condition="$(GeneratedMetadata) == ''"/>
</Target>
</Project>
8 changes: 4 additions & 4 deletions src/lfs_check.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if ($null -eq (Get-Command "git-lfs" -ErrorAction SilentlyContinue )) {
Push-Location
Set-Location $solution_root
$errored = $false
foreach($line in (git-lfs ls-files)) {
foreach ($line in (git-lfs ls-files)) {
# format:
# 1da5b69f92 * tests/Fixtures/whip bird2.wav
$status = $line[11]
Expand All @@ -29,16 +29,16 @@ foreach($line in (git-lfs ls-files)) {
$status = git status --porcelain $file
$has_changed = ($null -ne $status)
if (-not $has_changed) {
Write-Output "$file`:git-lfs error AP0001: Git LFS BLOB has not been restored. The file is empty! It contains only a LFS pointer."
Write-Output "$file`:git-lfs error AP001: Git LFS BLOB has not been restored. The file is empty! It contains only a LFS pointer."
$errored = $true
}
}
}

if ($errored -eq $true) {
Write-Output "$solution_root${slash}src${slash}AP.RequireLfsAssets.targets`:git-lfs error AP0002: AP build cannot continue there are Git LFS assets that have not been restored. Please follow the instructions at https://github.com/QutEcoacoustics/audio-analysis/blob/master/CONTRIBUTING.md#AP001"
Write-Output "$solution_root${slash}src${slash}AP.RequireLfsAssets.targets`:git-lfs error AP002: AP build cannot continue there are Git LFS assets that have not been restored. Please follow the instructions at https://github.com/QutEcoacoustics/audio-analysis/blob/master/CONTRIBUTING.md#AP001"
}
else {
else {
$null >> $cache_file
}

Expand Down

0 comments on commit 02d6500

Please sign in to comment.