tldr/scripts/deploy.sh

47 lines
1.3 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2020-06-09 15:03:35 +01:00
# This script is executed by GitHub Actions when a PR is merged (i.e. in the `deploy` step).
set -ex
function initialize {
if [ -z "$TLDRHOME" ]; then
2020-06-09 15:03:35 +01:00
export TLDRHOME=${GITHUB_WORKSPACE:-$(pwd)}
fi
export TLDR_ARCHIVE="tldr.zip"
export SITE_HOME="$HOME/site"
export SITE_REPO_SLUG="tldr-pages/tldr-pages.github.io"
# Configure git.
2020-06-09 15:03:35 +01:00
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
git config --global push.default simple
git config --global diff.zip.textconv "unzip -c -a"
# Decrypt and add deploy key.
eval "$(ssh-agent -s)"
openssl aes-256-cbc -K "$encrypted_973441be79af_key" -iv "$encrypted_973441be79af_iv" -in ./scripts/id_ed25519_tldr_asset_upload.enc -out id_ed25519 -d
chmod 600 id_ed25519
ssh-add id_ed25519
}
function upload_assets {
git clone --quiet --depth 1 git@github.com:${SITE_REPO_SLUG}.git "$SITE_HOME"
mv -f "$TLDR_ARCHIVE" "$SITE_HOME/assets/"
cp -f "$TLDRHOME/index.json" "$SITE_HOME/assets/"
cd "$SITE_HOME"
git add -A
2020-06-24 12:53:35 +01:00
git commit -m "[GitHub Actions] uploaded assets after commit ${GITHUB_SHA}"
git push -q
echo "Assets (pages archive, index) deployed to static site."
}
###################################
# MAIN
###################################
initialize
upload_assets