pedini.dev/version.sh

38 lines
1.3 KiB
Bash
Raw Normal View History

2024-08-21 21:49:00 +02:00
#!/usr/bin/env bash
set -e
# Get version from user
read -p "Version [latest]: " VERSIONINPUT
# If version was not provided, use the latest commit short hash as version
if [ -z ${VERSIONINPUT} ]; then
APP_VERSION="latest"
else
APP_VERSION=${VERSIONINPUT}
fi
# Get project commit id and URL
COMMIT_ID=$(git log HEAD --oneline | awk '{print $1}' | head -n1)
COMMIT_URL="$(git remote get-url origin | sed 's/\.git$//g;s/:/\//;s/git@/https:\/\//')/commit/${COMMIT_ID}"
# Get the theme used and its commit id and URL
THEME=$(cat hugo.yaml | grep "theme:" | awk '{print $2}' | sed 's/"//g')
pushd themes/${THEME} &>/dev/null
THEME_COMMIT=$(git log HEAD --oneline | awk '{print $1}' | head -n1)
THEME_URL="$(git remote get-url origin | sed 's/\.git$//g')/commit/${THEME_COMMIT}"
popd &>/dev/null
# Create version tag (if provided)
if [ ! -z ${VERSIONINPUT} ]; then
git tag ${APP_VERSION}
fi
# Build the website
hugo
# Put the correct version information in the website
sed -i "s|VAR_VERSION|${APP_VERSION}|" public/version/index.html
sed -i "s|VAR_COMMIT_ID|${COMMIT_ID}|" public/version/index.html
sed -i "s|VAR_COMMIT_URL|${COMMIT_URL}|" public/version/index.html
sed -i "s|VAR_THEME_URL|${THEME_URL}|" public/version/index.html
sed -i "s|VAR_THEME_COMMIT|${THEME_COMMIT}|" public/version/index.html