update deploy.sh
This commit is contained in:
parent
129c395823
commit
7c68898bf2
32
deploy.sh
32
deploy.sh
@ -1,49 +1,57 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# ref: https://github.com/jekyll/jekyll
|
# ref: https://github.com/jekyll/jekyll
|
||||||
|
|
||||||
set -eu
|
set -eu # Exit on error or unset variable
|
||||||
|
|
||||||
PAGES_BRANCH="gh-pages"
|
PAGES_BRANCH="gh-pages"
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
if [[ -z ${GITHUB_ACTION+x}]]; then
|
# Check if the script is running in a GitHub Actions environment
|
||||||
echo "ERROR: Not allowed to deploy outside of the GitHub Action envrionment."
|
if [[ -z ${GITHUB_ACTION+x} ]]; then
|
||||||
exit -1
|
echo "ERROR: Not allowed to deploy outside of the GitHub Action environment."
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
|
# Run the Ruby script to generate the output
|
||||||
bundle exec ruby "./scaffold.rb"
|
bundle exec ruby "./scaffold.rb"
|
||||||
|
|
||||||
|
# Move all generated files to the root directory
|
||||||
mv ./_output/* ./
|
mv ./_output/* ./
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_gh() {
|
setup_gh() {
|
||||||
|
# Delete the branch if it exists, and create a new one
|
||||||
if git branch --list "$PAGES_BRANCH" > /dev/null; then
|
if git branch --list "$PAGES_BRANCH" > /dev/null; then
|
||||||
echo "Branch '$PAGES_BRANCH' exists. Deleting and recreating it..."
|
echo "Branch '$PAGES_BRANCH' exists. Deleting and recreating it..."
|
||||||
git branch -D "$PAGES_BRANCH" # Delete the branch
|
git branch -D "$PAGES_BRANCH"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create and switch to the branch
|
# Create and switch to the new branch
|
||||||
git checkout -b "$PAGES_BRANCH"
|
git checkout -b "$PAGES_BRANCH"
|
||||||
}
|
}
|
||||||
|
|
||||||
deploy() {
|
deploy() {
|
||||||
|
# Configure Git user for the commit
|
||||||
git config --global user.name "ZhgChgLiBot"
|
git config --global user.name "ZhgChgLiBot"
|
||||||
git config --global user.email "no-reply@zhgchg.li"
|
git config --global user.email "no-reply@zhgchg.li"
|
||||||
|
|
||||||
|
# Reset the current HEAD to prepare for new commits
|
||||||
git update-ref -d HEAD
|
git update-ref -d HEAD
|
||||||
git add -A
|
git add -A
|
||||||
git commit -m "[Automation] Site update No.${GITHUB_RUN_NUMBER}"
|
git commit -m "[Automation] Site update No.${GITHUB_RUN_NUMBER}"
|
||||||
|
|
||||||
git push -u origin "$PAGES_BRANCH"
|
# Push the new branch to the remote repository
|
||||||
|
git push -u origin "$PAGES_BRANCH" --force
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
init
|
init # Initialize and validate environment
|
||||||
build
|
build # Build the site
|
||||||
setup_gh
|
setup_gh # Set up the gh-pages branch
|
||||||
deploy
|
deploy # Deploy the site
|
||||||
}
|
}
|
||||||
|
|
||||||
main
|
# Execute the main function
|
||||||
|
main
|
Loading…
x
Reference in New Issue
Block a user