|
| 1 | +name: Deploy documentation |
| 2 | + |
| 3 | +# Builds the Docusaurus site and deploys the static output to the web server |
| 4 | +# via rsync over SSH. Replaces the cron-based build.sh on the server: this runs |
| 5 | +# only when master actually changes (plus a manual trigger), instead of every |
| 6 | +# 15 minutes. |
| 7 | +# |
| 8 | +# Required repository secrets (Settings > Secrets and variables > Actions): |
| 9 | +# DEPLOY_SSH_KEY Private SSH key (ed25519) for the deploy user. The matching |
| 10 | +# public key goes into the deploy user's ~/.ssh/authorized_keys |
| 11 | +# on the server, ideally locked to rrsync, e.g.: |
| 12 | +# command="rrsync -wo /var/www/docu/htdocs",restrict ssh-ed25519 AAAA... |
| 13 | +# DEPLOY_HOST Server hostname or IP (e.g. docs.humhub.org) |
| 14 | +# DEPLOY_USER Deploy user name on the server |
| 15 | +# DEPLOY_KNOWN_HOSTS Output of `ssh-keyscan -H <host>` — pins the server key so |
| 16 | +# the connection cannot be MITM'd. |
| 17 | +# Optional: |
| 18 | +# DEPLOY_PORT SSH port (defaults to 22) |
| 19 | +# DEPLOY_PATH Destination path. Use "." when the key is locked to rrsync |
| 20 | +# (the path is relative to the rrsync root); use an absolute |
| 21 | +# path like "/var/www/docu/htdocs" if the key is unrestricted. |
| 22 | +# Defaults to ".". |
| 23 | + |
| 24 | +on: |
| 25 | + # Enable automatic deploys on push once the server-side deploy setup is done. |
| 26 | + # push: |
| 27 | + # branches: [master] |
| 28 | + workflow_dispatch: |
| 29 | + |
| 30 | +# Never let two deploys run at once; if a newer push arrives, drop the older run. |
| 31 | +concurrency: |
| 32 | + group: deploy-docs |
| 33 | + cancel-in-progress: true |
| 34 | + |
| 35 | +permissions: |
| 36 | + contents: read |
| 37 | + |
| 38 | +jobs: |
| 39 | + deploy: |
| 40 | + runs-on: ubuntu-latest |
| 41 | + # Bind the deploy secrets to a protected environment so only this workflow, |
| 42 | + # running on master, can read them. Configure protection rules on the |
| 43 | + # "production" environment in the repo settings. |
| 44 | + environment: production |
| 45 | + steps: |
| 46 | + - name: Checkout |
| 47 | + uses: actions/checkout@v4 |
| 48 | + |
| 49 | + - name: Set up Node.js |
| 50 | + uses: actions/setup-node@v4 |
| 51 | + with: |
| 52 | + node-version: '20' |
| 53 | + |
| 54 | + - name: Install dependencies |
| 55 | + run: npm install |
| 56 | + |
| 57 | + - name: Build |
| 58 | + run: npm run build |
| 59 | + |
| 60 | + - name: Set up SSH |
| 61 | + run: | |
| 62 | + mkdir -p ~/.ssh |
| 63 | + chmod 700 ~/.ssh |
| 64 | + printf '%s\n' "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/deploy_key |
| 65 | + chmod 600 ~/.ssh/deploy_key |
| 66 | + printf '%s\n' "${{ secrets.DEPLOY_KNOWN_HOSTS }}" > ~/.ssh/known_hosts |
| 67 | + chmod 600 ~/.ssh/known_hosts |
| 68 | +
|
| 69 | + - name: Deploy via rsync |
| 70 | + env: |
| 71 | + DEPLOY_PORT: ${{ secrets.DEPLOY_PORT || '22' }} |
| 72 | + DEPLOY_PATH: ${{ secrets.DEPLOY_PATH || '.' }} |
| 73 | + run: | |
| 74 | + rsync -az --delete \ |
| 75 | + -e "ssh -i ~/.ssh/deploy_key -p ${DEPLOY_PORT}" \ |
| 76 | + build/ "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:${DEPLOY_PATH}/" |
| 77 | +
|
| 78 | + - name: Clean up SSH key |
| 79 | + if: always() |
| 80 | + run: rm -f ~/.ssh/deploy_key |
0 commit comments