test deploy.yml

This commit is contained in:
Filippo Ferrari 2024-02-17 12:20:10 +01:00
parent c696c32b6d
commit 6fb6d0ff85

View file

@ -1,50 +1,57 @@
name: Deploy to Home Server name: Publish Blog
on: on: push
push:
branches: [master]
pull_request:
branches: [master]
jobs: jobs:
build: deploy:
runs-on: ubuntu-latest
permissions: runs-on: ubuntu-22.04
contents: write
steps: steps:
- uses: actions/checkout@v3
- name: Cache Hugo resources # CHEKCOUT REPOSITORY
uses: actions/cache@v3
env:
cache-name: cache-hugo-resources
with:
path: resources
key: ${{ env.cache-name }}
- uses: actions/setup-go@v4 - name: Git checkout
with: uses: actions/checkout@v3
go-version: "^1.17.0"
- run: go version # SETUP HUGO
# Read environemnt variable for subsequent actions.
# See: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
- name: Read .env
run: |
. ./.env
echo "HUGO_VERSION=${HUGO_VERSION}" >> $GITHUB_ENV
- name: Setup Hugo - name: Setup Hugo
uses: peaceiris/actions-hugo@v2 uses: peaceiris/actions-hugo@v2
with: with:
hugo-version: "latest" hugo-version: '${{ env.HUGO_VERSION }}'
extended: true extended: true
- name: Build - name: Cache Hugo
run: hugo --minify --gc uses: actions/cache@v3
- name: Deploy 🚀
uses: easingthemes/ssh-deploy@v2
with: with:
REMOTE_HOST: ${{ secrets.REMOTE_HOST }} path: /tmp/hugo_cache
REMOTE_USER: ${{ secrets.REMOTE_USER }} key: ${{ runner.os }}-hugomod-${{ hashFiles('**/go.sum') }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} restore-keys: |
local: ./public ${{ runner.os }}-hugomod-
remote: /var/www/html/
- name: Build Blog
env:
TZ: 'Europe/Rome'
run: hugo --minify
# DEPLOY TO REMOTE SERVER
- name: Install SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.PRIVATE_SSH_KEY }}
known_hosts: 'placeholder'
- name: Adding Known Hosts
run: ssh-keyscan -H ${{ secrets.DEPLOY_HOST_IP }} >> ~/.ssh/known_hosts
- name: Deploy with rsync
run: rsync -avz --delete ./public/ ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST_IP }}:${{ secrets.DEPLOY_PATH }}