pedini.dev/version.sh

41 lines
1.4 KiB
Bash
Raw Permalink Normal View History

2024-08-21 19:49:00 +00:00
#!/usr/bin/env bash
set -e
2024-08-21 20:01:24 +00:00
# Check if version is already provided
2024-08-21 20:31:38 +00:00
if [ -z "${APP_VERSION}" ]; then
2024-08-21 20:01:24 +00:00
# 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
2024-08-21 19:49:00 +00:00
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