Using ChatGPT I created a simple powershell script for deploying the site.

Goal

  • Take a commit message
  • Generate the static webpages
  • Commit+Publish the static webpages to the prod repo on the public directory that is a submodule
  • Goes back to the root directory (dev repo) and pushes that to origin as well.

Pro0mpting

Basic prompt as a starter…

create a simple powershell script that takes an input an adds “Hello” to it

So it works

a script that that takes a commit message, the git adds, commits and pushes the repo. Then cds into the “public” directory and does the same.

Almost there

Before running the git commit on the root directory it runs hugo -t fuji

Some minor fixes

  • Variable declaration needed to be fixed: "....$command:""....'$command':"
  • Need to commit the submodule git repo first, then to the root directory

And that’s about it

git_publish.ps1

# Function to execute Git commands
function Invoke-GitCommand {
    param (
        [Parameter(Mandatory=$true)]
        [string]$Command
    )

    $output = git $Command 2>&1
    if ($LASTEXITCODE -ne 0) {
        Write-Host "Error executing git '$Command':"
        Write-Host $output
        exit 1
    }
}

# Prompt for commit message
$commitMessage = Read-Host "Enter the commit message"

# Execute `hugo -t fuji` command
hugo -t fuji

# Change directory to "public"
Set-Location "public"

# Git commands for the "public" directory
git add -A
git commit -m $commitMessage
git push

# Change directory to "root"
Set-Location ..

# Git commands for the root directory
git add -A
git commit -m $commitMessage
git push

You run .\git_publish.ps1 and give the commit message and then it just works.