templating icon indicating copy to clipboard operation
templating copied to clipboard

YAML is malformed

Open dansiegel opened this issue 1 year ago • 2 comments

Product

dotnet CLI (dotnet new)

Describe The Bug

When using a template condition to control whether or not to bring a job within a GitHub Actions build, the template engine mangles the output into something unrecognizable. The issue only appears if we have a conditional block around the job and goes away when we remove it.

https://github.com/unoplatform/uno.templates/blob/6b31f9694792aa09db71bdf0b455725af4c8fab7/src/Uno.Templates/content/unoapp/GitHub/workflows/ci.yml#L37-L62

To Reproduce

Steps: Using the Uno.Templates

  1. dotnet new install Uno.Templates
  2. dotnet new unoapp -ci github -o GitHubTest1 -skip

Running this results in the .github/workflows/ci.yml generating like this:

name: CI

on:
  push:
    branches:
      - main
      - release/**

  pull_request:
    types: [opened, synchronize, reopened]
    branches:
      - main
      - release/**
env:
  STEP_TIMEOUT_MINUTES: 60

jobs:
  smoke_test:
    name: Smoke Test (Debug Build of GitHubTest1)
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Install Dependencies
        timeout-minutes: ${{ fromJSON(env.STEP_TIMEOUT_MINUTES) }}
        uses: "./.github/steps/install_dependencies"

      # Add  MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
      - name: Setup MSBuild
        uses: microsoft/[email protected]

      - name: Build GitHubTest1 (Debug)
        shell: pwsh
        run: msbuild ./GitHubTest1/GitHubTest1.csproj /r
GitHubTest1.Tests (Release)
        shell: pwsh
        run: msbuild ./GitHubTest1.Tests/GitHubTest1.Tests.csproj /p:Configuration=Release /p:OverrideTargetFrameworks=net8.0 /r

      - name: Run Unit Tests
        shell: pwsh
        run: dotnet test ./GitHubTest1.Tests/GitHubTest1.Tests.csproj --no-build -c Release --logger GitHubActions --blame-crash --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
#endif

dotnet Info

output .NET SDK: Version: 8.0.100-rc.2.23502.2 Commit: 0abacfc2b6

Runtime Environment: OS Name: Windows OS Version: 10.0.22621 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.100-rc.2.23502.2\

.NET workloads installed: [tvos] Installation Source: VS 17.7.34202.233 Manifest Version: 16.4.8968-net8-rc2/8.0.100-rc.2 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100-rc.2\microsoft.net.sdk.tvos\16.4.8968-net8-rc2\WorkloadManifest.json Install Type: Msi

[wasm-tools] Installation Source: VS 17.7.34202.233 Manifest Version: 8.0.0-rc.2.23479.6/8.0.100-rc.2 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100-rc.2\microsoft.net.workload.mono.toolchain.current\8.0.0-rc.2.23479.6\WorkloadManifest.json Install Type: Msi

[macos] Installation Source: VS 17.7.34202.233 Manifest Version: 13.3.8968-net8-rc2/8.0.100-rc.2 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100-rc.2\microsoft.net.sdk.macos\13.3.8968-net8-rc2\WorkloadManifest.json Install Type: Msi

[maui-windows] Installation Source: VS 17.7.34202.233, VS 17.8.34212.112 Manifest Version: 8.0.0-rc.2.9373/8.0.100-rc.2 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100-rc.2\microsoft.net.sdk.maui\8.0.0-rc.2.9373\WorkloadManifest.json Install Type: Msi

[maui-maccatalyst] Installation Source: VS 17.7.34202.233 Manifest Version: 8.0.0-rc.2.9373/8.0.100-rc.2 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100-rc.2\microsoft.net.sdk.maui\8.0.0-rc.2.9373\WorkloadManifest.json Install Type: Msi

[maccatalyst] Installation Source: VS 17.7.34202.233, VS 17.8.34212.112 Manifest Version: 16.4.8968-net8-rc2/8.0.100-rc.2 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100-rc.2\microsoft.net.sdk.maccatalyst\16.4.8968-net8-rc2\WorkloadManifest.json Install Type: Msi

[maui-ios] Installation Source: VS 17.7.34202.233 Manifest Version: 8.0.0-rc.2.9373/8.0.100-rc.2 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100-rc.2\microsoft.net.sdk.maui\8.0.0-rc.2.9373\WorkloadManifest.json Install Type: Msi

[ios] Installation Source: VS 17.7.34202.233, VS 17.8.34212.112 Manifest Version: 16.4.8968-net8-rc2/8.0.100-rc.2 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100-rc.2\microsoft.net.sdk.ios\16.4.8968-net8-rc2\WorkloadManifest.json Install Type: Msi

[android] Installation Source: VS 17.7.34202.233, VS 17.8.34212.112 Manifest Version: 34.0.0-rc.2.468/8.0.100-rc.2 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100-rc.2\microsoft.net.sdk.android\34.0.0-rc.2.468\WorkloadManifest.json Install Type: Msi

[maui-android] Installation Source: VS 17.7.34202.233 Manifest Version: 8.0.0-rc.2.9373/8.0.100-rc.2 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100-rc.2\microsoft.net.sdk.maui\8.0.0-rc.2.9373\WorkloadManifest.json Install Type: Msi

Host: Version: 8.0.0-rc.2.23479.6 Architecture: x64 Commit: 0b25e38ad3

.NET SDKs installed: 3.1.426 [C:\Program Files\dotnet\sdk] 6.0.319 [C:\Program Files\dotnet\sdk] 6.0.416 [C:\Program Files\dotnet\sdk] 7.0.402 [C:\Program Files\dotnet\sdk] 7.0.403 [C:\Program Files\dotnet\sdk] 8.0.100-preview.6.23330.14 [C:\Program Files\dotnet\sdk] 8.0.100-rc.2.23502.2 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.24 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.0-preview.6.23329.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.0-rc.2.23480.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.24 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.0-preview.6.23329.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.0-rc.2.23479.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.23 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.24 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.0-preview.6.23329.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.0-rc.2.23479.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables: Not set

global.json file: Not found

Learn more: https://aka.ms/dotnet/info

Download .NET: https://aka.ms/dotnet/download

Visual Studio Version

n/a

Additional context

I have additionally tried:

  • Removing the comments # Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
  • Removing the timeout-minutes: ${{ fromJSON(env.STEP_TIMEOUT_MINUTES) }}
  • Switching from 8.0.100-rc.2.23502.2 to 7.0.403
  • Adding a custom operation entry in the template.json and changing the operators for the condition in the ci.yml

None of these seemed to make a difference

dansiegel avatar Nov 13 '23 21:11 dansiegel

Additional testing has shed some interesting new information on this issue.

This actually works just fine... and when the condition in the template evaluates to true it outputs correctly.

#if (true)

  # some job here....
  unit_test:
    name: Unit Tests
    runs-on: windows-latest
    steps:

#endif

This results in the malformed output shown above.

#if (false)

  # some job here....
  unit_test:
    name: Unit Tests
    runs-on: windows-latest
    steps:

#endif

dansiegel avatar Nov 14 '23 13:11 dansiegel

We have found a workaround for this...

#if (useUnitTests)

  # some job here....
  unit_test:
    name: Unit Tests
    runs-on: windows-latest
    steps:
#else
#endif

However it would be great if this could actually be fixed so we can take the hack of the empty else out of template files.

dansiegel avatar Nov 20 '23 15:11 dansiegel