forked from Sandra/Sandra.Snow
-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (79 loc) · 3.03 KB
/
publish-website.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
name: Publish Website
# 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