f49cb77fa4
ssh-keyscan and rsync's -e ssh both need the port passed via -p rather than embedded in the hostname; parse DEPLOY_HOST accordingly, defaulting to 22 when no port is given.
67 lines
2.4 KiB
YAML
67 lines
2.4 KiB
YAML
name: Build and deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [master]
|
|
workflow_dispatch: {}
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: self-hosted
|
|
container: python:3.12-slim
|
|
steps:
|
|
- name: Install system dependencies
|
|
run: |
|
|
apt-get update
|
|
apt-get install -y --no-install-recommends git rsync openssh-client nodejs
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
submodules: false
|
|
|
|
- name: Set up SSH key
|
|
# Same key used both as the theme repo's deploy key (Gitea) and for
|
|
# the webserver login (below) — one secret, two authorized_keys entries.
|
|
# DEPLOY_HOST may be "fqdn" or "fqdn:port" (non-standard SSH port).
|
|
env:
|
|
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
|
|
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
printf '%s\n' "$DEPLOY_SSH_KEY" > ~/.ssh/deploy_key
|
|
chmod 600 ~/.ssh/deploy_key
|
|
DEPLOY_HOSTNAME="${DEPLOY_HOST%%:*}"
|
|
DEPLOY_PORT="${DEPLOY_HOST#*:}"
|
|
[ "$DEPLOY_PORT" = "$DEPLOY_HOST" ] && DEPLOY_PORT=22
|
|
ssh-keyscan -H git.haemka.in >> ~/.ssh/known_hosts 2>/dev/null
|
|
ssh-keyscan -H -p "$DEPLOY_PORT" "$DEPLOY_HOSTNAME" >> ~/.ssh/known_hosts 2>/dev/null
|
|
|
|
- name: Fetch theme submodule
|
|
run: |
|
|
# Override the submodule's tracked HTTPS URL for this checkout only,
|
|
# so it's fetched over SSH with the deploy key instead of needing a
|
|
# token with access to both repos.
|
|
git config submodule.themes/latex.url git@git.haemka.in:hmk/pelican-latex.git
|
|
GIT_SSH_COMMAND="ssh -i ~/.ssh/deploy_key -o StrictHostKeyChecking=yes" \
|
|
git submodule update --init --recursive
|
|
|
|
- name: Install Python dependencies
|
|
run: pip install --no-cache-dir -r requirements.txt
|
|
|
|
- name: Build site
|
|
run: pelican -s publishconf.py
|
|
|
|
- name: Deploy via rsync
|
|
env:
|
|
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
|
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
|
|
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
|
|
run: |
|
|
DEPLOY_HOSTNAME="${DEPLOY_HOST%%:*}"
|
|
DEPLOY_PORT="${DEPLOY_HOST#*:}"
|
|
[ "$DEPLOY_PORT" = "$DEPLOY_HOST" ] && DEPLOY_PORT=22
|
|
rsync -avz --delete \
|
|
-e "ssh -i ~/.ssh/deploy_key -p $DEPLOY_PORT -o StrictHostKeyChecking=yes" \
|
|
output/ "${DEPLOY_USER}@${DEPLOY_HOSTNAME}:${DEPLOY_PATH}"
|