From cdb360dc3e45dc004733df3d3ae9afdce7ac0a63 Mon Sep 17 00:00:00 2001 From: Roger Gonzalez Date: Wed, 14 May 2025 20:34:07 -0300 Subject: [PATCH] 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. --- .gitea/workflows/deploy.yml | 49 +++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .gitea/workflows/deploy.yml diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 0000000..18cf6d3 --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -0,0 +1,49 @@ +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 }}