check vars before run #12
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish Website | ||
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 }} | ||
jobs: | ||
publish: | ||
runs-on: windows-latest | ||
steps: | ||
- name: Check WEBSITE_REPO var | ||
if: ${{ !env.IS_WEBSITE_REPO_SET }} | ||
shell: pwsh | ||
run: | | ||
"::warning file=$env.YAML_PATH::Mandatory repo variable WEBSITE_REPO is not set." | ||
- name: Check WEBSITE_PAT secret | ||
if: ${{ secrets.WEBSITE_PAT == null }} | ||
Check failure on line 28 in .github/workflows/publish-website.yml GitHub Actions / Publish WebsiteInvalid workflow file
|
||
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 }} | ||
uses: actions/checkout@v3 | ||
with: | ||
sparse-checkout: SnowSite | ||
path: doc | ||
- name: Checkout Website | ||
if: ${{ env.IS_WEBSITE_REPO_SET }} | ||
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 }} | ||
uses: dawidd6/action-download-artifact@v2 | ||
with: | ||
workflow: build-snow.yml | ||
- name: run Snow | ||
if: ${{ env.IS_WEBSITE_REPO_SET }} | ||
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 |