From 08aecda4d066633d7bda1f9bea2ce073996c096e Mon Sep 17 00:00:00 2001 From: TheClashFruit Date: Sat, 20 Apr 2024 17:51:34 +0200 Subject: [PATCH] feat: deploy!! --- action.yml | 16 ++++++++++++++++ deploy.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 action.yml create mode 100644 deploy.sh diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..fdc1607 --- /dev/null +++ b/action.yml @@ -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 \ No newline at end of file diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..c1467c6 --- /dev/null +++ b/deploy.sh @@ -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 \ No newline at end of file