name: Build Website on: [push] jobs: build: runs-on: shell steps: - name: Checkout run: | git clone --branch ${{ github.ref_name }} ${{ github.server_url }}/${{ github.repository }}.git . - name: Prepare output directory run: | mkdir -p site/public chmod 777 site # - name: Build # run: | # mkdir -p "$PWD/.hugo-cache" # docker run --rm \ # -u "$(id -u):$(id -g)" \ # -v "$PWD/site:/src" \ # -v "$PWD/.git:/src/.git:ro" \ # -v "$PWD/.hugo-cache:/cache" \ # -e GOPATH=/cache \ # -w /src \ # forgejo.jmopines.com/jm/hugo-git:latest \ # --minify --destination "public" --baseURL "/" # - name: Deploy # run: | # echo "${{ secrets.FORGEJO_SSH }}" > /tmp/deploy_key # chmod 600 /tmp/deploy_key # rsync -az --delete \ # --exclude 'resume/' \ # -e "ssh -i /tmp/deploy_key -o StrictHostKeyChecking=no" \ # site/public/. \ # ${{ vars.JMOPINES_USER }}@${{ vars.JMOPINES_IP }}:/var/www/jmopines/ # rm /tmp/deploy_key - name: Build run: | set -ex # 1. Create a permanent cache folder on the VM so it doesn't redownload every time mkdir -p /home/forgejo/hugo_cache chmod 777 /home/forgejo/hugo_cache # 2. Run with a 60-second timeout. If it takes longer, something is wrong. # We add --network host to ensure the container can see the internet/local gitea timeout 60s docker run --rm \ --entrypoint /bin/sh \ --network host \ -v "$PWD:/src" \ -v "/home/forgejo/hugo_cache:/cache" \ -e HUGO_CACHEDIR=/cache \ -e GOPATH=/cache \ -w /src/site \ forgejo.jmopines.com/jm/hugo-git:latest \ -c "git config --global --add safe.directory /src && hugo --minify --enableGitInfo --noTimes --destination public" - name: Deploy run: | set -ex # Verify files exist ls -la site/public/ # Setup SSH echo "${{ secrets.FORGEJO_SSH }}" > /tmp/deploy_key chmod 600 /tmp/deploy_key # Sync with verbose output so we see what is happening rsync -avz --delete \ --exclude 'resume/' \ -e "ssh -i /tmp/deploy_key -o StrictHostKeyChecking=no" \ site/public/ \ ${{ vars.JMOPINES_USER }}@${{ vars.JMOPINES_IP }}:/var/www/jmopines/ rm /tmp/deploy_key