From bafe51c27b31d9bcce9f578864b480a46710d8d8 Mon Sep 17 00:00:00 2001 From: Roger Gonzalez Date: Thu, 15 May 2025 20:51:26 -0300 Subject: [PATCH] Remove mirroring and update website deployment - Removes the GitLab mirroring workflow. - Replaces the existing website deployment workflow with a new Gitea Actions workflow. - The new workflow uses SSH to deploy to a remote server. - Adds a `build.sh` script to convert images to WebP format. - The deployment workflow now clears Cloudflare cache. - The old workflow used an external action for Cloudflare cache clearing. --- .gitea/workflows/upload.yml | 46 ++++++++++++++++++++++++++++++++++++ .github/workflows/mirror.yml | 17 ------------- .github/workflows/upload.yml | 39 ------------------------------ build.sh | 11 +++++++++ 4 files changed, 57 insertions(+), 56 deletions(-) create mode 100644 .gitea/workflows/upload.yml delete mode 100644 .github/workflows/mirror.yml delete mode 100644 .github/workflows/upload.yml create mode 100644 build.sh diff --git a/.gitea/workflows/upload.yml b/.gitea/workflows/upload.yml new file mode 100644 index 0000000..edbd97c --- /dev/null +++ b/.gitea/workflows/upload.yml @@ -0,0 +1,46 @@ +name: Deploy Website + +on: + push: + branches: + - master + workflow_dispatch: + +jobs: + update: + name: Deploy Hugo Site + runs-on: ubuntu-latest + + steps: + - name: Set up SSH and deploy site + run: | + echo "🔐 Setting up SSH" + 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 + + echo "🚀 Running remote build" + 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_KEY }} + SSH_USER: ${{ secrets.SSH_USER }} + SSH_HOST: ${{ secrets.SSH_HOST }} + SSH_PORT: ${{ secrets.SSH_PORT }} + + - name: Clear Cloudflare cache + run: | + curl -X POST "https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE/purge_cache" \ + -H "Authorization: Bearer $CLOUDFLARE_TOKEN" \ + -H "Content-Type: application/json" \ + --data '{"purge_everything":true}' + env: + CLOUDFLARE_ZONE: ${{ secrets.CLOUDFLARE_ZONE }} + CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_TOKEN }} diff --git a/.github/workflows/mirror.yml b/.github/workflows/mirror.yml deleted file mode 100644 index 57a66de..0000000 --- a/.github/workflows/mirror.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: Mirroring - -on: [push, delete] - -jobs: - to_gitlab: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - uses: pixta-dev/repository-mirroring-action@v1 - with: - target_repo_url: - git@gitlab.com:rogs/montevideo.restaurant.git - ssh_private_key: - ${{ secrets.GITLAB_SSH_PRIVATE_KEY }} diff --git a/.github/workflows/upload.yml b/.github/workflows/upload.yml deleted file mode 100644 index d064377..0000000 --- a/.github/workflows/upload.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: CI - -# Controls when the action will run. -on: - # Triggers the workflow on push to master (including merged PRs) - push: - branches: [ master ] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - update: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - - name: Update website. - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.ssh_host }} - username: ${{ secrets.ssh_user }} - key: ${{ secrets.ssh_key }} - passphrase: ${{ secrets.ssh_pass }} - port: ${{ secrets.ssh_port }} - script: | - cd repo - git stash - git pull --force origin master - rm -rf /var/www/montevideo.restaurant/* - hugo -s . -d /var/www/montevideo.restaurant/ - - name: Clear Cloudflare cache. - uses: Cyb3r-Jak3/action-cloudflare-cache@main - with: - zone: ${{ secrets.CLOUDFLARE_ZONE }} - api_token: ${{ secrets.CLOUDFLARE_TOKEN }} diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..d20d35f --- /dev/null +++ b/build.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +find ./ -type f -name '*.png' -not -path '*/.git/*' -exec sh -c 'cwebp -lossless "$1" -o "${1%.png}.webp"' _ {} \; +find ./ -type f -name '*.jpg' -not -path '*/.git/*' -exec sh -c 'cwebp -lossless "$1" -o "${1%.jpg}.webp"' _ {} \; +find ./ -type f -name '*.jpeg' -not -path '*/.git/*' -exec sh -c 'cwebp -lossless "$1" -o "${1%.jpeg}.webp"' _ {} \; + +find . -type f -not -path '*/.git/*' -exec sed -i -e 's/\.png/\.webp/g' {} \; +find . -type f -not -path '*/.git/*' -exec sed -i -e 's/\.jpg/\.webp/g' {} \; +find . -type f -not -path '*/.git/*' -exec sed -i -e 's/\.jpeg/\.webp/g' {} \; + +hugo -s . -d /var/www/montevideo.restaurant/ --minify --cacheDir $PWD/hugo-cache