Files
hugoblog/.gitea/workflows/deploy.yml
2025-06-13 15:41:22 +02:00

78 lines
2.3 KiB
YAML

name: Build and Deploy
on:
push:
branches: [master]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0
# Cache Hugo dependencies and modules
- name: Cache Hugo dependencies
uses: actions/cache@v3
with:
path: /tmp/hugo_cache
key: ${{ runner.os }}-hugo-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-hugo-
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: "latest"
extended: true
# Cache the Hugo build output
- name: Cache Hugo build
uses: actions/cache@v3
with:
path: |
public
resources/_gen
key: ${{ runner.os }}-hugo-build-${{ hashFiles('content/**', 'layouts/**', 'static/**', 'themes/**', 'config/**') }}
restore-keys: |
${{ runner.os }}-hugo-build-
- name: Build
run: hugo --minify --buildFuture
# Cache apt packages
- name: Cache apt packages
uses: actions/cache@v3
with:
path: /var/cache/apt/archives
key: ${{ runner.os }}-apt-${{ hashFiles('**/deploy.yml') }}
restore-keys: |
${{ runner.os }}-apt-
- name: Install rsync
run: sudo apt-get update && sudo apt-get install -y rsync
- name: Install SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
known_hosts: unnecessary
if_key_exists: replace
- name: Adding Known Hosts
run: ssh-keyscan -p ${{ secrets.SERVER_PORT }} -H ${{ secrets.SERVER_HOST }} >> ~/.ssh/known_hosts
- name: Deploy with rsync
run: |
rsync -avz --delete -e "ssh -p ${{ secrets.SERVER_PORT }}" \
./public ./botPolicy.yaml ./nginx.conf ./docker-compose.prod.yml \
${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}:${{ secrets.DEPLOY_PATH }}
- name: Restart Docker container
run: |
ssh -p ${{ secrets.SERVER_PORT }} ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} \
"cd ${{ secrets.DEPLOY_PATH }} && sudo docker compose -f docker-compose.prod.yml up -d --build"