pages-deploy/deploy.sh
2024-04-21 13:11:52 +02:00

50 lines
1.4 KiB
Bash
Executable file

set -e
# most of the stuff is taken from [https://git.gay/gitgay/pages-deploy] with a few modifications.
# Set the variables
COMMIT_ID=$(git rev-parse --short HEAD)
FOLDER=$INPUT_FOLDER
GIT_SERVER_HOST=$(echo $GITHUB_SERVER_URL | sed 's/.*:\/\///' | sed 's/\/$//')
GIT_REMOTE="https://$GIT_SERVER_HOST/$GITHUB_REPOSITORY"
GITHUB_REPOSITORY_AUTHOR=$(echo "$GITHUB_REPOSITORY" | cut -d'/' -f1)
GITHUB_REPOSITORY_NAME=$(echo "$GITHUB_REPOSITORY" | cut -d'/' -f2)
PAGES_HOSTNAME="$GITHUB_REPOSITORY_NAME.$GITHUB_REPOSITORY_AUTHOR.theclashfruit.page"
# Move to temp
TMP_DIR=$(mktemp -d)
mv $FOLDER "$TMP_DIR/build"
# Setting the git user
git config user.name "Forgejo"
git config user.email "forgejo@theclashfruit.me"
# Check if the pages branch exists
if git rev-list --count $DEPLOY_BRANCH 2 > /dev/null; then
echo "Pages branch already exists, checking it out..."
git checkout $DEPLOY_BRANCH
else
echo "Pages branch does not exist, creating it..."
git checkout --orphan pages
fi
# idk
find . -maxdepth 1 ! \( -name '.git' -o -name '.' -o -name '..' \) -exec rm -rf {} +
cp -rT "$TMP_DIR/build" .
# Commit and push
git add --all
git commit -m "Deployed $COMMIT_ID to Pages. ($PAGES_HOSTNAME)"
git remote set-url origin "https://$GITHUB_ACTOR:$GITHUB_TOKEN@$GIT_SERVER_HOST/$GITHUB_REPOSITORY.git"
git push --force origin "$DEPLOY_BRANCH:$DEPLOY_BRANCH"
curl -sL -H 'cache-control: no-cache' "https://$PAGES_HOSTNAME" > /dev/null
exit 0