Skip to content

Commit

Permalink
Merge pull request #142 from Pxtl/updates
Browse files Browse the repository at this point in the history
modernize Sandra.snow somewhat
  • Loading branch information
phillip-haydon authored Dec 4, 2023
2 parents c753204 + 228b689 commit 72b097d
Show file tree
Hide file tree
Showing 30 changed files with 387 additions and 182 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/build-snow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Build Snow
# compile Sandra.Snow binary in release mode and publish as artifact "Snow"

on:
push:
branches: [ "master" ]
paths:
- 'src/**'
- '.github/workflows/build-snow.yml'
workflow_dispatch:

jobs:
build:

runs-on: windows-latest

steps:
- uses: actions/checkout@v3
- name: Setup NuGet
uses: NuGet/[email protected]
- name: setup-msbuild
uses: microsoft/[email protected]
- name: Restore Packages
run: nuget restore src/Sandra.Snow.sln
- name: Build solution
run: msbuild src/Sandra.Snow.sln -t:rebuild -property:Configuration=Release
- name: Upload a Build Artifact
uses: actions/[email protected]
with:
# Artifact name
name: Snow
# A file, directory or wildcard pattern that describes what to upload
path: src/Snow/bin/Release
94 changes: 94 additions & 0 deletions .github/workflows/publish-website.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Publish Website

Check warning on line 1 in .github/workflows/publish-website.yml

View workflow job for this annotation

GitHub Actions / publish

Mandatory repo variable WEBSITE_REPO is not set.

Check warning on line 1 in .github/workflows/publish-website.yml

View workflow job for this annotation

GitHub Actions / publish

Mandatory repo variable WEBSITE_REPO is not set.
# publish SnowSite to the repo set in vars.WEBSITE_REPO, using the pat defined in secrets.WEBSITE_PAT
# note that this action overrides the output paths set in the snow config file

on:
push:
paths:
- 'SnowSite/**'
- '.github/workflows/publish-website.yml'
workflow_dispatch:
workflow_run:
workflows: ["Build Snow"]
types:
- completed

env:
YAML_PATH: .github/workflows/publish-website.yml
IS_WEBSITE_REPO_SET: ${{ vars.WEBSITE_REPO != null }}
IS_WEBSITE_PAT_SET: ${{ secrets.WEBSITE_PAT != null }}

jobs:
publish:
runs-on: windows-latest
steps:
- name: Check WEBSITE_REPO var
if: ${{ env.IS_WEBSITE_REPO_SET == 'false' }}
shell: pwsh
run: |
"::warning file=$env:YAML_PATH::Mandatory repo variable WEBSITE_REPO is not set."
- name: Check WEBSITE_PAT secret
if: ${{ env.IS_WEBSITE_REPO_SET == 'true' && env.IS_WEBSITE_PAT_SET == 'false' }}
shell: pwsh
run: |
"::error file=$env:YAML_PATH::Mandatory repo secret WEBSITE_PAT is not set."
- name: Checkout SnowSite
if: ${{ env.IS_WEBSITE_REPO_SET == 'true' }}
uses: actions/checkout@v3
with:
sparse-checkout: SnowSite
path: doc

- name: Checkout Website
if: ${{ env.IS_WEBSITE_REPO_SET == 'true' }}
uses: actions/checkout@v3
with:
repository: ${{ vars.WEBSITE_REPO }}
path: website
token: ${{ secrets.WEBSITE_PAT }}

- name: Download Snow artifact
if: ${{ env.IS_WEBSITE_REPO_SET == 'true' }}
uses: dawidd6/action-download-artifact@v2
with:
workflow: build-snow.yml

- name: run Snow
if: ${{ env.IS_WEBSITE_REPO_SET == 'true' }}
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$blogDir = (mkdir ".\website" -force).FullName
$docDir = ".\doc\SnowSite"
"Configuring git..."
pushd $docDir
$lastMessage = git log -1 --pretty=%B | Select-Object -First 1
$lastUserName = git log -1 --pretty=format:'%an' | Select-Object -First 1
$lastUserEamil = git log -1 --pretty=format:'%ae' | Select-Object -First 1
git config --global user.name "github actions bot (on behalf of $lastUserName)"
git config --global user.email $lastUserEamil
git config --global core.autocrlf false
popd
"Overriding output dirs to $blogDir"
$configPath = "$docDir\Snow\Snow.config.json"
$config = Get-Content $configPath | ConvertFrom-Json
$config.postsOutput = $blogDir
$config.pagesOutput = $blogDir
$config | ConvertTo-Json | Out-File $configPath
"Running Snow..."
& Snow\Snow.exe "config=$configPath"
Write-Output "Updating $blogdir..."
cd $blogdir
Get-Location #DEBUG
git add .
git commit -m "Publish: $lastMessage"
git push
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ packages/
SnowSite/Snow/Images/original-images/
SnowSite/Snow/_ignore/
*.log
src/Barbato/Snow/
src/Barbato/Snow/
.vs
Binary file added SnowSite/Snow/_pages/.gitkeep
Binary file not shown.
6 changes: 4 additions & 2 deletions SnowSite/Snow/snow.config → SnowSite/Snow/snow.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"pages": "_pages",
"layouts": "_layouts",
"theme": "default",
"output": "../Website",
"postsOutput": "../Website",
"pagesOutput": "../Website",
"urlFormat": "yyyy/MM/slug",
"copyDirectories": [
"images",
Expand All @@ -24,7 +25,8 @@
},{
"file": "categories.cshtml => category"
},{
"file": "archive.cshtml"
"file": "archive.cshtml",
"title": "Archive"
},{
"file": "about.cshtml"
},{
Expand Down
3 changes: 2 additions & 1 deletion SnowSite/Snow/themes/default/_layouts/default.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@using System.Collections.Generic
@{
var keywords = String.Join(",", Model.Keywords);
var title = String.Join("", Model.HeaderTitleChain);
}
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
Expand All @@ -10,7 +11,7 @@
<meta name="viewport" content="width=device-width" />
<meta http-equiv="last-modified" content="@Model.GeneratedDate" />
<meta name="keywords" content="@keywords" />
<title>philliphaydon.com</title>
<title>@title</title>
<link rel="stylesheet" type="text/css" href="/stylesheets/style.css" />
@Html.CanonicalUrl()
</head>
Expand Down
1 change: 1 addition & 0 deletions debug.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
& src\Snow\bin\Debug\Snow config=.\SnowSite\Snow\Snow.config.json debug=true server=true
50 changes: 50 additions & 0 deletions publish.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#.SYNOPSIS
# Simple 1-step publish script, but has many assumptions. See description.

#.DESCRIPTION
# This publish is a simple local convenience measure for publishing SnowSite
# from localhost to your gitrepo, assuming you've customized SnowSite to become
# your site.
#
# It also assumes you've already compiled Sandra.snow in "debug" mode.
#
# It also assumes that your "config" is set to output directly into your target
# static site repo.
#
# If any of these assumptions are false, you may need to use a different publish
# script, or customize this one.

param (
# git commit message for both Sandra.Snow repo and output repo.
[Parameter(mandatory)]
[string] $commitMessage,

# path to the config file. Must be in the site directory. Defaults to SnowSite\Snow\Snow.config
[Parameter()]
[IO.FileInfo] $configPath = $null
)

Push-Location $PSScriptRoot

# defaulting.
if (-not $configPath) {
$configPath = [IO.FileInfo](Resolve-Path ".\SnowSite\Snow\Snow.config.json").Path
}
$configDirPath = Split-Path $configPath -Parent
$outputPath = Resolve-Path (Join-Path $configDirPath $config.postsOutput)

& src\Snow\bin\Debug\Snow config=$configPath

#region commits
git add .
git commit -m $message
git push

Push-Location $outputPath
git add .
git commit -m $message
git push
Pop-Location
#endregion commits

Pop-Location
13 changes: 8 additions & 5 deletions src/Barbato.Tests/Barbato.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand All @@ -9,10 +9,11 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Barbato.Tests</RootNamespace>
<AssemblyName>Barbato.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -22,6 +23,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -30,15 +32,15 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="FakeItEasy, Version=1.22.0.0, Culture=neutral, PublicKeyToken=eff28e2146d5fd2c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\FakeItEasy.1.22.0\lib\net40\FakeItEasy.dll</HintPath>
</Reference>
<Reference Include="Nancy, Version=0.23.2.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Nancy.0.23.2\lib\net40\Nancy.dll</HintPath>
<Reference Include="Nancy, Version=1.4.5.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Nancy.1.4.5\lib\net40\Nancy.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -57,6 +59,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
Expand Down
11 changes: 11 additions & 0 deletions src/Barbato.Tests/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
2 changes: 1 addition & 1 deletion src/Barbato.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FakeItEasy" version="1.22.0" targetFramework="net40" />
<package id="Nancy" version="0.23.2" targetFramework="net40" />
<package id="Nancy" version="1.4.5" targetFramework="net48" />
<package id="xunit" version="1.9.2" targetFramework="net40" />
</packages>
Loading

0 comments on commit 72b097d

Please sign in to comment.