Skip to content

update workflow

update workflow #29

Workflow file for this run

name: Deploy public
on:
push:
branches: ["main"]
workflow_dispatch:
inputs:
hugoVersion:
description: 'Hugo version to use'
required: false
default: '0.128.0'
type: string
baseUrl:
description: 'Site base URL'
required: false
type: string
environment:
description: 'Hugo environment'
required: false
default: 'production'
type: string
permissions:
contents: write
actions: read
jobs:
build:
runs-on: ubuntu-latest
env:
HUGO_VERSION: ${{ inputs.hugoVersion || '0.128.0' }}
steps:
- name: Install Hugo CLI
run: |
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb
- name: Install Dart Sass
run: sudo snap install dart-sass
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Node.js dependencies
run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"
- name: Build with Hugo
env:
HUGO_CACHEDIR: ${{ runner.temp }}/hugo_cache
HUGO_ENVIRONMENT: ${{ inputs.environment || 'production' }}
run: |
hugo --minify --gc --cleanDestinationDir --environment ${HUGO_ENVIRONMENT}
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: hugo-public
path: ./public
retention-days: 1
push_public:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: hugo-public
path: public
- name: Sync public branch
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
COMMIT_MSG=$(git log -1 --pretty=%B)
COMMIT_HASH=$(git rev-parse --short HEAD)
SOURCE_REF=$(git rev-parse --abbrev-ref HEAD)
git fetch origin public || true
git switch public 2>/dev/null || git switch --orphan public
find . -mindepth 1 -maxdepth 1 ! -name .git ! -name public -exec rm -rf {} +
cp -r public/* .
rm -rf public
git add -A
if ! git diff --staged --quiet; then
git commit -m "Update from ${SOURCE_REF} ${COMMIT_HASH}" -m "Source commit message:" -m "${COMMIT_MSG}"
git push origin public
else
echo "No changes detected"
fi