Roger Gonzalez cdb360dc3e
All checks were successful
Hugo Build and Deploy / Build Hugo Site (pull_request) Successful in 20s
Hugo Build and Deploy / Deploy to Server (pull_request) Has been skipped
Add GitHub Actions deployment workflow
- Adds a workflow to build and deploy the Hugo site.
- Uses klakegg/hugo:0.111.3-ext-alpine-ci for the build environment.
- Checks out the code in both build and deploy jobs.
- Deploys to the server using SSH keys and secrets.
- Only deploys on pushes to the master branch.
- Uses `git stash` and `git pull --force` for deployment.
2025-05-14 20:34:07 -03:00

50 lines
1.2 KiB
YAML

name: Hugo Build and Deploy
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
test_build:
name: Build Hugo Site
runs-on: ubuntu-latest
container:
image: klakegg/hugo:0.111.3-ext-alpine-ci
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Check Hugo Version and Build
run: |
hugo version
hugo --minify
deploy:
name: Deploy to Server
runs-on: ubuntu-latest
needs: test_build
if: github.ref == 'refs/heads/master'
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup SSH and Deploy
run: |
eval "$(ssh-agent -s)"
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
chmod 700 ~/.ssh
ssh-keyscan "$SSH_HOST" >> ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
ssh -p "$SSH_PORT" "$SSH_USER@$SSH_HOST" 'cd repo && git stash && git pull --force origin master && ./build.sh'
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_PORT: ${{ secrets.SSH_PORT }}