From f817df939e9b7b94544644b379fcf4180c406a4c Mon Sep 17 00:00:00 2001 From: tesar-tech Date: Mon, 6 Jan 2025 10:32:03 +0100 Subject: [PATCH] version updates, gha update --- .github/workflows/publish-to-nuget.yml | 122 ++++++++++++++++++ BlazorStatic.Templates.csproj | 10 +- pack_and_test.ps1 | 8 +- .../.template-config/dotnetcli.host.json | 2 +- .../.template-config/template.json | 4 +- .../BlazorStaticMinimalBlog.csproj | 4 +- .../Components/Pages/Blog.razor | 2 +- .../Components/Pages/Tags.razor | 6 +- .../Components/PostsList.razor | 2 +- .../Program.cs | 4 + 10 files changed, 145 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/publish-to-nuget.yml diff --git a/.github/workflows/publish-to-nuget.yml b/.github/workflows/publish-to-nuget.yml new file mode 100644 index 0000000..f013ff4 --- /dev/null +++ b/.github/workflows/publish-to-nuget.yml @@ -0,0 +1,122 @@ + + +name: Build, publish to gh pages and nuget + +on: + workflow_dispatch: + inputs: + new_version_blazorstatic: + description: "Enter the new BlazorStatic version" + required: true + default: "1.0.0-beta.XX" + +env: + TEMPLATE_PROJ_PATH: BlazorStaticTemplates/BlazorStatic.Templates.csproj + NUGET_FOLDER: nugetky + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: write + + + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-dotnet@v4 + with: + dotnet-version: '9.0.x' + + - name: Update .csproj files with new version + run: | + # Define the list of .csproj files + csproj_files=( + "templates/BlazorStaticMinimalBlogTemplate/BlazorStaticMinimalBlog.csproj" + ) + + # Loop through each file and update the version + for csproj_file in "${csproj_files[@]}"; do + if [[ ! -f "$csproj_file" ]]; then + echo "Error: $csproj_file does not exist." + exit 1 + fi + + # Replace the version in the .csproj file + sed -i "s/).*?(?=)' ./BlazorStatic.Templates.csproj) + echo "current_version=$current_version" >> $GITHUB_ENV + + # Step 3: Increment the version using the action + - name: Increment version + id: increment-version + uses: christian-draeger/increment-semantic-version@v2 + with: + current-version: ${{ env.current_version }} + version-fragment: minor + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + + + - name: Update version in csproj + run: | + sed -i "s/${{ env.current_version }}<\/PackageVersion>/${{ steps.increment-version.outputs.next-version }}<\/PackageVersion>/" ./BlazorStatic.Templates.csproj + + + + + - name: Create nuget BlazorStatic.Templates to destination folder + run: | + mkdir -p "${{ env.NUGET_FOLDER }}" + dotnet pack BlazorStatic.Templates.csproj --output ${{ env.NUGET_FOLDER }} + + # Step: Install package, create project, and build + - name: Test Template Installation and Build + run: | + # Use the dynamically determined package version + package_version="${{ steps.increment-version.outputs.next-version }}" + + echo "Using package version: $package_version" + + # Install the template package + dotnet new install --force "bin/Release/BlazorStatic.Templates.${package_version}.nupkg" + + # Create a new project from the template + dotnet new BlazorStaticMinimalBlog -o "TestProject" --force + + # Build the newly created project + dotnet build "TestProject" + + +# - uses: stefanzweifel/git-auto-commit-action@v5 +# +# - name: Upload NuGet package artifacts +# uses: actions/upload-artifact@v4 +# with: +# name: nuget-packages +# path: ${{ env.NUGET_FOLDER }}/*.nupkg +# +# publish-to-nuget: +# needs: build +# runs-on: ubuntu-latest +# steps: +# - name: Download NuGet package artifacts +# uses: actions/download-artifact@v4 +# with: +# name: nuget-packages +# - run: dotnet nuget push "*.nupkg" --source "https://api.nuget.org/v3/index.json" --api-key ${{ secrets.NUGET_API_KEY_BLAZORSTATIC_TEMPLATES }} diff --git a/BlazorStatic.Templates.csproj b/BlazorStatic.Templates.csproj index 0f35508..b851251 100644 --- a/BlazorStatic.Templates.csproj +++ b/BlazorStatic.Templates.csproj @@ -8,7 +8,7 @@ tesar.tech Templates for creating project for static websites using BlazorStatic. dotnet-new;templates;blazor;static;website;generator;BlazorStatic - net8.0 + net9.0 true @@ -18,8 +18,8 @@ true README.md - AGPL-3.0-or-later - https://github.com/tesar-tech/BlazorStatic/ + MIT + https://github.com/BlazorStatic/BlazorStatic/ @@ -27,12 +27,12 @@ - + - + diff --git a/pack_and_test.ps1 b/pack_and_test.ps1 index a02219b..14de273 100644 --- a/pack_and_test.ps1 +++ b/pack_and_test.ps1 @@ -1,16 +1,16 @@ # Quick packing to see the result. Change the version if needed. Write-Host "Packing the project..." -ForegroundColor Cyan -dotnet pack +dotnet pack /p:PackageVersion=1.0.0-test Write-Host "Uninstalling the old template 'BlazorStatic.Templates'..." -ForegroundColor Cyan dotnet new uninstall BlazorStatic.Templates Write-Host "Installing the new template" -ForegroundColor Cyan -dotnet new install --force "bin/Release/BlazorStatic.Templates.1.0.2.nupkg" +dotnet new install --force "bin/Release/BlazorStatic.Templates.1.0.0-test.nupkg" Write-Host "Removing the old 'TestProject' directory..." -ForegroundColor Cyan -Remove-Item -Recurse -Force -Path ".\TestProject" +Remove-Item -Recurse -Force -Path "./TestProject" Write-Host "Creating a new project from the 'BlazorStaticMinimalBlog' template..." -ForegroundColor Cyan -dotnet new BlazorStaticMinimalBlog -o "TestProject" --force -e +dotnet new BlazorStaticMinimalBlog -o "TestProject" --force diff --git a/templates/BlazorStaticMinimalBlogTemplate/.template-config/dotnetcli.host.json b/templates/BlazorStaticMinimalBlogTemplate/.template-config/dotnetcli.host.json index 2f5de78..da3ff0e 100644 --- a/templates/BlazorStaticMinimalBlogTemplate/.template-config/dotnetcli.host.json +++ b/templates/BlazorStaticMinimalBlogTemplate/.template-config/dotnetcli.host.json @@ -3,7 +3,7 @@ "symbolInfo": { "ExcludeDefaultPosts": { "longName": "exclude-default-posts", - "shortName": "e" + "shortName": "e", } } } diff --git a/templates/BlazorStaticMinimalBlogTemplate/.template-config/template.json b/templates/BlazorStaticMinimalBlogTemplate/.template-config/template.json index 391e0b0..e440083 100644 --- a/templates/BlazorStaticMinimalBlogTemplate/.template-config/template.json +++ b/templates/BlazorStaticMinimalBlogTemplate/.template-config/template.json @@ -37,12 +37,12 @@ { "condition": "true", "exclude": [ - "./BlazorStaticMinimalBlog/.git", + "./.git", ".git" ] } ], - "source": "./BlazorStaticMinimalBlog" + "source": "./" } ], "symbols": { diff --git a/templates/BlazorStaticMinimalBlogTemplate/BlazorStaticMinimalBlog.csproj b/templates/BlazorStaticMinimalBlogTemplate/BlazorStaticMinimalBlog.csproj index da49219..4132561 100644 --- a/templates/BlazorStaticMinimalBlogTemplate/BlazorStaticMinimalBlog.csproj +++ b/templates/BlazorStaticMinimalBlogTemplate/BlazorStaticMinimalBlog.csproj @@ -1,13 +1,13 @@ - net8.0 + net9.0 enable enable - + diff --git a/templates/BlazorStaticMinimalBlogTemplate/Components/Pages/Blog.razor b/templates/BlazorStaticMinimalBlogTemplate/Components/Pages/Blog.razor index 8caed65..fc372df 100644 --- a/templates/BlazorStaticMinimalBlogTemplate/Components/Pages/Blog.razor +++ b/templates/BlazorStaticMinimalBlogTemplate/Components/Pages/Blog.razor @@ -96,7 +96,7 @@
@foreach(var tag in post.FrontMatter.Tags) { - @tag + @tag }
diff --git a/templates/BlazorStaticMinimalBlogTemplate/Components/Pages/Tags.razor b/templates/BlazorStaticMinimalBlogTemplate/Components/Pages/Tags.razor index e02e144..a56acf6 100644 --- a/templates/BlazorStaticMinimalBlogTemplate/Components/Pages/Tags.razor +++ b/templates/BlazorStaticMinimalBlogTemplate/Components/Pages/Tags.razor @@ -10,14 +10,14 @@
@{ var tagsWithCount = blazorStaticContentService.Posts - .SelectMany(x => x.FrontMatter.Tags) + .SelectMany(x => x.Tags) .GroupBy(x => x) .Select(group => new { Tag = group.Key, Count = group.Count() }) .OrderByDescending(x => x.Count); - foreach(var tag in tagsWithCount) + foreach(var tagGroup in tagsWithCount) { - @tag.Tag (@tag.Count) + @tagGroup.Tag.Name } }
diff --git a/templates/BlazorStaticMinimalBlogTemplate/Components/PostsList.razor b/templates/BlazorStaticMinimalBlogTemplate/Components/PostsList.razor index 8626500..94bd36f 100644 --- a/templates/BlazorStaticMinimalBlogTemplate/Components/PostsList.razor +++ b/templates/BlazorStaticMinimalBlogTemplate/Components/PostsList.razor @@ -29,7 +29,7 @@
@foreach(var tag in post.FrontMatter.Tags) { - @tag + @tag }
diff --git a/templates/BlazorStaticMinimalBlogTemplate/Program.cs b/templates/BlazorStaticMinimalBlogTemplate/Program.cs index d522d8a..4b22141 100644 --- a/templates/BlazorStaticMinimalBlogTemplate/Program.cs +++ b/templates/BlazorStaticMinimalBlogTemplate/Program.cs @@ -1,4 +1,8 @@ using BlazorStatic; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using BlazorStaticMinimalBlog.Components; var builder = WebApplication.CreateBuilder(args);