Like any software engineer, I strive to be two things: cheap and lazy. That’s why I manage this site (and several others) through free hosting services such as surge.sh and a static site generator like Hugo. I’ve been using the command line to deploy changes, but recently I decided to use Github Workflows to deploy changes with a press of a button.
Here is my workflow for publishing to surge
with Github Workflows. It’s an amalgamation of several other workflows, but it does the job well.
# This is a basic workflow that is manually triggered
name: Publish to Surge
# Controls when the action will run. Workflow runs when manually triggered using the UI
# or API.
on:
workflow_dispatch:
inputs:
git-ref:
description: Git SHA-1 Ref (Optional)
required: false
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
deploy:
# The type of runner that the job will run on
runs-on: ubuntu-latest
steps:
- name: Clone Repository (Latest)
uses: actions/[email protected]
if: github.event.inputs.git-ref == ''
- name: Clone Repository (Custom Ref)
uses: actions/[email protected]
if: github.event.inputs.git-ref != ''
with:
ref: ${{ github.event.inputs.git-ref }}
- name: Hugo setup
# You may pin to the exact commit or the version.
# uses: peaceiris/[email protected]
uses: peaceiris/[email protected]
with:
# The Hugo version to download (if necessary) and use. Example: 0.58.2
hugo-version: latest
# Download (if necessary) and use Hugo extended version. Example: true
extended: true
- name: Generate static files
run: cd <HUGO_APP> && hugo -D
- name: Publish to surge.sh
# You may pin to the exact commit or the version.
# uses: dswistowski/[email protected]
uses: dswistowski/[email protected]
with:
# your surge.sh domain to deploy
domain: <YOUR_DOMAIN_NAME>
# surge.sh login
login: <YOUR_EMAIL>
# surge.sh token, generate it with `surge token` command
token: <TOKEN>
# your project path
project: <PATH_TO_YOUR_PROJECT>