Skip to content

Commit 72b097d

Browse files
Merge pull request #142 from Pxtl/updates
modernize Sandra.snow somewhat
2 parents c753204 + 228b689 commit 72b097d

30 files changed

Lines changed: 387 additions & 182 deletions

.github/workflows/build-snow.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Build Snow
2+
# compile Sandra.Snow binary in release mode and publish as artifact "Snow"
3+
4+
on:
5+
push:
6+
branches: [ "master" ]
7+
paths:
8+
- 'src/**'
9+
- '.github/workflows/build-snow.yml'
10+
workflow_dispatch:
11+
12+
jobs:
13+
build:
14+
15+
runs-on: windows-latest
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: Setup NuGet
20+
uses: NuGet/setup-nuget@v1.0.5
21+
- name: setup-msbuild
22+
uses: microsoft/setup-msbuild@v1.1
23+
- name: Restore Packages
24+
run: nuget restore src/Sandra.Snow.sln
25+
- name: Build solution
26+
run: msbuild src/Sandra.Snow.sln -t:rebuild -property:Configuration=Release
27+
- name: Upload a Build Artifact
28+
uses: actions/upload-artifact@v3.1.3
29+
with:
30+
# Artifact name
31+
name: Snow
32+
# A file, directory or wildcard pattern that describes what to upload
33+
path: src/Snow/bin/Release
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Publish Website
2+
# publish SnowSite to the repo set in vars.WEBSITE_REPO, using the pat defined in secrets.WEBSITE_PAT
3+
# note that this action overrides the output paths set in the snow config file
4+
5+
on:
6+
push:
7+
paths:
8+
- 'SnowSite/**'
9+
- '.github/workflows/publish-website.yml'
10+
workflow_dispatch:
11+
workflow_run:
12+
workflows: ["Build Snow"]
13+
types:
14+
- completed
15+
16+
env:
17+
YAML_PATH: .github/workflows/publish-website.yml
18+
IS_WEBSITE_REPO_SET: ${{ vars.WEBSITE_REPO != null }}
19+
IS_WEBSITE_PAT_SET: ${{ secrets.WEBSITE_PAT != null }}
20+
21+
jobs:
22+
publish:
23+
runs-on: windows-latest
24+
steps:
25+
- name: Check WEBSITE_REPO var
26+
if: ${{ env.IS_WEBSITE_REPO_SET == 'false' }}
27+
shell: pwsh
28+
run: |
29+
"::warning file=$env:YAML_PATH::Mandatory repo variable WEBSITE_REPO is not set."
30+
31+
- name: Check WEBSITE_PAT secret
32+
if: ${{ env.IS_WEBSITE_REPO_SET == 'true' && env.IS_WEBSITE_PAT_SET == 'false' }}
33+
shell: pwsh
34+
run: |
35+
"::error file=$env:YAML_PATH::Mandatory repo secret WEBSITE_PAT is not set."
36+
37+
- name: Checkout SnowSite
38+
if: ${{ env.IS_WEBSITE_REPO_SET == 'true' }}
39+
uses: actions/checkout@v3
40+
with:
41+
sparse-checkout: SnowSite
42+
path: doc
43+
44+
- name: Checkout Website
45+
if: ${{ env.IS_WEBSITE_REPO_SET == 'true' }}
46+
uses: actions/checkout@v3
47+
with:
48+
repository: ${{ vars.WEBSITE_REPO }}
49+
path: website
50+
token: ${{ secrets.WEBSITE_PAT }}
51+
52+
- name: Download Snow artifact
53+
if: ${{ env.IS_WEBSITE_REPO_SET == 'true' }}
54+
uses: dawidd6/action-download-artifact@v2
55+
with:
56+
workflow: build-snow.yml
57+
58+
- name: run Snow
59+
if: ${{ env.IS_WEBSITE_REPO_SET == 'true' }}
60+
shell: pwsh
61+
run: |
62+
$ErrorActionPreference = 'Stop'
63+
$blogDir = (mkdir ".\website" -force).FullName
64+
$docDir = ".\doc\SnowSite"
65+
66+
"Configuring git..."
67+
68+
pushd $docDir
69+
$lastMessage = git log -1 --pretty=%B | Select-Object -First 1
70+
$lastUserName = git log -1 --pretty=format:'%an' | Select-Object -First 1
71+
$lastUserEamil = git log -1 --pretty=format:'%ae' | Select-Object -First 1
72+
73+
git config --global user.name "github actions bot (on behalf of $lastUserName)"
74+
git config --global user.email $lastUserEamil
75+
git config --global core.autocrlf false
76+
popd
77+
78+
"Overriding output dirs to $blogDir"
79+
$configPath = "$docDir\Snow\Snow.config.json"
80+
$config = Get-Content $configPath | ConvertFrom-Json
81+
$config.postsOutput = $blogDir
82+
$config.pagesOutput = $blogDir
83+
$config | ConvertTo-Json | Out-File $configPath
84+
85+
"Running Snow..."
86+
& Snow\Snow.exe "config=$configPath"
87+
88+
Write-Output "Updating $blogdir..."
89+
cd $blogdir
90+
Get-Location #DEBUG
91+
92+
git add .
93+
git commit -m "Publish: $lastMessage"
94+
git push

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ packages/
2727
SnowSite/Snow/Images/original-images/
2828
SnowSite/Snow/_ignore/
2929
*.log
30-
src/Barbato/Snow/
30+
src/Barbato/Snow/
31+
.vs

SnowSite/Snow/_pages/.gitkeep

6 Bytes
Binary file not shown.
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"pages": "_pages",
88
"layouts": "_layouts",
99
"theme": "default",
10-
"output": "../Website",
10+
"postsOutput": "../Website",
11+
"pagesOutput": "../Website",
1112
"urlFormat": "yyyy/MM/slug",
1213
"copyDirectories": [
1314
"images",
@@ -24,7 +25,8 @@
2425
},{
2526
"file": "categories.cshtml => category"
2627
},{
27-
"file": "archive.cshtml"
28+
"file": "archive.cshtml",
29+
"title": "Archive"
2830
},{
2931
"file": "about.cshtml"
3032
},{

SnowSite/Snow/themes/default/_layouts/default.cshtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
@using System.Collections.Generic
33
@{
44
var keywords = String.Join(",", Model.Keywords);
5+
var title = String.Join("", Model.HeaderTitleChain);
56
}
67
<!DOCTYPE html>
78
<html dir="ltr" lang="en-US">
@@ -10,7 +11,7 @@
1011
<meta name="viewport" content="width=device-width" />
1112
<meta http-equiv="last-modified" content="@Model.GeneratedDate" />
1213
<meta name="keywords" content="@keywords" />
13-
<title>philliphaydon.com</title>
14+
<title>@title</title>
1415
<link rel="stylesheet" type="text/css" href="/stylesheets/style.css" />
1516
@Html.CanonicalUrl()
1617
</head>

debug.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
& src\Snow\bin\Debug\Snow config=.\SnowSite\Snow\Snow.config.json debug=true server=true

publish.ps1

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#.SYNOPSIS
2+
# Simple 1-step publish script, but has many assumptions. See description.
3+
4+
#.DESCRIPTION
5+
# This publish is a simple local convenience measure for publishing SnowSite
6+
# from localhost to your gitrepo, assuming you've customized SnowSite to become
7+
# your site.
8+
#
9+
# It also assumes you've already compiled Sandra.snow in "debug" mode.
10+
#
11+
# It also assumes that your "config" is set to output directly into your target
12+
# static site repo.
13+
#
14+
# If any of these assumptions are false, you may need to use a different publish
15+
# script, or customize this one.
16+
17+
param (
18+
# git commit message for both Sandra.Snow repo and output repo.
19+
[Parameter(mandatory)]
20+
[string] $commitMessage,
21+
22+
# path to the config file. Must be in the site directory. Defaults to SnowSite\Snow\Snow.config
23+
[Parameter()]
24+
[IO.FileInfo] $configPath = $null
25+
)
26+
27+
Push-Location $PSScriptRoot
28+
29+
# defaulting.
30+
if (-not $configPath) {
31+
$configPath = [IO.FileInfo](Resolve-Path ".\SnowSite\Snow\Snow.config.json").Path
32+
}
33+
$configDirPath = Split-Path $configPath -Parent
34+
$outputPath = Resolve-Path (Join-Path $configDirPath $config.postsOutput)
35+
36+
& src\Snow\bin\Debug\Snow config=$configPath
37+
38+
#region commits
39+
git add .
40+
git commit -m $message
41+
git push
42+
43+
Push-Location $outputPath
44+
git add .
45+
git commit -m $message
46+
git push
47+
Pop-Location
48+
#endregion commits
49+
50+
Pop-Location

src/Barbato.Tests/Barbato.Tests.csproj

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -9,10 +9,11 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>Barbato.Tests</RootNamespace>
1111
<AssemblyName>Barbato.Tests</AssemblyName>
12-
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
1515
<RestorePackages>true</RestorePackages>
16+
<TargetFrameworkProfile />
1617
</PropertyGroup>
1718
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1819
<DebugSymbols>true</DebugSymbols>
@@ -22,6 +23,7 @@
2223
<DefineConstants>DEBUG;TRACE</DefineConstants>
2324
<ErrorReport>prompt</ErrorReport>
2425
<WarningLevel>4</WarningLevel>
26+
<Prefer32Bit>false</Prefer32Bit>
2527
</PropertyGroup>
2628
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2729
<DebugType>pdbonly</DebugType>
@@ -30,15 +32,15 @@
3032
<DefineConstants>TRACE</DefineConstants>
3133
<ErrorReport>prompt</ErrorReport>
3234
<WarningLevel>4</WarningLevel>
35+
<Prefer32Bit>false</Prefer32Bit>
3336
</PropertyGroup>
3437
<ItemGroup>
3538
<Reference Include="FakeItEasy, Version=1.22.0.0, Culture=neutral, PublicKeyToken=eff28e2146d5fd2c, processorArchitecture=MSIL">
3639
<SpecificVersion>False</SpecificVersion>
3740
<HintPath>..\packages\FakeItEasy.1.22.0\lib\net40\FakeItEasy.dll</HintPath>
3841
</Reference>
39-
<Reference Include="Nancy, Version=0.23.2.0, Culture=neutral, processorArchitecture=MSIL">
40-
<SpecificVersion>False</SpecificVersion>
41-
<HintPath>..\packages\Nancy.0.23.2\lib\net40\Nancy.dll</HintPath>
42+
<Reference Include="Nancy, Version=1.4.5.0, Culture=neutral, processorArchitecture=MSIL">
43+
<HintPath>..\packages\Nancy.1.4.5\lib\net40\Nancy.dll</HintPath>
4244
</Reference>
4345
<Reference Include="System" />
4446
<Reference Include="System.Core" />
@@ -57,6 +59,7 @@
5759
<Compile Include="Properties\AssemblyInfo.cs" />
5860
</ItemGroup>
5961
<ItemGroup>
62+
<None Include="app.config" />
6063
<None Include="packages.config" />
6164
</ItemGroup>
6265
<ItemGroup>

src/Barbato.Tests/app.config

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<runtime>
4+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
5+
<dependentAssembly>
6+
<assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
7+
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
8+
</dependentAssembly>
9+
</assemblyBinding>
10+
</runtime>
11+
</configuration>

0 commit comments

Comments
 (0)