name: Deploy static site description: >- Ships a built static site to a host guarded by the deploy-static forced command: writes version.txt, rsyncs the files into releases// and atomically activates them. inputs: ssh-key: description: Private key of the site account; the server pins it to deploy-static. required: true ssh-user: description: Site account on the server (www-*). required: true host: description: Server host name. required: true known-hosts: description: Pinned known_hosts line for the host. Never generate it with ssh-keyscan in CI. required: true release: description: Release id - directory name on the server and content of version.txt. Empty means the pushed ref name (tag). required: false default: '' path: description: Directory with the built site. required: false default: public runs: using: composite steps: - name: Configure SSH shell: sh env: DEPLOY_SSH_KEY: ${{ inputs.ssh-key }} DEPLOY_SSH_USER: ${{ inputs.ssh-user }} DEPLOY_HOST: ${{ inputs.host }} DEPLOY_KNOWN_HOSTS: ${{ inputs.known-hosts }} # The runner does not enforce `required`, and an empty secret would surface later as a # cryptic ssh error - name what is missing instead. run: | missing="" [ -n "$DEPLOY_SSH_KEY" ] || missing="$missing ssh-key" [ -n "$DEPLOY_SSH_USER" ] || missing="$missing ssh-user" [ -n "$DEPLOY_HOST" ] || missing="$missing host" [ -n "$DEPLOY_KNOWN_HOSTS" ] || missing="$missing known-hosts" if [ -n "$missing" ]; then echo "::error::deploy-static-site: empty inputs:$missing" exit 1 fi install -d -m 700 ~/.ssh (umask 077 && printf '%s\n' "$DEPLOY_SSH_KEY" > ~/.ssh/deploy) printf '%s\n' "$DEPLOY_KNOWN_HOSTS" > ~/.ssh/known_hosts cat > ~/.ssh/config < "$SITE_PATH/version.txt" # No --delete (the release directory is new) and no -p/-o/-g (activate sets permissions). - name: Upload release shell: sh env: RELEASE: ${{ inputs.release || github.ref_name }} SITE_PATH: ${{ inputs.path }} run: rsync -rlz "$SITE_PATH/" "prod:$RELEASE/" - name: Activate release shell: sh env: RELEASE: ${{ inputs.release || github.ref_name }} run: | # shellcheck disable=SC2029 # the id is meant to expand on the CI side ssh prod activate "$RELEASE" ssh prod list # Runs even after a failed upload/activate, so a later step of the job cannot reuse the key. - name: Remove SSH key if: always() shell: sh run: rm -f ~/.ssh/deploy ~/.ssh/config ~/.ssh/known_hosts