Skip to content

Commit

Permalink
Merge pull request #1 from BlazorStatic/gha-test
Browse files Browse the repository at this point in the history
version updates, gha update
  • Loading branch information
tesar-tech authored Jan 6, 2025
2 parents 7cbf00a + f817df9 commit 805448e
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 19 deletions.
122 changes: 122 additions & 0 deletions .github/workflows/publish-to-nuget.yml
Original file line number Diff line number Diff line change
@@ -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/<PackageReference Include=\"BlazorStatic\" Version=\"[^\"]*\"/<PackageReference Include=\"BlazorStatic\" Version=\"${{ github.event.inputs.new_version_blazorstatic }}\"/" "$csproj_file"
# Verify the update
if grep -q "<PackageReference Include=\"BlazorStatic\" Version=\"${{ github.event.inputs.new_version_blazorstatic }}\"" "$csproj_file"; then
echo "BlazorStatic version updated to ${{ github.event.inputs.new_version_blazorstatic }} in $csproj_file."
else
echo "Error: Failed to update the BlazorStatic version in $csproj_file."
exit 1
fi
done
# Step 2: Read the current version from the BlazorStatic.Templates.csproj file
- name: Extract current version
id: extract-version
run: |
current_version=$(grep -oP '(?<=<PackageVersion>).*?(?=</PackageVersion>)' ./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/<PackageVersion>${{ env.current_version }}<\/PackageVersion>/<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 }}
10 changes: 5 additions & 5 deletions BlazorStatic.Templates.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Authors>tesar.tech</Authors>
<Description>Templates for creating project for static websites using BlazorStatic.</Description>
<PackageTags>dotnet-new;templates;blazor;static;website;generator;BlazorStatic</PackageTags>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>

<!-- Include content in the NuGet package -->
<IncludeContentInPack>true</IncludeContentInPack>
Expand All @@ -18,21 +18,21 @@
<NoDefaultExcludes>true</NoDefaultExcludes>

<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression>
<RepositoryUrl>https://github.com/tesar-tech/BlazorStatic/</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/BlazorStatic/BlazorStatic/</RepositoryUrl>


</PropertyGroup>

<ItemGroup>
<!-- Include all template files, excluding build folders -->
<Content Include="templates\**\*" Exclude="templates\**\bin\**;templates\**\obj\**" />

<!-- Remove any files from compilation, as these are templates -->
<Compile Remove="**\*" />
<None Include="README.md" Pack="true" PackagePath="\" />



</ItemGroup>
</Project>
8 changes: 4 additions & 4 deletions pack_and_test.ps1
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"symbolInfo": {
"ExcludeDefaultPosts": {
"longName": "exclude-default-posts",
"shortName": "e"
"shortName": "e",
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
{
"condition": "true",
"exclude": [
"./BlazorStaticMinimalBlog/.git",
"./.git",
".git"
]
}
],
"source": "./BlazorStaticMinimalBlog"
"source": "./"
}
],
"symbols": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BlazorStatic" Version="1.0.0-beta.13"/>
<PackageReference Include="BlazorStatic" Version="1.0.0-beta.14"/>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<div class="flex flex-wrap">
@foreach(var tag in post.FrontMatter.Tags)
{
<a class="text-primary-500 hover:text-primary-400 mr-3 text-sm font-medium uppercase" href="@blazorStaticContentService.Options.TagsPageUrl/@tag">@tag</a>
<a class="text-primary-500 hover:text-primary-400 mr-3 text-sm font-medium uppercase" href="@blazorStaticContentService.Options.Tags.TagsPageUrl/@tag">@tag</a>
}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
<div class="flex flex-wrap justify-evenly gap-1">
@{
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)
{
<a class="text-primary-500 hover:text-primary-400 mr-3 text-sm font-medium uppercase" href="@blazorStaticContentService.Options.TagsPageUrl/@WebUtility.HtmlEncode(tag.Tag)">@tag.Tag (@tag.Count)</a>
<a class="text-primary-500 hover:text-primary-400 mr-3 text-sm font-medium uppercase" href="@($"{blazorStaticContentService.Options.Tags.TagsPageUrl}/{tagGroup.Tag.EncodedName}")">@tagGroup.Tag.Name</a>
}
}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<div class="flex flex-wrap">
@foreach(var tag in post.FrontMatter.Tags)
{
<a class="text-primary-500 hover:text-primary-400 mr-3 text-sm font-medium uppercase" href="@blazorStaticContentService.Options.TagsPageUrl/@tag">@tag</a>
<a class="text-primary-500 hover:text-primary-400 mr-3 text-sm font-medium uppercase" href="@blazorStaticContentService.Options.Tags.TagsPageUrl/@tag">@tag</a>
}
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions templates/BlazorStaticMinimalBlogTemplate/Program.cs
Original file line number Diff line number Diff line change
@@ -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);
Expand Down

0 comments on commit 805448e

Please sign in to comment.