From eec48567811ec798ba2e5a05553ad2b9b90fd2b9 Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Sun, 19 Jan 2020 22:36:47 +0100 Subject: [PATCH 01/23] Update bootstrapper --- build.ps1 | 121 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 85 insertions(+), 36 deletions(-) diff --git a/build.ps1 b/build.ps1 index a6d30c4..9a6ade2 100644 --- a/build.ps1 +++ b/build.ps1 @@ -5,11 +5,14 @@ ########################################################################## <# + .SYNOPSIS This is a Powershell script to bootstrap a Cake build. + .DESCRIPTION This Powershell script will download NuGet if missing, restore NuGet tools (including Cake) and execute your Cake build script with the parameters you provide. + .PARAMETER Script The build script to execute. .PARAMETER Target @@ -18,19 +21,22 @@ The build script target to run. The build configuration to use. .PARAMETER Verbosity Specifies the amount of information to be displayed. +.PARAMETER ShowDescription +Shows description about tasks. +.PARAMETER DryRun +Performs a dry run. .PARAMETER Experimental -Tells Cake to use the latest Roslyn release. -.PARAMETER WhatIf -Performs a dry run of the build script. -No tasks will be executed. +Uses the nightly builds of the Roslyn script engine. .PARAMETER Mono -Tells Cake to use the Mono scripting engine. +Uses the Mono compiler rather than the Roslyn script engine. .PARAMETER SkipToolPackageRestore Skips restoring of packages. .PARAMETER ScriptArgs Remaining arguments are added here. + .LINK -http://cakebuild.net +https://cakebuild.net + #> [CmdletBinding()] @@ -41,9 +47,10 @@ Param( [string]$Configuration = "Release", [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] [string]$Verbosity = "Verbose", + [switch]$ShowDescription, + [Alias("WhatIf", "Noop")] + [switch]$DryRun, [switch]$Experimental, - [Alias("DryRun","Noop")] - [switch]$WhatIf, [switch]$Mono, [switch]$SkipToolPackageRestore, [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] @@ -75,6 +82,15 @@ function MD5HashFile([string] $filePath) } } +function GetProxyEnabledWebClient +{ + $wc = New-Object System.Net.WebClient + $proxy = [System.Net.WebRequest]::GetSystemWebProxy() + $proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials + $wc.Proxy = $proxy + return $wc +} + Write-Host "Preparing to run build script..." if(!$PSScriptRoot){ @@ -82,31 +98,15 @@ if(!$PSScriptRoot){ } $TOOLS_DIR = Join-Path $PSScriptRoot "tools" +$ADDINS_DIR = Join-Path $TOOLS_DIR "Addins" +$MODULES_DIR = Join-Path $TOOLS_DIR "Modules" $NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe" $CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe" $NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" $PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config" $PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum" - -# Should we use mono? -$UseMono = ""; -if($Mono.IsPresent) { - Write-Verbose -Message "Using the Mono based scripting engine." - $UseMono = "-mono" -} - -# Should we use the new Roslyn? -$UseExperimental = ""; -if($Experimental.IsPresent -and !($Mono.IsPresent)) { - Write-Verbose -Message "Using experimental version of Roslyn." - $UseExperimental = "-experimental" -} - -# Is this a dry run? -$UseDryRun = ""; -if($WhatIf.IsPresent) { - $UseDryRun = "-dryrun" -} +$ADDINS_PACKAGES_CONFIG = Join-Path $ADDINS_DIR "packages.config" +$MODULES_PACKAGES_CONFIG = Join-Path $MODULES_DIR "packages.config" # Make sure tools folder exists if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) { @@ -116,8 +116,10 @@ if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) { # Make sure that packages.config exist. if (!(Test-Path $PACKAGES_CONFIG)) { - Write-Verbose -Message "Downloading packages.config..." - try { (New-Object System.Net.WebClient).DownloadFile("http://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch { + Write-Verbose -Message "Downloading packages.config..." + try { + $wc = GetProxyEnabledWebClient + $wc.DownloadFile("https://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch { Throw "Could not download packages.config." } } @@ -125,7 +127,7 @@ if (!(Test-Path $PACKAGES_CONFIG)) { # Try find NuGet.exe in path if not exists if (!(Test-Path $NUGET_EXE)) { Write-Verbose -Message "Trying to find nuget.exe in PATH..." - $existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_) } + $existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_ -PathType Container) } $NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1 if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) { Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)." @@ -137,7 +139,8 @@ if (!(Test-Path $NUGET_EXE)) { if (!(Test-Path $NUGET_EXE)) { Write-Verbose -Message "Downloading NuGet.exe..." try { - (New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE) + $wc = GetProxyEnabledWebClient + $wc.DownloadFile($NUGET_URL, $NUGET_EXE) } catch { Throw "Could not download NuGet.exe." } @@ -160,16 +163,51 @@ if(-Not $SkipToolPackageRestore.IsPresent) { } Write-Verbose -Message "Restoring tools from NuGet..." - $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -PreRelease -OutputDirectory `"$TOOLS_DIR`" -Source https://www.myget.org/F/cake/api/v3/index.json" + $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`"" if ($LASTEXITCODE -ne 0) { - Throw "An error occured while restoring NuGet tools." + Throw "An error occurred while restoring NuGet tools." } else { $md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII" } Write-Verbose -Message ($NuGetOutput | out-string) + + Pop-Location +} + +# Restore addins from NuGet +if (Test-Path $ADDINS_PACKAGES_CONFIG) { + Push-Location + Set-Location $ADDINS_DIR + + Write-Verbose -Message "Restoring addins from NuGet..." + $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$ADDINS_DIR`"" + + if ($LASTEXITCODE -ne 0) { + Throw "An error occurred while restoring NuGet addins." + } + + Write-Verbose -Message ($NuGetOutput | out-string) + + Pop-Location +} + +# Restore modules from NuGet +if (Test-Path $MODULES_PACKAGES_CONFIG) { + Push-Location + Set-Location $MODULES_DIR + + Write-Verbose -Message "Restoring modules from NuGet..." + $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$MODULES_DIR`"" + + if ($LASTEXITCODE -ne 0) { + Throw "An error occurred while restoring NuGet modules." + } + + Write-Verbose -Message ($NuGetOutput | out-string) + Pop-Location } @@ -178,7 +216,18 @@ if (!(Test-Path $CAKE_EXE)) { Throw "Could not find Cake.exe at $CAKE_EXE" } +# Build Cake arguments +$cakeArguments = @("$Script"); +if ($Target) { $cakeArguments += "-target=$Target" } +if ($Configuration) { $cakeArguments += "-configuration=$Configuration" } +if ($Verbosity) { $cakeArguments += "-verbosity=$Verbosity" } +if ($ShowDescription) { $cakeArguments += "-showdescription" } +if ($DryRun) { $cakeArguments += "-dryrun" } +if ($Experimental) { $cakeArguments += "-experimental" } +if ($Mono) { $cakeArguments += "-mono" } +$cakeArguments += $ScriptArgs + # Start Cake Write-Host "Running build script..." -Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs" -exit $LASTEXITCODE +&$CAKE_EXE $cakeArguments +exit $LASTEXITCODE \ No newline at end of file From a952629f37c14f83106047b2b0a1b8c3b384dd1a Mon Sep 17 00:00:00 2001 From: Nils Andresen Date: Wed, 22 May 2024 21:05:57 +0200 Subject: [PATCH 02/23] (#64) update CI * enable building on GitHub actions * bump image when running on appveyor * disabled Dupfinder & InspectCode since non of them run on modern CI --- .appveyor.yml | 18 +++++- .github/workflows/build.yml | 84 +++++++++++++++++++++++++++ .github/workflows/codeql-analysis.yml | 67 +++++++++++++++++++++ recipe.cake | 11 ++-- 4 files changed, 174 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/codeql-analysis.yml diff --git a/.appveyor.yml b/.appveyor.yml index 0b365f1..3b528cd 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,7 +1,23 @@ #---------------------------------# # Build Image # #---------------------------------# -image: Visual Studio 2017 +image: Visual Studio 2022 + +#---------------------------------# +# Install .NET # +#---------------------------------# +install: + - ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetsdk" + - ps: mkdir $env:DOTNET_INSTALL_DIR -Force | Out-Null + - ps: Invoke-WebRequest -Uri "https://dotnet.microsoft.com/download/dotnet/scripts/v1/dotnet-install.ps1" -OutFile "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1" + - ps: '& "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1" -Channel 2.1 -InstallDir $env:DOTNET_INSTALL_DIR' + - ps: '& "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1" -Channel 3.1 -InstallDir $env:DOTNET_INSTALL_DIR' + - ps: '& "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1" -Channel 5.0 -InstallDir $env:DOTNET_INSTALL_DIR' + - ps: '& "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1" -Channel 6.0 -InstallDir $env:DOTNET_INSTALL_DIR' + - ps: '& "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1" -Channel 7.0 -InstallDir $env:DOTNET_INSTALL_DIR' + - ps: '& "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1" -Channel 8.0 -InstallDir $env:DOTNET_INSTALL_DIR' + - ps: $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path" + - ps: dotnet --info #---------------------------------# # Build Script # diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..fa1b7a1 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,84 @@ +name: Build + +on: + push: + branches: + - master + - develop + - "feature/**" + - "release/**" + - "hotfix/**" + tags: + - "*" + paths-ignore: + - "README.md" + pull_request: + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ windows-2022, ubuntu-22.04, macos-12 ] + + env: + AZURE_PASSWORD: ${{ secrets.AZURE_PASSWORD }} + AZURE_SOURCE: ${{ secrets.AZURE_SOURCE }} + AZURE_USER: ${{ secrets.AZURE_USER }} + COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} + GITHUB_PAT: ${{ secrets.GH_TOKEN }} + GITTER_ROOM_ID: ${{ secrets.GITTER_ROOM_ID }} + GITTER_TOKEN: ${{ secrets.GITTER_TOKEN }} + GPR_PASSWORD: ${{ secrets.GPR_PASSWORD }} + GPR_SOURCE: ${{ secrets.GPR_SOURCE }} + GPR_USER: ${{ secrets.GPR_USER }} + NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} + NUGET_SOURCE: "https://api.nuget.org/v3/index.json" + TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }} + TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} + TWITTER_CONSUMER_KEY: ${{ secrets.TWITTER_CONSUMER_KEY }} + TWITTER_CONSUMER_SECRET: ${{ secrets.TWITTER_CONSUMER_SECRET }} + WYAM_ACCESS_TOKEN: ${{ secrets.WYAM_ACCESS_TOKEN }} + WYAM_DEPLOY_BRANCH: "gh-pages" + WYAM_DEPLOY_REMOTE: ${{ github.event.repository.html_url }} + + steps: + - name: Checkout the repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + - name: Fetch all tags and branches + run: git fetch --prune --unshallow + - uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4.0.0 + with: + dotnet-version: | + 2.1.818 + 3.1.x + 5.0.x + 6.0.x + 7.0.x + 8.0.x + - name: Cache Tools + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4 + with: + path: tools + key: ${{ runner.os }}-tools-${{ hashFiles('recipe.cake') }} + - name: Build project + uses: cake-build/cake-action@a6eb054329257c9e70a6c6bf01747ad6e1d9d52b # v1 + with: + script-path: recipe.cake + target: CI + cake-version: 0.32.1 + - name: Upload Issues + uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4 + with: + if-no-files-found: warn + name: ${{ matrix.os }} Issues + path: | + BuildArtifacts/report.html + BuildArtifacts/**/coverlet/*.xml + - name: Upload Packages + uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4 + if: runner.os == 'Windows' + with: + if-no-files-found: warn + name: package + path: BuildArtifacts/Packages/**/* diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..9d41c74 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,67 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +name: "CodeQL" + +on: + push: + branches: [develop] + pull_request: + # The branches below must be a subset of the branches above + branches: [develop] + schedule: + - cron: '0 15 * * 6' + workflow_dispatch: + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-22.04 + + strategy: + fail-fast: false + matrix: + # Override automatic language detection by changing the below list + # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] + language: ['csharp'] + # Learn more... + # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection + + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + with: + fetch-depth: 0 + - uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4.0.0 + with: + dotnet-version: | + 5.0.x + 8.0.x + + - name: Cache Tools + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4 + with: + path: tools + key: ${{ runner.os }}-tools-${{ hashFiles('recipe.cake') }} + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@1b1aada464948af03b950897e5eb522f92603cc2 # v3 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + - name: Build project + uses: cake-build/cake-action@a6eb054329257c9e70a6c6bf01747ad6e1d9d52b # v1 + with: + script-path: recipe.cake + target: DotNetCore-Build + cake-version: 0.32.1 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@1b1aada464948af03b950897e5eb522f92603cc2 # v3 diff --git a/recipe.cake b/recipe.cake index 7314e1d..fc28784 100644 --- a/recipe.cake +++ b/recipe.cake @@ -12,15 +12,16 @@ BuildParameters.SetParameters(context: Context, webHost: "cake-contrib.github.io", webLinkRoot: "Cake.Terraform", webBaseEditUrl: "https://github.com/cake-contrib/Cake.Terraform/tree/develop/docs/input", - shouldRunGitVersion: true); + shouldRunGitVersion: true, + shouldRunDupFinder: false, + shouldRunInspectCode: false + //preferredBuildProviderType: BuildProviderType.GitHubActions, + //preferredBuildAgentOperatingSystem: PlatformFamily.Linux + ); BuildParameters.PrintParameters(Context); ToolSettings.SetToolSettings(context: Context, - dupFinderExcludePattern: new string[] { - BuildParameters.RootDirectoryPath + "/src/Cake.Terraform.Tests/**/*.cs" - }, - dupFinderThrowExceptionOnFindingDuplicates: false, testCoverageFilter: "+[*]* -[xunit.*]* -[Cake.Core]* -[Cake.Testing]* -[*.Tests]* ", testCoverageExcludeByAttribute: "*.ExcludeFromCodeCoverage*", testCoverageExcludeByFile: "*/*Designer.cs;*/*.g.cs;*/*.g.i.cs"); From 1bd56e1fd09569d73e4409d36ceda2ce22756158 Mon Sep 17 00:00:00 2001 From: Nils Andresen Date: Wed, 22 May 2024 22:33:03 +0200 Subject: [PATCH 03/23] (#64) update CI fixes builds on GitHub actions --- .github/workflows/build.yml | 16 ++++++++++------ .github/workflows/codeql-analysis.yml | 15 +++++++++------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fa1b7a1..ded3171 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,7 +19,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ windows-2022, ubuntu-22.04, macos-12 ] + os: [ windows-2022 ] env: AZURE_PASSWORD: ${{ secrets.AZURE_PASSWORD }} @@ -61,12 +61,16 @@ jobs: with: path: tools key: ${{ runner.os }}-tools-${{ hashFiles('recipe.cake') }} + #- name: Build project + # uses: cake-build/cake-action@a6eb054329257c9e70a6c6bf01747ad6e1d9d52b # v1 + # with: + # script-path: recipe.cake + # target: CI + # cake-version: tool-manifest - name: Build project - uses: cake-build/cake-action@a6eb054329257c9e70a6c6bf01747ad6e1d9d52b # v1 - with: - script-path: recipe.cake - target: CI - cake-version: 0.32.1 + run: | + ./build.ps1 -Target DotNetCore-Build + - name: Upload Issues uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4 with: diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 9d41c74..8e63172 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -18,7 +18,7 @@ on: jobs: analyze: name: Analyze - runs-on: ubuntu-22.04 + runs-on: windows-2022 strategy: fail-fast: false @@ -56,12 +56,15 @@ jobs: # Prefix the list here with "+" to use these queries and those in the config file. # queries: ./path/to/local/query, your-org/your-repo/queries@main + #- name: Build project + # uses: cake-build/cake-action@a6eb054329257c9e70a6c6bf01747ad6e1d9d52b # v1 + # with: + # script-path: recipe.cake + # target: DotNetCore-Build + # cake-version: tool-manifest - name: Build project - uses: cake-build/cake-action@a6eb054329257c9e70a6c6bf01747ad6e1d9d52b # v1 - with: - script-path: recipe.cake - target: DotNetCore-Build - cake-version: 0.32.1 + run: | + ./build.ps1 -Target DotNetCore-Build - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@1b1aada464948af03b950897e5eb522f92603cc2 # v3 From 073fbd398a787936ca1ef0fb3cfc2ef7b7f32db5 Mon Sep 17 00:00:00 2001 From: David Obee <35892395+david-obee@users.noreply.github.com> Date: Thu, 23 May 2024 19:12:48 +0100 Subject: [PATCH 04/23] Add support for the output command (#54) added Output wrapper --------- Co-authored-by: David Obee --- .../TerraformEnvListTests.cs | 1 - .../TerraformOutputTests.cs | 205 ++++++++++++++++++ src/Cake.Terraform.sln | 56 ++--- .../Output/TerraformOutputRunner.cs | 93 ++++++++ .../Output/TerraformOutputSettings.cs | 11 + src/Cake.Terraform/TerraformAliases.cs | 8 + 6 files changed, 345 insertions(+), 29 deletions(-) create mode 100644 src/Cake.Terraform.Tests/TerraformOutputTests.cs create mode 100644 src/Cake.Terraform/Output/TerraformOutputRunner.cs create mode 100644 src/Cake.Terraform/Output/TerraformOutputSettings.cs diff --git a/src/Cake.Terraform.Tests/TerraformEnvListTests.cs b/src/Cake.Terraform.Tests/TerraformEnvListTests.cs index abf19c7..972f910 100644 --- a/src/Cake.Terraform.Tests/TerraformEnvListTests.cs +++ b/src/Cake.Terraform.Tests/TerraformEnvListTests.cs @@ -1,7 +1,6 @@ using Cake.Core; using Cake.Terraform.EnvList; using Cake.Testing; -using Cake.Testing.Fixtures; using Xunit; namespace Cake.Terraform.Tests diff --git a/src/Cake.Terraform.Tests/TerraformOutputTests.cs b/src/Cake.Terraform.Tests/TerraformOutputTests.cs new file mode 100644 index 0000000..f7bf081 --- /dev/null +++ b/src/Cake.Terraform.Tests/TerraformOutputTests.cs @@ -0,0 +1,205 @@ +using System; +using System.Collections.Generic; +using Cake.Core; +using Cake.Terraform.Output; +using Cake.Testing; +using Xunit; + +namespace Cake.Terraform.Tests +{ + public class TerraformOutputTests + { + class Fixture : TerraformFixture + { + public Fixture(PlatformFamily platformFamily = PlatformFamily.Windows) : base(platformFamily) { } + + public List ToolOutput { get; set; } = new List { "foo = 123", "bar = abc" }; + public string Outputs { get; private set; } = null; + + protected override void RunTool() + { + ProcessRunner.Process.SetStandardOutput(ToolOutput); + + var tool = new TerraformOutputRunner(FileSystem, Environment, ProcessRunner, Tools); + + Outputs = tool.Run(Settings); + } + } + + public class TheExecutable + { + [Fact] + public void Should_throw_if_terraform_runner_was_not_found() + { + var fixture = new Fixture(); + fixture.GivenDefaultToolDoNotExist(); + + var result = Record.Exception(() => fixture.Run()); + + Assert.IsType(result); + Assert.Equal("Terraform: Could not locate executable.", result.Message); + } + + [Theory] + [InlineData("/bin/tools/terraform/terraform.exe", "/bin/tools/terraform/terraform.exe")] + [InlineData("/bin/tools/terraform/terraform", "/bin/tools/terraform/terraform")] + public void Should_use_terraform_from_tool_path_if_provided(string toolPath, string expected) + { + var fixture = new Fixture() {Settings = {ToolPath = toolPath}}; + fixture.GivenSettingsToolPathExist(); + + var result = fixture.Run(); + + Assert.Equal(expected, result.Path.FullPath); + } + + [Fact] + public void Should_find_terraform_if_tool_path_not_provided() + { + var fixture = new Fixture(); + + var result = fixture.Run(); + + Assert.Equal("/Working/tools/terraform.exe", result.Path.FullPath); + } + + [Fact] + public void Should_throw_if_process_has_a_non_zero_exit_code() + { + var fixture = new Fixture(); + fixture.GivenProcessExitsWithCode(1); + + var result = Record.Exception(() => fixture.Run()); + + Assert.IsType(result); + Assert.Equal("Terraform: Process returned an error (exit code 1).", result.Message); + } + + [Fact] + public void Should_find_linux_executable() + { + var fixture = new Fixture(PlatformFamily.Linux); + fixture.Environment.Platform.Family = PlatformFamily.Linux; + + var result = fixture.Run(); + + Assert.Equal("/Working/tools/terraform", result.Path.FullPath); + } + + [Fact] + public void Should_call_only_command_if_no_settings_specified() + { + var fixture = new Fixture(); + + var result = fixture.Run(); + + Assert.Equal("output -no-color", result.Args); + } + + [Fact] + public void Should_request_json_if_specified() + { + var fixture = new Fixture { Settings = new TerraformOutputSettings { Json = true } }; + + var result = fixture.Run(); + + Assert.Equal("output -no-color -json", result.Args); + } + + [Fact] + public void Should_request_raw_if_specified() + { + var fixture = new Fixture { Settings = new TerraformOutputSettings { Raw = true } }; + + var result = fixture.Run(); + + Assert.Equal("output -no-color -raw", result.Args); + } + + [Fact] + public void Should_request_raw_over_json_if_both_are_specified() + { + var fixture = new Fixture { Settings = new TerraformOutputSettings { Raw = true, Json = true} }; + + var result = fixture.Run(); + + Assert.Equal("output -no-color -raw", result.Args); + } + + [Fact] + public void Should_request_specific_state_path_if_specified() + { + var fixture = new Fixture { Settings = new TerraformOutputSettings { StatePath = "some_path"} }; + + var result = fixture.Run(); + + Assert.Equal("output -no-color -state=some_path", result.Args); + } + + [Fact] + public void Should_request_particular_output_if_specified() + { + var fixture = new Fixture { Settings = new TerraformOutputSettings { OutputName = "some_output"} }; + + var result = fixture.Run(); + + Assert.Equal("output -no-color some_output", result.Args); + } + + [Fact] + public void Should_combine_output_lines_into_string() + { + var fixture = new Fixture(); + + fixture.Run(); + + Assert.Equal("foo = 123\nbar = abc", fixture.Outputs); + } + + [Fact] + public void Should_raise_exception_if_output_not_found() + { + var fixture = new Fixture + { + ToolOutput = new List + { + "The output variable requested could not be found in the state", + "file. If you recently added this to your configuration, be", + "sure to run `terraform apply`, since the state won't be updated", + "with new output variables until that command is run." + } + }; + + var exception = Assert.Throws(() => fixture.Run()); + Assert.Equal( + "The output variable requested could not be found in the state\nfile. If you recently added this to your configuration, be\nsure to run `terraform apply`, since the state won't be updated\nwith new output variables until that command is run.", + exception.Message); + } + + [Fact] + public void Should_not_raise_exception_if_output_not_found_and_validation_disabled() + { + var fixture = new Fixture + { + ToolOutput = new List + { + "The output variable requested could not be found in the state", + "file. If you recently added this to your configuration, be", + "sure to run `terraform apply`, since the state won't be updated", + "with new output variables until that command is run." + }, + Settings = new TerraformOutputSettings + { + ValidateToolOutput = false + } + }; + + fixture.Run(); + + Assert.Equal( + "The output variable requested could not be found in the state\nfile. If you recently added this to your configuration, be\nsure to run `terraform apply`, since the state won't be updated\nwith new output variables until that command is run.", + fixture.Outputs); + } + } + } +} \ No newline at end of file diff --git a/src/Cake.Terraform.sln b/src/Cake.Terraform.sln index f38f01f..dc1bbf6 100644 --- a/src/Cake.Terraform.sln +++ b/src/Cake.Terraform.sln @@ -1,28 +1,28 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26228.12 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cake.Terraform", "Cake.Terraform\Cake.Terraform.csproj", "{C6E9A60F-9055-4E54-9E29-7F277875ABC1}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cake.Terraform.Tests", "Cake.Terraform.Tests\Cake.Terraform.Tests.csproj", "{AB9EDCDE-48B6-4B6E-B0B6-28CF549A6591}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {C6E9A60F-9055-4E54-9E29-7F277875ABC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C6E9A60F-9055-4E54-9E29-7F277875ABC1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C6E9A60F-9055-4E54-9E29-7F277875ABC1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C6E9A60F-9055-4E54-9E29-7F277875ABC1}.Release|Any CPU.Build.0 = Release|Any CPU - {AB9EDCDE-48B6-4B6E-B0B6-28CF549A6591}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AB9EDCDE-48B6-4B6E-B0B6-28CF549A6591}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AB9EDCDE-48B6-4B6E-B0B6-28CF549A6591}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AB9EDCDE-48B6-4B6E-B0B6-28CF549A6591}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26228.12 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cake.Terraform", "Cake.Terraform\Cake.Terraform.csproj", "{C6E9A60F-9055-4E54-9E29-7F277875ABC1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cake.Terraform.Tests", "Cake.Terraform.Tests\Cake.Terraform.Tests.csproj", "{AB9EDCDE-48B6-4B6E-B0B6-28CF549A6591}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C6E9A60F-9055-4E54-9E29-7F277875ABC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C6E9A60F-9055-4E54-9E29-7F277875ABC1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C6E9A60F-9055-4E54-9E29-7F277875ABC1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C6E9A60F-9055-4E54-9E29-7F277875ABC1}.Release|Any CPU.Build.0 = Release|Any CPU + {AB9EDCDE-48B6-4B6E-B0B6-28CF549A6591}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AB9EDCDE-48B6-4B6E-B0B6-28CF549A6591}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AB9EDCDE-48B6-4B6E-B0B6-28CF549A6591}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AB9EDCDE-48B6-4B6E-B0B6-28CF549A6591}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/src/Cake.Terraform/Output/TerraformOutputRunner.cs b/src/Cake.Terraform/Output/TerraformOutputRunner.cs new file mode 100644 index 0000000..2f0d7f2 --- /dev/null +++ b/src/Cake.Terraform/Output/TerraformOutputRunner.cs @@ -0,0 +1,93 @@ +using System; +using System.Linq; +using System.Text; +using Cake.Core; +using Cake.Core.IO; +using Cake.Core.Tooling; + +namespace Cake.Terraform.Output +{ + public class TerraformOutputRunner : TerraformRunner + { + public TerraformOutputRunner(IFileSystem fileSystem, ICakeEnvironment environment, IProcessRunner processRunner, IToolLocator tools) + : base(fileSystem, environment, processRunner, tools) + { + } + + private static string RemoveWhitespace(string x) + { + return x + .Replace("\n", "") + .Replace("\r", "") + .Replace(" ", ""); + } + + private void ConfirmSuccess(string output) + { + string outputNotFoundErrorString = RemoveWhitespace("The output variable requested could not be found in the state file. If you recently added this to your configuration, be sure to run `terraform apply`, since the state won't be updated with new output variables until that command is run."); + + if (RemoveWhitespace(output) == outputNotFoundErrorString) + { + throw new ArgumentException(output); + } + } + + public string Run(TerraformOutputSettings settings) + { + var arguments = new ProcessArgumentBuilder() + .Append("output") + .Append("-no-color"); + + if (settings.StatePath != null) + { + arguments.Append($"-state={settings.StatePath}"); + } + + if (settings.Raw) + { + arguments.Append("-raw"); + } + else if (settings.Json) + { + arguments.Append("-json"); + } + + if (settings.OutputName != null) + { + arguments.Append(settings.OutputName); + } + + var processSettings = new ProcessSettings + { + RedirectStandardOutput = true + }; + + string output = null; + Run(settings, arguments, processSettings, x => + { + var outputLines = x.GetStandardOutput().ToList(); + int lineCount = outputLines.Count(); + + var builder = new StringBuilder(); + for (int i = 0; i < lineCount; i++) + { + builder.Append(outputLines[i]); + + if (i < lineCount - 1) + { + builder.Append("\n"); // OS consistent + } + } + + output = builder.ToString(); + }); + + if (settings.ValidateToolOutput) + { + ConfirmSuccess(output); + } + + return output; + } + } +} \ No newline at end of file diff --git a/src/Cake.Terraform/Output/TerraformOutputSettings.cs b/src/Cake.Terraform/Output/TerraformOutputSettings.cs new file mode 100644 index 0000000..7bc3234 --- /dev/null +++ b/src/Cake.Terraform/Output/TerraformOutputSettings.cs @@ -0,0 +1,11 @@ +namespace Cake.Terraform.Output +{ + public class TerraformOutputSettings : TerraformSettings + { + public string OutputName { get; set; } + public bool Json { get; set; } + public bool Raw { get; set; } + public string StatePath { get; set; } + public bool ValidateToolOutput { get; set; } = true; + } +} \ No newline at end of file diff --git a/src/Cake.Terraform/TerraformAliases.cs b/src/Cake.Terraform/TerraformAliases.cs index de4fcbc..5fa31aa 100644 --- a/src/Cake.Terraform/TerraformAliases.cs +++ b/src/Cake.Terraform/TerraformAliases.cs @@ -8,6 +8,7 @@ using Cake.Terraform.EnvNew; using Cake.Terraform.EnvSelect; using Cake.Terraform.Init; +using Cake.Terraform.Output; using Cake.Terraform.Plan; using Cake.Terraform.Refresh; using Cake.Terraform.Show; @@ -147,5 +148,12 @@ public static void TerraformRefresh(this ICakeContext context, TerraformRefreshS var runner = new TerraformRefreshRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); runner.Run(settings); } + + [CakeMethodAlias] + public static string TerraformOutput(this ICakeContext context, TerraformOutputSettings settings) + { + var runner = new TerraformOutputRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); + return runner.Run(settings); + } } } From cac550ad94c22608b80c8bba21fbec77c80edcde Mon Sep 17 00:00:00 2001 From: Tanner Watson Date: Tue, 11 Aug 2020 18:49:28 -0400 Subject: [PATCH 05/23] Added some missing switches to apply, init, and plan settings --- .../TerraformApplyTests.cs | 28 +++++++++- .../TerraformInitTests.cs | 52 +++++++++++++++++++ .../TerraformPlanTests.cs | 26 ++++++++++ .../Apply/TerraformApplyRunner.cs | 5 ++ .../Apply/TerraformApplySettings.cs | 11 ++++ .../Init/TerraformInitRunner.cs | 10 ++++ .../Init/TerraformInitSettings.cs | 18 +++++++ .../Plan/TerraformPlanRunner.cs | 5 ++ .../Plan/TerraformPlanSettings.cs | 11 ++++ 9 files changed, 165 insertions(+), 1 deletion(-) diff --git a/src/Cake.Terraform.Tests/TerraformApplyTests.cs b/src/Cake.Terraform.Tests/TerraformApplyTests.cs index 3c24f7f..ee5eb49 100644 --- a/src/Cake.Terraform.Tests/TerraformApplyTests.cs +++ b/src/Cake.Terraform.Tests/TerraformApplyTests.cs @@ -157,7 +157,7 @@ public void Should_set_plan_path() Assert.Equal("apply \"plan.out\"", result.Args); } - [Fact] + [Fact] public void Should_set_parallelism() { var fixture = new Fixture @@ -171,6 +171,32 @@ public void Should_set_parallelism() Assert.Contains("-parallelism=42", result.Args); } + + [Fact] + public void Should_omit_input_flag_by_default() + { + var fixture = new Fixture(); + + var result = fixture.Run(); + + Assert.DoesNotContain("-input", result.Args); + } + + [Fact] + public void Should_include_input_flag_when_setting_is_false() + { + var fixture = new Fixture + { + Settings = new TerraformApplySettings + { + Input = false + } + }; + + var result = fixture.Run(); + + Assert.Contains("-input", result.Args); + } } } } diff --git a/src/Cake.Terraform.Tests/TerraformInitTests.cs b/src/Cake.Terraform.Tests/TerraformInitTests.cs index 0af54b4..ce48d6c 100644 --- a/src/Cake.Terraform.Tests/TerraformInitTests.cs +++ b/src/Cake.Terraform.Tests/TerraformInitTests.cs @@ -163,6 +163,58 @@ public void Should_include_force_copy_flag_when_setting_is_true() Assert.Contains("-force-copy", result.Args); } + + [Fact] + public void Should_omit_input_flag_by_default() + { + var fixture = new Fixture(); + + var result = fixture.Run(); + + Assert.DoesNotContain("-input", result.Args); + } + + [Fact] + public void Should_include_input_flag_when_setting_is_false() + { + var fixture = new Fixture + { + Settings = new TerraformInitSettings + { + Input = false + } + }; + + var result = fixture.Run(); + + Assert.Contains("-input", result.Args); + } + + [Fact] + public void Should_omit_backend_flag_by_default() + { + var fixture = new Fixture(); + + var result = fixture.Run(); + + Assert.DoesNotContain("-backend", result.Args); + } + + [Fact] + public void Should_include_backend_flag_when_setting_is_false() + { + var fixture = new Fixture + { + Settings = new TerraformInitSettings + { + Backend = false + } + }; + + var result = fixture.Run(); + + Assert.Contains("-backend", result.Args); + } } } } \ No newline at end of file diff --git a/src/Cake.Terraform.Tests/TerraformPlanTests.cs b/src/Cake.Terraform.Tests/TerraformPlanTests.cs index f5c079c..1e95eee 100644 --- a/src/Cake.Terraform.Tests/TerraformPlanTests.cs +++ b/src/Cake.Terraform.Tests/TerraformPlanTests.cs @@ -205,6 +205,32 @@ public void Should_not_set_destroy_flag_if_set_to_false() Assert.DoesNotContain("-destroy", result.Args); } + + [Fact] + public void Should_omit_input_flag_by_default() + { + var fixture = new Fixture(); + + var result = fixture.Run(); + + Assert.DoesNotContain("-input", result.Args); + } + + [Fact] + public void Should_include_input_flag_when_setting_is_false() + { + var fixture = new Fixture + { + Settings = new TerraformPlanSettings + { + Input = false + } + }; + + var result = fixture.Run(); + + Assert.Contains("-input", result.Args); + } } } } \ No newline at end of file diff --git a/src/Cake.Terraform/Apply/TerraformApplyRunner.cs b/src/Cake.Terraform/Apply/TerraformApplyRunner.cs index 9d9319a..813b51c 100644 --- a/src/Cake.Terraform/Apply/TerraformApplyRunner.cs +++ b/src/Cake.Terraform/Apply/TerraformApplyRunner.cs @@ -44,6 +44,11 @@ public void Run(TerraformApplySettings settings) builder.AppendSwitchQuoted("-var", $"{inputVariable.Key}={inputVariable.Value}"); } + if (!settings.Input) + { + builder.AppendSwitch("-input", "=", settings.Input.ToString()); + } + Run(settings, builder); } } diff --git a/src/Cake.Terraform/Apply/TerraformApplySettings.cs b/src/Cake.Terraform/Apply/TerraformApplySettings.cs index 3cf537f..9587975 100644 --- a/src/Cake.Terraform/Apply/TerraformApplySettings.cs +++ b/src/Cake.Terraform/Apply/TerraformApplySettings.cs @@ -5,6 +5,11 @@ namespace Cake.Terraform.Apply { public class TerraformApplySettings : TerraformSettings { + public TerraformApplySettings() + { + this.Input = true; + } + public int Parallelism { get; set; } public FilePath Plan { get; set; } @@ -25,5 +30,11 @@ public class TerraformApplySettings : TerraformSettings /// https://www.terraform.io/docs/commands/apply.html#auto-approve /// public bool AutoApprove { get; set; } + + /// + /// Ask for input for variables if not directly set. + /// https://www.terraform.io/docs/commands/apply.html#input-true + /// + public bool Input { get; set; } } } \ No newline at end of file diff --git a/src/Cake.Terraform/Init/TerraformInitRunner.cs b/src/Cake.Terraform/Init/TerraformInitRunner.cs index 1d653c5..0dc8d32 100644 --- a/src/Cake.Terraform/Init/TerraformInitRunner.cs +++ b/src/Cake.Terraform/Init/TerraformInitRunner.cs @@ -32,6 +32,16 @@ public void Run(TerraformInitSettings settings) builder.Append("-reconfigure"); } + if (!settings.Input) + { + builder.AppendSwitch("-input", "=", settings.Input.ToString()); + } + + if (!settings.Backend) + { + builder.AppendSwitch("-backend", "=", settings.Backend.ToString()); + } + Run(settings, builder); } } diff --git a/src/Cake.Terraform/Init/TerraformInitSettings.cs b/src/Cake.Terraform/Init/TerraformInitSettings.cs index bb4b3e8..9659be4 100644 --- a/src/Cake.Terraform/Init/TerraformInitSettings.cs +++ b/src/Cake.Terraform/Init/TerraformInitSettings.cs @@ -4,6 +4,12 @@ namespace Cake.Terraform.Init { public class TerraformInitSettings : TerraformSettings { + public TerraformInitSettings() + { + this.Input = true; + this.Backend = true; + } + /// /// A set of backend config key-value overrides to be passed to `terraform init` /// https://www.terraform.io/docs/commands/init.html#backend-config-value @@ -22,5 +28,17 @@ public class TerraformInitSettings : TerraformSettings /// https://www.terraform.io/docs/commands/init.html#force-copy /// public bool ForceCopy { get; set; } + + /// + /// Ask for input if necessary. If false, will error if input was required. + /// https://www.terraform.io/docs/commands/init.html#input-true + /// + public bool Input { get; set; } + + /// + /// Configure the backend for this configuration. + /// https://www.terraform.io/docs/commands/init.html#backend-initialization + /// + public bool Backend { get; set; } } } diff --git a/src/Cake.Terraform/Plan/TerraformPlanRunner.cs b/src/Cake.Terraform/Plan/TerraformPlanRunner.cs index c1be060..3bea879 100644 --- a/src/Cake.Terraform/Plan/TerraformPlanRunner.cs +++ b/src/Cake.Terraform/Plan/TerraformPlanRunner.cs @@ -43,6 +43,11 @@ public void Run(TerraformPlanSettings settings) } } + if (!settings.Input) + { + builder.AppendSwitch("-input", "=", settings.Input.ToString()); + } + Run(settings, builder); } diff --git a/src/Cake.Terraform/Plan/TerraformPlanSettings.cs b/src/Cake.Terraform/Plan/TerraformPlanSettings.cs index bf43fb8..096e9ab 100644 --- a/src/Cake.Terraform/Plan/TerraformPlanSettings.cs +++ b/src/Cake.Terraform/Plan/TerraformPlanSettings.cs @@ -5,6 +5,11 @@ namespace Cake.Terraform.Plan { public class TerraformPlanSettings : TerraformSettings { + public TerraformPlanSettings() + { + this.Input = true; + } + public FilePath OutFile { get; set; } public int Parallelism { get; set; } @@ -24,5 +29,11 @@ public class TerraformPlanSettings : TerraformSettings /// If set to true, generates a plan to destroy all the known resources /// public bool Destroy { get; set; } + + /// + /// Ask for input for variables if not directly set. + /// https://www.terraform.io/docs/commands/plan.html#input-true + /// + public bool Input { get; set; } } } \ No newline at end of file From 05ac266138ddd0b9059a8054f501c841c45f94ab Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Fri, 2 Oct 2020 18:28:55 +0100 Subject: [PATCH 06/23] #57 Adding support for terraform validate command. --- .../TerraformValidateTests.cs | 97 +++++++++++++++++++ src/Cake.Terraform/TerraformAliases.cs | 14 +++ .../Validate/TerraformValidateRunner.cs | 32 ++++++ 3 files changed, 143 insertions(+) create mode 100644 src/Cake.Terraform.Tests/TerraformValidateTests.cs create mode 100644 src/Cake.Terraform/Validate/TerraformValidateRunner.cs diff --git a/src/Cake.Terraform.Tests/TerraformValidateTests.cs b/src/Cake.Terraform.Tests/TerraformValidateTests.cs new file mode 100644 index 0000000..745458d --- /dev/null +++ b/src/Cake.Terraform.Tests/TerraformValidateTests.cs @@ -0,0 +1,97 @@ +using System.Collections.Generic; +using Cake.Core; +using Cake.Terraform.Validate; +using Cake.Testing; +using Xunit; + +namespace Cake.Terraform.Tests +{ + public class TerraformValidateTests + { + class Fixture : TerraformFixture + { + public Fixture(PlatformFamily platformFamily = PlatformFamily.Windows) : base(platformFamily) { } + + protected override void RunTool() + { + ProcessRunner.Process.SetStandardOutput(new List { "default" }); + + var tool = new TerraformValidateRunner(FileSystem, Environment, ProcessRunner, Tools); + + tool.Run(Settings); + } + } + + public class TheExecutable + { + [Fact] + public void Should_throw_if_terraform_runner_was_not_found() + { + var fixture = new Fixture(); + fixture.GivenDefaultToolDoNotExist(); + + var result = Record.Exception(() => fixture.Run()); + + Assert.IsType(result); + Assert.Equal("Terraform: Could not locate executable.", result.Message); + } + + [Theory] + [InlineData("/bin/tools/terraform/terraform.exe", "/bin/tools/terraform/terraform.exe")] + [InlineData("/bin/tools/terraform/terraform", "/bin/tools/terraform/terraform")] + public void Should_use_terraform_from_tool_path_if_provided(string toolPath, string expected) + { + var fixture = new Fixture() { Settings = { ToolPath = toolPath } }; + fixture.GivenSettingsToolPathExist(); + + var result = fixture.Run(); + + Assert.Equal(expected, result.Path.FullPath); + } + + [Fact] + public void Should_find_terraform_if_tool_path_not_provided() + { + var fixture = new Fixture(); + + var result = fixture.Run(); + + Assert.Equal("/Working/tools/terraform.exe", result.Path.FullPath); + } + + [Fact] + public void Should_throw_if_process_has_a_non_zero_exit_code() + { + var fixture = new Fixture(); + fixture.GivenProcessExitsWithCode(1); + + var result = Record.Exception(() => fixture.Run()); + + Assert.IsType(result); + Assert.Equal("Terraform: Process returned an error (exit code 1).", result.Message); + } + + [Fact] + public void Should_find_linux_executable() + { + var fixture = new Fixture(PlatformFamily.Linux); + fixture.Environment.Platform.Family = PlatformFamily.Linux; + + + var result = fixture.Run(); + + Assert.Equal("/Working/tools/terraform", result.Path.FullPath); + } + + [Fact] + public void Should_set_workspace_and_list_parameter() + { + var fixture = new Fixture(); + + var result = fixture.Run(); + + Assert.Contains("validate", result.Args); + } + } + } +} diff --git a/src/Cake.Terraform/TerraformAliases.cs b/src/Cake.Terraform/TerraformAliases.cs index 5fa31aa..43cab81 100644 --- a/src/Cake.Terraform/TerraformAliases.cs +++ b/src/Cake.Terraform/TerraformAliases.cs @@ -12,6 +12,7 @@ using Cake.Terraform.Plan; using Cake.Terraform.Refresh; using Cake.Terraform.Show; +using Cake.Terraform.Validate; namespace Cake.Terraform { @@ -149,6 +150,19 @@ public static void TerraformRefresh(this ICakeContext context, TerraformRefreshS runner.Run(settings); } + [CakeMethodAlias] + public static void TerraformValidate(this ICakeContext context) + { + TerraformValidate(context, new TerraformValidateSettings()); + } + + [CakeMethodAlias] + public static void TerraformValidate(this ICakeContext context, TerraformValidateSettings settings) + { + var runner = new TerraformValidateRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); + runner.Run(settings); + } + [CakeMethodAlias] public static string TerraformOutput(this ICakeContext context, TerraformOutputSettings settings) { diff --git a/src/Cake.Terraform/Validate/TerraformValidateRunner.cs b/src/Cake.Terraform/Validate/TerraformValidateRunner.cs new file mode 100644 index 0000000..5774771 --- /dev/null +++ b/src/Cake.Terraform/Validate/TerraformValidateRunner.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Cake.Core; +using Cake.Core.IO; +using Cake.Core.Tooling; +using Cake.Terraform.Init; + +namespace Cake.Terraform.Validate +{ + public class TerraformValidateRunner : TerraformRunner + { + public TerraformValidateRunner(IFileSystem fileSystem, ICakeEnvironment environment, IProcessRunner processRunner, IToolLocator tools) + : base(fileSystem, environment, processRunner, tools) + { + } + + public void Run(TerraformValidateSettings settings) + { + var builder = new ProcessArgumentBuilder().Append("validate"); + + + Run(settings, builder); + } + } + + public class TerraformValidateSettings : TerraformSettings + { + } +} From f63e8a20da1867fde49fa94c8c5b1b868d22eaba Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Fri, 2 Oct 2020 18:33:57 +0100 Subject: [PATCH 07/23] #57 Updating examples. --- docs/input/docs/usage/examples.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/input/docs/usage/examples.md b/docs/input/docs/usage/examples.md index 3f2d441..41a1c98 100644 --- a/docs/input/docs/usage/examples.md +++ b/docs/input/docs/usage/examples.md @@ -143,4 +143,17 @@ Task("Destroy") }; TerraformDestroy(settings); }); +``` + + +## TerraformValidate + +```csharp +#addin Cake.Terraform + +Task("Validate") + .Does(() => +{ + TerraformValidate(); +}); ``` \ No newline at end of file From 18ca1c8fdf5ec86c89792442c3b0218934bd9852 Mon Sep 17 00:00:00 2001 From: Sergio Jozee Date: Thu, 12 Jan 2023 11:24:20 +0100 Subject: [PATCH 08/23] Adding destroy attribute to the apply --- src/Cake.Terraform/Apply/TerraformApplyRunner.cs | 5 +++++ src/Cake.Terraform/Apply/TerraformApplySettings.cs | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/src/Cake.Terraform/Apply/TerraformApplyRunner.cs b/src/Cake.Terraform/Apply/TerraformApplyRunner.cs index 813b51c..d90d077 100644 --- a/src/Cake.Terraform/Apply/TerraformApplyRunner.cs +++ b/src/Cake.Terraform/Apply/TerraformApplyRunner.cs @@ -17,6 +17,11 @@ public void Run(TerraformApplySettings settings) var builder = new ProcessArgumentBuilder() .Append("apply"); + if (settings.Destroy) + { + builder.Append("-destroy"); + } + // Order of AutoApprove and Plan are important. if (settings.AutoApprove) { diff --git a/src/Cake.Terraform/Apply/TerraformApplySettings.cs b/src/Cake.Terraform/Apply/TerraformApplySettings.cs index 9587975..0e29f9f 100644 --- a/src/Cake.Terraform/Apply/TerraformApplySettings.cs +++ b/src/Cake.Terraform/Apply/TerraformApplySettings.cs @@ -36,5 +36,11 @@ public TerraformApplySettings() /// https://www.terraform.io/docs/commands/apply.html#input-true /// public bool Input { get; set; } + + /// + /// Does destory + /// https://www.terraform.io/docs/commands/destroy.html + /// + public bool Destroy { get; set; } } } \ No newline at end of file From bac5e0f05d94f37150e6b0887528fcc40c9a357b Mon Sep 17 00:00:00 2001 From: Sergio Jozee Date: Thu, 12 Jan 2023 12:59:29 +0100 Subject: [PATCH 09/23] Updating summary and adding a test --- src/Cake.Terraform.Tests/TerraformApplyTests.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Cake.Terraform.Tests/TerraformApplyTests.cs b/src/Cake.Terraform.Tests/TerraformApplyTests.cs index ee5eb49..2107459 100644 --- a/src/Cake.Terraform.Tests/TerraformApplyTests.cs +++ b/src/Cake.Terraform.Tests/TerraformApplyTests.cs @@ -142,6 +142,22 @@ public void Should_Append_Auto_Approve_When_AutoApprove_Is_True() Assert.Contains("-auto-approve", result.Args); } + [Fact] + public void Should_Append_Destroy_When_AutoApprove_Is_True() + { + var fixture = new Fixture + { + Settings = new TerraformApplySettings + { + Destroy = true + } + }; + + var result = fixture.Run(); + + Assert.Contains("-destroy", result.Args); + } + [Fact] public void Should_set_plan_path() { From 87fd38c31a56a103ee9c315a9dc2d43e7e62f62e Mon Sep 17 00:00:00 2001 From: Nils Andresen Date: Thu, 23 May 2024 23:45:44 +0200 Subject: [PATCH 10/23] (#67) Update Cake.Recipe to 3.1.1 and Cake in CI to 1.3 --- .appveyor.yml | 4 +- .config/dotnet-tools.json | 12 ++ .github/workflows/build.yml | 16 +- .github/workflows/codeql-analysis.yml | 15 +- build.ps1 | 238 +------------------------- build.sh | 119 +------------ recipe.cake | 9 +- tools/packages.config | 4 - 8 files changed, 44 insertions(+), 373 deletions(-) create mode 100644 .config/dotnet-tools.json delete mode 100644 tools/packages.config diff --git a/.appveyor.yml b/.appveyor.yml index 3b528cd..0a58f15 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -23,7 +23,7 @@ install: # Build Script # #---------------------------------# build_script: - - ps: .\build.ps1 -Target AppVeyor + - ps: .\build.ps1 --target=CI #---------------------------------# # Tests @@ -56,7 +56,7 @@ branches: # Build Cache # #---------------------------------# cache: -- tools -> recipe.cake, tools/packages.config +- tools -> recipe.cake #---------------------------------# # Skip builds for doc changes # diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..4903ba5 --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "cake.tool": { + "version": "1.3.0", + "commands": [ + "dotnet-cake" + ] + } + } +} \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ded3171..5f0331b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,7 +19,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ windows-2022 ] + os: [ windows-2022, ubuntu-22.04, macos-12 ] env: AZURE_PASSWORD: ${{ secrets.AZURE_PASSWORD }} @@ -61,16 +61,12 @@ jobs: with: path: tools key: ${{ runner.os }}-tools-${{ hashFiles('recipe.cake') }} - #- name: Build project - # uses: cake-build/cake-action@a6eb054329257c9e70a6c6bf01747ad6e1d9d52b # v1 - # with: - # script-path: recipe.cake - # target: CI - # cake-version: tool-manifest - name: Build project - run: | - ./build.ps1 -Target DotNetCore-Build - + uses: cake-build/cake-action@a6eb054329257c9e70a6c6bf01747ad6e1d9d52b # v1 + with: + script-path: recipe.cake + target: CI + cake-version: tool-manifest - name: Upload Issues uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4 with: diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 8e63172..6dd8e1a 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -18,7 +18,7 @@ on: jobs: analyze: name: Analyze - runs-on: windows-2022 + runs-on: ubuntu-22.04 strategy: fail-fast: false @@ -56,15 +56,12 @@ jobs: # Prefix the list here with "+" to use these queries and those in the config file. # queries: ./path/to/local/query, your-org/your-repo/queries@main - #- name: Build project - # uses: cake-build/cake-action@a6eb054329257c9e70a6c6bf01747ad6e1d9d52b # v1 - # with: - # script-path: recipe.cake - # target: DotNetCore-Build - # cake-version: tool-manifest - name: Build project - run: | - ./build.ps1 -Target DotNetCore-Build + uses: cake-build/cake-action@a6eb054329257c9e70a6c6bf01747ad6e1d9d52b # v1 + with: + script-path: recipe.cake + target: DotNetCore-Build + cake-version: tool-manifest - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@1b1aada464948af03b950897e5eb522f92603cc2 # v3 diff --git a/build.ps1 b/build.ps1 index 9a6ade2..35df8f8 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,233 +1,11 @@ -########################################################################## -# This is the Cake bootstrapper script for PowerShell. -# This file was downloaded from https://github.com/cake-build/resources -# Feel free to change this file to fit your needs. -########################################################################## +Set-Location -LiteralPath $PSScriptRoot -<# +$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = '1' +$env:DOTNET_CLI_TELEMETRY_OPTOUT = '1' +$env:DOTNET_NOLOGO = '1' -.SYNOPSIS -This is a Powershell script to bootstrap a Cake build. +dotnet tool restore +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } -.DESCRIPTION -This Powershell script will download NuGet if missing, restore NuGet tools (including Cake) -and execute your Cake build script with the parameters you provide. - -.PARAMETER Script -The build script to execute. -.PARAMETER Target -The build script target to run. -.PARAMETER Configuration -The build configuration to use. -.PARAMETER Verbosity -Specifies the amount of information to be displayed. -.PARAMETER ShowDescription -Shows description about tasks. -.PARAMETER DryRun -Performs a dry run. -.PARAMETER Experimental -Uses the nightly builds of the Roslyn script engine. -.PARAMETER Mono -Uses the Mono compiler rather than the Roslyn script engine. -.PARAMETER SkipToolPackageRestore -Skips restoring of packages. -.PARAMETER ScriptArgs -Remaining arguments are added here. - -.LINK -https://cakebuild.net - -#> - -[CmdletBinding()] -Param( - [string]$Script = "recipe.cake", - [string]$Target = "Default", - [ValidateSet("Release", "Debug")] - [string]$Configuration = "Release", - [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] - [string]$Verbosity = "Verbose", - [switch]$ShowDescription, - [Alias("WhatIf", "Noop")] - [switch]$DryRun, - [switch]$Experimental, - [switch]$Mono, - [switch]$SkipToolPackageRestore, - [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] - [string[]]$ScriptArgs -) - -[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null -function MD5HashFile([string] $filePath) -{ - if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf)) - { - return $null - } - - [System.IO.Stream] $file = $null; - [System.Security.Cryptography.MD5] $md5 = $null; - try - { - $md5 = [System.Security.Cryptography.MD5]::Create() - $file = [System.IO.File]::OpenRead($filePath) - return [System.BitConverter]::ToString($md5.ComputeHash($file)) - } - finally - { - if ($file -ne $null) - { - $file.Dispose() - } - } -} - -function GetProxyEnabledWebClient -{ - $wc = New-Object System.Net.WebClient - $proxy = [System.Net.WebRequest]::GetSystemWebProxy() - $proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials - $wc.Proxy = $proxy - return $wc -} - -Write-Host "Preparing to run build script..." - -if(!$PSScriptRoot){ - $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent -} - -$TOOLS_DIR = Join-Path $PSScriptRoot "tools" -$ADDINS_DIR = Join-Path $TOOLS_DIR "Addins" -$MODULES_DIR = Join-Path $TOOLS_DIR "Modules" -$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe" -$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe" -$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config" -$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum" -$ADDINS_PACKAGES_CONFIG = Join-Path $ADDINS_DIR "packages.config" -$MODULES_PACKAGES_CONFIG = Join-Path $MODULES_DIR "packages.config" - -# Make sure tools folder exists -if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) { - Write-Verbose -Message "Creating tools directory..." - New-Item -Path $TOOLS_DIR -Type directory | out-null -} - -# Make sure that packages.config exist. -if (!(Test-Path $PACKAGES_CONFIG)) { - Write-Verbose -Message "Downloading packages.config..." - try { - $wc = GetProxyEnabledWebClient - $wc.DownloadFile("https://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch { - Throw "Could not download packages.config." - } -} - -# Try find NuGet.exe in path if not exists -if (!(Test-Path $NUGET_EXE)) { - Write-Verbose -Message "Trying to find nuget.exe in PATH..." - $existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_ -PathType Container) } - $NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1 - if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) { - Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)." - $NUGET_EXE = $NUGET_EXE_IN_PATH.FullName - } -} - -# Try download NuGet.exe if not exists -if (!(Test-Path $NUGET_EXE)) { - Write-Verbose -Message "Downloading NuGet.exe..." - try { - $wc = GetProxyEnabledWebClient - $wc.DownloadFile($NUGET_URL, $NUGET_EXE) - } catch { - Throw "Could not download NuGet.exe." - } -} - -# Save nuget.exe path to environment to be available to child processed -$ENV:NUGET_EXE = $NUGET_EXE - -# Restore tools from NuGet? -if(-Not $SkipToolPackageRestore.IsPresent) { - Push-Location - Set-Location $TOOLS_DIR - - # Check for changes in packages.config and remove installed tools if true. - [string] $md5Hash = MD5HashFile($PACKAGES_CONFIG) - if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or - ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) { - Write-Verbose -Message "Missing or changed package.config hash..." - Remove-Item * -Recurse -Exclude packages.config,nuget.exe - } - - Write-Verbose -Message "Restoring tools from NuGet..." - $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`"" - - if ($LASTEXITCODE -ne 0) { - Throw "An error occurred while restoring NuGet tools." - } - else - { - $md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII" - } - Write-Verbose -Message ($NuGetOutput | out-string) - - Pop-Location -} - -# Restore addins from NuGet -if (Test-Path $ADDINS_PACKAGES_CONFIG) { - Push-Location - Set-Location $ADDINS_DIR - - Write-Verbose -Message "Restoring addins from NuGet..." - $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$ADDINS_DIR`"" - - if ($LASTEXITCODE -ne 0) { - Throw "An error occurred while restoring NuGet addins." - } - - Write-Verbose -Message ($NuGetOutput | out-string) - - Pop-Location -} - -# Restore modules from NuGet -if (Test-Path $MODULES_PACKAGES_CONFIG) { - Push-Location - Set-Location $MODULES_DIR - - Write-Verbose -Message "Restoring modules from NuGet..." - $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$MODULES_DIR`"" - - if ($LASTEXITCODE -ne 0) { - Throw "An error occurred while restoring NuGet modules." - } - - Write-Verbose -Message ($NuGetOutput | out-string) - - Pop-Location -} - -# Make sure that Cake has been installed. -if (!(Test-Path $CAKE_EXE)) { - Throw "Could not find Cake.exe at $CAKE_EXE" -} - -# Build Cake arguments -$cakeArguments = @("$Script"); -if ($Target) { $cakeArguments += "-target=$Target" } -if ($Configuration) { $cakeArguments += "-configuration=$Configuration" } -if ($Verbosity) { $cakeArguments += "-verbosity=$Verbosity" } -if ($ShowDescription) { $cakeArguments += "-showdescription" } -if ($DryRun) { $cakeArguments += "-dryrun" } -if ($Experimental) { $cakeArguments += "-experimental" } -if ($Mono) { $cakeArguments += "-mono" } -$cakeArguments += $ScriptArgs - -# Start Cake -Write-Host "Running build script..." -&$CAKE_EXE $cakeArguments -exit $LASTEXITCODE \ No newline at end of file +dotnet cake recipe.cake @args +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } diff --git a/build.sh b/build.sh index 7fc4599..9863e90 100755 --- a/build.sh +++ b/build.sh @@ -1,117 +1,12 @@ #!/usr/bin/env bash +set -euox pipefail -########################################################################## -# This is the Cake bootstrapper script for Linux and OS X. -# This file was downloaded from https://github.com/cake-build/resources -# Feel free to change this file to fit your needs. -########################################################################## +cd "$(dirname "${BASH_SOURCE[0]}")" -# Define directories. -SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) -TOOLS_DIR=$SCRIPT_DIR/tools -ADDINS_DIR=$TOOLS_DIR/Addins -MODULES_DIR=$TOOLS_DIR/Modules -NUGET_EXE=$TOOLS_DIR/nuget.exe -CAKE_EXE=$TOOLS_DIR/Cake/Cake.exe -PACKAGES_CONFIG=$TOOLS_DIR/packages.config -PACKAGES_CONFIG_MD5=$TOOLS_DIR/packages.config.md5sum -ADDINS_PACKAGES_CONFIG=$ADDINS_DIR/packages.config -MODULES_PACKAGES_CONFIG=$MODULES_DIR/packages.config +export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 +export DOTNET_CLI_TELEMETRY_OPTOUT=1 +export DOTNET_NOLOGO=1 -# Define md5sum or md5 depending on Linux/OSX -MD5_EXE= -if [[ "$(uname -s)" == "Darwin" ]]; then - MD5_EXE="md5 -r" -else - MD5_EXE="md5sum" -fi +dotnet tool restore -# Define default arguments. -SCRIPT="recipe.cake" -CAKE_ARGUMENTS=() - -# Parse arguments. -for i in "$@"; do - case $1 in - -s|--script) SCRIPT="$2"; shift ;; - --) shift; CAKE_ARGUMENTS+=("$@"); break ;; - *) CAKE_ARGUMENTS+=("$1") ;; - esac - shift -done - -# Make sure the tools folder exist. -if [ ! -d "$TOOLS_DIR" ]; then - mkdir "$TOOLS_DIR" -fi - -# Make sure that packages.config exist. -if [ ! -f "$TOOLS_DIR/packages.config" ]; then - echo "Downloading packages.config..." - curl -Lsfo "$TOOLS_DIR/packages.config" https://cakebuild.net/download/bootstrapper/packages - if [ $? -ne 0 ]; then - echo "An error occurred while downloading packages.config." - exit 1 - fi -fi - -# Download NuGet if it does not exist. -if [ ! -f "$NUGET_EXE" ]; then - echo "Downloading NuGet..." - curl -Lsfo "$NUGET_EXE" https://dist.nuget.org/win-x86-commandline/latest/nuget.exe - if [ $? -ne 0 ]; then - echo "An error occurred while downloading nuget.exe." - exit 1 - fi -fi - -# Restore tools from NuGet. -pushd "$TOOLS_DIR" >/dev/null -if [ ! -f "$PACKAGES_CONFIG_MD5" ] || [ "$( cat "$PACKAGES_CONFIG_MD5" | sed 's/\r$//' )" != "$( $MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' )" ]; then - find . -type d ! -name . ! -name 'Cake.Bakery' | xargs rm -rf -fi - -mono "$NUGET_EXE" install -ExcludeVersion -if [ $? -ne 0 ]; then - echo "Could not restore NuGet tools." - exit 1 -fi - -$MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' >| "$PACKAGES_CONFIG_MD5" - -popd >/dev/null - -# Restore addins from NuGet. -if [ -f "$ADDINS_PACKAGES_CONFIG" ]; then - pushd "$ADDINS_DIR" >/dev/null - - mono "$NUGET_EXE" install -ExcludeVersion - if [ $? -ne 0 ]; then - echo "Could not restore NuGet addins." - exit 1 - fi - - popd >/dev/null -fi - -# Restore modules from NuGet. -if [ -f "$MODULES_PACKAGES_CONFIG" ]; then - pushd "$MODULES_DIR" >/dev/null - - mono "$NUGET_EXE" install -ExcludeVersion - if [ $? -ne 0 ]; then - echo "Could not restore NuGet modules." - exit 1 - fi - - popd >/dev/null -fi - -# Make sure that Cake has been installed. -if [ ! -f "$CAKE_EXE" ]; then - echo "Could not find Cake.exe at '$CAKE_EXE'." - exit 1 -fi - -# Start Cake -exec mono "$CAKE_EXE" $SCRIPT "${CAKE_ARGUMENTS[@]}" +dotnet cake recipe.cake "$@" diff --git a/recipe.cake b/recipe.cake index fc28784..950f322 100644 --- a/recipe.cake +++ b/recipe.cake @@ -1,4 +1,4 @@ -#load nuget:?package=Cake.Recipe&version=1.0.0 +#load nuget:?package=Cake.Recipe&version=3.1.1 Environment.SetVariableNames(); @@ -8,13 +8,9 @@ BuildParameters.SetParameters(context: Context, title: "Cake.Terraform", repositoryOwner: "cake-contrib", repositoryName: "Cake.Terraform", - appVeyorAccountName: "cakecontrib", webHost: "cake-contrib.github.io", webLinkRoot: "Cake.Terraform", - webBaseEditUrl: "https://github.com/cake-contrib/Cake.Terraform/tree/develop/docs/input", - shouldRunGitVersion: true, - shouldRunDupFinder: false, - shouldRunInspectCode: false + webBaseEditUrl: "https://github.com/cake-contrib/Cake.Terraform/tree/develop/docs/input" //preferredBuildProviderType: BuildProviderType.GitHubActions, //preferredBuildAgentOperatingSystem: PlatformFamily.Linux ); @@ -27,3 +23,4 @@ ToolSettings.SetToolSettings(context: Context, testCoverageExcludeByFile: "*/*Designer.cs;*/*.g.cs;*/*.g.i.cs"); Build.RunDotNetCore(); + diff --git a/tools/packages.config b/tools/packages.config deleted file mode 100644 index f27ab48..0000000 --- a/tools/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - From f2d0ddf345ec3ad57be21252a70bcab6318b724f Mon Sep 17 00:00:00 2001 From: Nils Andresen Date: Fri, 24 May 2024 00:06:05 +0200 Subject: [PATCH 11/23] (#67) switched from nuspec to packing using dotnet --- nuspec/nuget/Cake.Terraform.nuspec | 24 ------------------------ recipe.cake | 8 +++----- src/Cake.Terraform/Cake.Terraform.csproj | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 29 deletions(-) delete mode 100644 nuspec/nuget/Cake.Terraform.nuspec diff --git a/nuspec/nuget/Cake.Terraform.nuspec b/nuspec/nuget/Cake.Terraform.nuspec deleted file mode 100644 index 005d096..0000000 --- a/nuspec/nuget/Cake.Terraform.nuspec +++ /dev/null @@ -1,24 +0,0 @@ - - - - Cake.Terraform - 0.0.0 - Erik van Brakel - Erik van Brakel - Cake Terraform Addin. - Cake AddIn that extends Cake with ability to execute terraform commands. - https://github.com/cake-contrib/Cake.Terraform/ - https://cdn.jsdelivr.net/gh/cake-contrib/graphics/png/cake-contrib-medium.png - false - MIT - - Copyright (c) 2017 - Present - Cake, Script, Build, Terraform, Hashicorp - - - - - - - - diff --git a/recipe.cake b/recipe.cake index 950f322..5afea91 100644 --- a/recipe.cake +++ b/recipe.cake @@ -10,17 +10,15 @@ BuildParameters.SetParameters(context: Context, repositoryName: "Cake.Terraform", webHost: "cake-contrib.github.io", webLinkRoot: "Cake.Terraform", - webBaseEditUrl: "https://github.com/cake-contrib/Cake.Terraform/tree/develop/docs/input" + webBaseEditUrl: "https://github.com/cake-contrib/Cake.Terraform/tree/develop/docs/input", + shouldRunDotNetCorePack: true //preferredBuildProviderType: BuildProviderType.GitHubActions, //preferredBuildAgentOperatingSystem: PlatformFamily.Linux ); BuildParameters.PrintParameters(Context); -ToolSettings.SetToolSettings(context: Context, - testCoverageFilter: "+[*]* -[xunit.*]* -[Cake.Core]* -[Cake.Testing]* -[*.Tests]* ", - testCoverageExcludeByAttribute: "*.ExcludeFromCodeCoverage*", - testCoverageExcludeByFile: "*/*Designer.cs;*/*.g.cs;*/*.g.i.cs"); +ToolSettings.SetToolSettings(context: Context); Build.RunDotNetCore(); diff --git a/src/Cake.Terraform/Cake.Terraform.csproj b/src/Cake.Terraform/Cake.Terraform.csproj index 749cf9a..0a1d541 100644 --- a/src/Cake.Terraform/Cake.Terraform.csproj +++ b/src/Cake.Terraform/Cake.Terraform.csproj @@ -4,6 +4,21 @@ net461;netstandard2.0 + + + Erik van Brakel + opyright (c) 2017 - Present — Erik van Brakel + Cake AddIn that extends Cake with ability to execute terraform commands. + MIT + https://github.com/cake-contrib/Cake.Terraform + cake;build;cake-build;script;addin;cake-addin;terraform;hashicorp + $(PackageProjectUrl).git + https://github.com/cake-contrib/Cake.7zip/releases + Cake.SevenZip + 0.0.0 + https://cdn.jsdelivr.net/gh/cake-contrib/graphics/png/cake-contrib-medium.png + + 0.33.0 From 93d87729d2f9a817c59f4dcc970b8ef920ad7d62 Mon Sep 17 00:00:00 2001 From: Nils Andresen Date: Fri, 24 May 2024 00:13:02 +0200 Subject: [PATCH 12/23] (#67) added a reference to CakeContrib.Guidelines this also updates the icon in the nupkg - see #61 --- src/Cake.Terraform/Cake.Terraform.csproj | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Cake.Terraform/Cake.Terraform.csproj b/src/Cake.Terraform/Cake.Terraform.csproj index 0a1d541..cb3e4fc 100644 --- a/src/Cake.Terraform/Cake.Terraform.csproj +++ b/src/Cake.Terraform/Cake.Terraform.csproj @@ -16,13 +16,17 @@ https://github.com/cake-contrib/Cake.7zip/releases Cake.SevenZip 0.0.0 - https://cdn.jsdelivr.net/gh/cake-contrib/graphics/png/cake-contrib-medium.png 0.33.0 + + 1.5.1 + all + runtime; build; native; contentfiles; analyzers; buildtransitive + From 19321b124bde00ee1097a39ad5b0b35cd705cb65 Mon Sep 17 00:00:00 2001 From: Nils Andresen Date: Fri, 24 May 2024 00:14:21 +0200 Subject: [PATCH 13/23] (#67) added a reference to Cake.Addin.Analyzer --- src/Cake.Terraform/Cake.Terraform.csproj | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Cake.Terraform/Cake.Terraform.csproj b/src/Cake.Terraform/Cake.Terraform.csproj index cb3e4fc..61b88f0 100644 --- a/src/Cake.Terraform/Cake.Terraform.csproj +++ b/src/Cake.Terraform/Cake.Terraform.csproj @@ -19,6 +19,11 @@ + + 0.1.3 + all + runtime; build; native; contentfiles; analyzers; buildtransitive + 0.33.0 From 883742c108cef7ec31906c33f6fc792bb85fc53f Mon Sep 17 00:00:00 2001 From: Nils Andresen Date: Fri, 24 May 2024 23:24:23 +0200 Subject: [PATCH 14/23] bump xunit references to try and work around https://github.com/microsoft/vstest/issues/2469 --- src/Cake.Terraform.Tests/Cake.Terraform.Tests.csproj | 9 +++++++-- src/Cake.Terraform/Cake.Terraform.csproj | 3 +-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Cake.Terraform.Tests/Cake.Terraform.Tests.csproj b/src/Cake.Terraform.Tests/Cake.Terraform.Tests.csproj index c670ae2..cbeeea9 100644 --- a/src/Cake.Terraform.Tests/Cake.Terraform.Tests.csproj +++ b/src/Cake.Terraform.Tests/Cake.Terraform.Tests.csproj @@ -8,8 +8,13 @@ - - + + + + diff --git a/src/Cake.Terraform/Cake.Terraform.csproj b/src/Cake.Terraform/Cake.Terraform.csproj index 61b88f0..87bf7fa 100644 --- a/src/Cake.Terraform/Cake.Terraform.csproj +++ b/src/Cake.Terraform/Cake.Terraform.csproj @@ -13,8 +13,7 @@ https://github.com/cake-contrib/Cake.Terraform cake;build;cake-build;script;addin;cake-addin;terraform;hashicorp $(PackageProjectUrl).git - https://github.com/cake-contrib/Cake.7zip/releases - Cake.SevenZip + $(PackageProjectUrl)/releases 0.0.0 From 233115b452028af5a2072fdd4a197737748c9fc7 Mon Sep 17 00:00:00 2001 From: Nils Andresen Date: Sat, 25 May 2024 00:40:46 +0200 Subject: [PATCH 15/23] disable codeCov, as upload breaks on every build --- recipe.cake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/recipe.cake b/recipe.cake index 5afea91..0fac8aa 100644 --- a/recipe.cake +++ b/recipe.cake @@ -11,7 +11,8 @@ BuildParameters.SetParameters(context: Context, webHost: "cake-contrib.github.io", webLinkRoot: "Cake.Terraform", webBaseEditUrl: "https://github.com/cake-contrib/Cake.Terraform/tree/develop/docs/input", - shouldRunDotNetCorePack: true + shouldRunDotNetCorePack: true, + shouldRunCodecov: false //preferredBuildProviderType: BuildProviderType.GitHubActions, //preferredBuildAgentOperatingSystem: PlatformFamily.Linux ); From d60422111bd6f02adb62c0b83e7b2d70cf1c7b02 Mon Sep 17 00:00:00 2001 From: Nils Andresen Date: Sat, 25 May 2024 01:16:08 +0200 Subject: [PATCH 16/23] (#69) added README to nupkg --- src/Cake.Terraform/Cake.Terraform.csproj | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Cake.Terraform/Cake.Terraform.csproj b/src/Cake.Terraform/Cake.Terraform.csproj index 87bf7fa..93df888 100644 --- a/src/Cake.Terraform/Cake.Terraform.csproj +++ b/src/Cake.Terraform/Cake.Terraform.csproj @@ -4,6 +4,10 @@ net461;netstandard2.0 + + + + Erik van Brakel @@ -15,6 +19,7 @@ $(PackageProjectUrl).git $(PackageProjectUrl)/releases 0.0.0 + README.md From 4014199af53ba985e580624575832f63d9260e16 Mon Sep 17 00:00:00 2001 From: Nils Andresen Date: Sat, 25 May 2024 01:47:47 +0200 Subject: [PATCH 17/23] (#73) enabled deterministic builds --- .../Cake.Terraform.Tests.csproj | 4 +++ src/Cake.Terraform/Cake.Terraform.csproj | 4 +++ src/Directory.Build.targets | 27 +++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 src/Directory.Build.targets diff --git a/src/Cake.Terraform.Tests/Cake.Terraform.Tests.csproj b/src/Cake.Terraform.Tests/Cake.Terraform.Tests.csproj index cbeeea9..cbe3428 100644 --- a/src/Cake.Terraform.Tests/Cake.Terraform.Tests.csproj +++ b/src/Cake.Terraform.Tests/Cake.Terraform.Tests.csproj @@ -7,6 +7,10 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + true + true + $([System.IO.Path]::Combine('$(IntermediateOutputPath)','$(TargetFrameworkMoniker).AssemblyAttributes$(DefaultLanguageSourceExtension)')) + + + + + + + + + + + <_LocalTopLevelSourceRoot Include="@(SourceRoot)" Condition="'%(SourceRoot.NestedRoot)' == ''"/> + + + From abd767d6f504d41856bd46930198739ee84e2ad1 Mon Sep 17 00:00:00 2001 From: Nils Andresen Date: Sun, 26 May 2024 00:46:27 +0200 Subject: [PATCH 18/23] (#59) bump reference of cake.core to v 1.0.0 --- .../Cake.Terraform.Tests.csproj | 14 ++++++++++---- src/Cake.Terraform/Cake.Terraform.csproj | 4 ++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Cake.Terraform.Tests/Cake.Terraform.Tests.csproj b/src/Cake.Terraform.Tests/Cake.Terraform.Tests.csproj index cbe3428..7274d57 100644 --- a/src/Cake.Terraform.Tests/Cake.Terraform.Tests.csproj +++ b/src/Cake.Terraform.Tests/Cake.Terraform.Tests.csproj @@ -1,17 +1,23 @@  - net461 + + netcoreapp3.1 + net461;net5.0 - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - +