commit accafc15d5a854d4d1a229326f90e34788cd9d7b Author: Maximilian Keßler Date: Tue Oct 17 15:49:51 2023 +0200 initial commit diff --git a/action.sh b/action.sh new file mode 100755 index 0000000..981a7a4 --- /dev/null +++ b/action.sh @@ -0,0 +1,31 @@ +# Set up private key in a five + +SSH_KEY_FILE=/tmp/gitea-pages-ssh-key-$(date +%s) + +# set up ssh private key +echo "${INPUT_SSH_KEY}" >> "${SSH_KEY_FILE}" +chmod 600 "${SSH_KEY_FILE}" + +# set up ssh remote key +echo "${INPUT_HOST} ${INPUT_HOST_KEY}" >> ~/.ssh/known_hosts + +# optionally: create index +if [ "${INPUT_INDEX}" ]; then + if [ ! -e "${INPUT_DIRECTORY}/index.html" ]; then + tree -H "${INPUT_DIRECTORY}" \ + -D \ + --charset utf-8 \ + -T "${INPUT_INDEX_TITLE}" \ + > "${INPUT_DIRECTORY}/index.html" + echo "Added index" + else + echo "File index.html exists, not overriding." + fi +fi + + +# deploy via ssh +tar -C "${INPUT_DIRECTORY}" -czf - . \ + | ssh -o "IdentitiesOnly=yes" -i "${SSH_KEY_FILE}" \ + "${INPUT_HOST_USER}@${INPUT_HOST}" + diff --git a/action.yaml b/action.yaml new file mode 100644 index 0000000..41330e0 --- /dev/null +++ b/action.yaml @@ -0,0 +1,49 @@ +name: 'Deploy to Pages' +description: 'Deploy files to static html server via ssh' +author: 'Maximilian Keßler' +inputs: + host: + description: > + Server to deploy to. + The action will ssh to this endpoint to try to deploy files. + default: pabstractnonsen.se + host-user: + description: > + User used for host authentication. + default: pages + hostkey: + description: > + SSH host key fingerprint of the specified host, including the key type. + If this does not match the host key fingerprint upon invocation of ssh, + the action will fail + default: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAufJTq206GOv0D8gHs2o3eDusLNWaB0U7JRhUYnux9B + ssh-key: + description: > + SSH key used to authenticate to host. + default: ${{ secrets.pages_ssh_key }} + directory: + description: > + Directory to deploy. + default: pages + index: + description: > + Whether to create an index.html file recursively listing the directory + default: true + index-title: + description: > + Title that will be displayed in the index.html + default: ${{ github.repository }} + runs: + using: composite + steps: + - shell: bash + run: | + "${GITHUB_ACTION_PATH}/action.sh" + env: + INPUT_HOST: ${{ inputs.host }} + INPUT_HOST_USER: ${{ inputs.host-user }} + INPUT_HOST_KEY: ${{ inputs.hostkey }} + INPUT_SSH_KEY: ${{ inputs.ssh-key }} + INPUT_DIRECTORY: ${{ inputs.directory }} + INPUT_INDEX: ${{ inputs.index }} + INPUT_INDEX_TITLE: ${{ inputs.index-title }}