feat: deploy!!

This commit is contained in:
TheClashFruit 2024-04-20 17:51:34 +02:00
parent 7d3a5eeba7
commit 08aecda4d0
Signed by: TheClashFruit
GPG key ID: 09BB24C34C2F3204
2 changed files with 63 additions and 0 deletions

16
action.yml Normal file
View file

@ -0,0 +1,16 @@
name: "Deploy to Pages"
description: "Deploy pages that require builds!"
inputs:
folder:
description: "The folder to deploy."
required: true
type: string
runs:
using: "composite"
steps:
- run: echo "${{ github.action_path }}" >> $GITHUB_PATH
shell: bash
- run: deploy.sh
shell: bash

47
deploy.sh Normal file
View file

@ -0,0 +1,47 @@
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="$DEPLOY_BRANCH.$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