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
0 commit comments