diff --git a/.azure/checks.ps1 b/.azure/checks.ps1 deleted file mode 100644 index 9a8f8747b..000000000 --- a/.azure/checks.ps1 +++ /dev/null @@ -1,27 +0,0 @@ -# Check if Azure CLI is installed -$azPath = (Get-Command az -ErrorAction SilentlyContinue).Source -if (-not $azPath) { - Write-Host "Azure CLI (az) is not installed. Please install it and try again." - return -} - -# Check if GitHub CLI is installed -$ghPath = (Get-Command gh -ErrorAction SilentlyContinue).Source -if (-not $ghPath) { - Write-Host "GitHub CLI (gh) is not installed. Please install it and try again." - return -} - -# Check if Azure CLI is authenticated -$azLoggedIn = (az account show -o json) -ne $null -if (-not $azLoggedIn) { - Write-Host "Azure CLI (az) is not authenticated. Please authenticate with Azure CLI and try again." - return -} - -# Check if GitHub CLI is authenticated -$ghAuthStatus = (gh auth status) -if (-not ($ghAuthStatus -like "*Logged in to github.com*")) { - Write-Host "GitHub CLI (gh) is not authenticated. Please authenticate with GitHub CLI and try again." - return -} \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 54d519e5e..4326a3729 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,6 +4,7 @@ on: pull_request: branches: [ main ] paths-ignore: + - '.scripts/**' - .gitignore - CODE_OF_CONDUCT.md - LICENSE diff --git a/.scripts/checks.ps1 b/.scripts/checks.ps1 new file mode 100644 index 000000000..5dbd5dff7 --- /dev/null +++ b/.scripts/checks.ps1 @@ -0,0 +1,29 @@ +# Check if Azure CLI is installed +$azPath = (Get-Command az -ErrorAction SilentlyContinue).Source +if (-not $azPath) { + throw "Azure CLI (az) is not installed. Please install it and try again." +} + +# Check if Azure CLI is authenticated +az account show --output none +if ($LASTEXITCODE -ne 0) { + throw "Azure CLI (az) is not authenticated. Please authenticate with Azure CLI and try again." +} + +# Check if GitHub CLI is installed +$ghPath = (Get-Command gh -ErrorAction SilentlyContinue).Source +if (-not $ghPath) { + throw "GitHub CLI (gh) is not installed. Please install it and try again." +} + +# Check if GitHub CLI is authenticated +gh auth status | Out-Null +if ($LASTEXITCODE -ne 0) { + throw "GitHub CLI (gh) is not authenticated. Please authenticate with GitHub CLI and try again." +} + +# Check if Git repo is initialised +git status | Out-Null +if ($LASTEXITCODE -ne 0) { + throw "The Git repository has not been initialised. Please create a new GitHub repository and try again." +} \ No newline at end of file diff --git a/.azure/cleanup.ps1 b/.scripts/cleanup.ps1 similarity index 89% rename from .azure/cleanup.ps1 rename to .scripts/cleanup.ps1 index 2766f1297..824909d6f 100644 --- a/.azure/cleanup.ps1 +++ b/.scripts/cleanup.ps1 @@ -2,7 +2,16 @@ Param( [String]$ProjectName ) -. ".\checks.ps1" +$scriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path +$checksScript = Join-Path $scriptRoot "checks.ps1" + +try { + . $checksScript +} catch { + Write-Host $_.Exception.Message -ForegroundColor Red + Write-Host "Setup script terminated due to the checks failure." -ForegroundColor Red + exit 1 +} $MissingParameterValues = $false diff --git a/.azure/environments.json b/.scripts/environments.json similarity index 100% rename from .azure/environments.json rename to .scripts/environments.json diff --git a/.azure/setup.ps1 b/.scripts/setup.ps1 similarity index 93% rename from .azure/setup.ps1 rename to .scripts/setup.ps1 index 315d80e42..70e0a350d 100644 --- a/.azure/setup.ps1 +++ b/.scripts/setup.ps1 @@ -9,7 +9,17 @@ Param( [String]$AzureSqlLogin = "SqlAdmin" ) -. ".\checks.ps1" +$scriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path +$checksScript = Join-Path $scriptRoot "checks.ps1" +$environmentsFile = Join-Path $scriptRoot "environments.json" + +try { + . $checksScript +} catch { + Write-Host $_.Exception.Message -ForegroundColor Red + Write-Host "Setup script terminated due to the checks failure." -ForegroundColor Red + exit 1 +} $MissingParameterValues = $false @@ -52,7 +62,7 @@ if (-not $ProjectName) { $repoUrl = "https://github.com/$GitHubOrganisationName/$GitHubRepositoryName" -$environments = Get-Content -Raw -Path "environments.json" | ConvertFrom-Json +$environments = Get-Content -Raw -Path $environmentsFile | ConvertFrom-Json $ParametersTableData = @{ "AzureLocation" = $AzureLocation @@ -72,7 +82,7 @@ $ParametersTableData | Format-Table -AutoSize if ($MissingParameterValues) { Write-Host "Script execution cancelled. Missing parameter values." -ForegroundColor Red - return + exit 1 } $EnvironmentTableData = foreach ($environment in $environments.PSObject.Properties) { diff --git a/CleanArchitecture.nuspec b/CleanArchitecture.nuspec index e34721a80..2ffbf89d5 100644 --- a/CleanArchitecture.nuspec +++ b/CleanArchitecture.nuspec @@ -3,7 +3,7 @@ Clean.Architecture.Solution.Template - 8.0.0-preview.6.10 + 8.0.0-preview.6.11 Clean Architecture Solution Template JasonTaylorDev Clean Architecture Solution Template for .NET 8. @@ -11,7 +11,7 @@ A Clean Architecture Solution Template for creating apps using Angular, React, or Web API only with ASP.NET Core. - General improvements and bug fixes. + General improvements for supporting scripts. https://github.com/JasonTaylorDev/CleanArchitecture diff --git a/README-template.md b/README-template.md index 89f7b8991..65e940d1d 100644 --- a/README-template.md +++ b/README-template.md @@ -1,6 +1,6 @@ # CleanArchitecture -The project was generated using the [Clean.Architecture.Solution.Template](https://github.com/jasontaylordev/CleanArchitecture) version 8.0.0-preview.6.10. +The project was generated using the [Clean.Architecture.Solution.Template](https://github.com/jasontaylordev/CleanArchitecture) version 8.0.0-preview.6.11. ## Build @@ -38,7 +38,7 @@ dotnet new ca-usecase -n GetTodos -fn TodoLists -ut query -rt TodosVm If you encounter the error *"No templates or subcommands found matching: 'ca-usecase'."*, install the template and try again: ```bash -dotnet new install Clean.Architecture.Solution.Template::8.0.0-preview.6.10 +dotnet new install Clean.Architecture.Solution.Template::8.0.0-preview.6.11 ``` ## Test diff --git a/README.md b/README.md index 80616a71b..527828c0d 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ If you find this project useful, please give it a star. Thanks! ⭐ The easiest way to get started is to install the [.NET template](https://www.nuget.org/packages/Clean.Architecture.Solution.Template): ``` -dotnet new install Clean.Architecture.Solution.Template::8.0.0-preview.6.10 +dotnet new install Clean.Architecture.Solution.Template::8.0.0-preview.6.11 ``` Once installed, create a new solution using the template. You can choose to use Angular, React, or create a Web API-only solution. Specify the client framework using the `-cf` or `--client-framework` option, and provide the output directory where your project will be created. Here are some examples: