Improve the init tool
This commit is contained in:
parent
77c2009658
commit
a053c454e4
1 changed files with 23 additions and 1 deletions
|
@ -16,6 +16,13 @@ help() {
|
||||||
echo " -h, --help Print this help information."
|
echo " -h, --help Print this help information."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_status() {
|
||||||
|
if [[ -n $(git status . -s) ]]; then
|
||||||
|
echo "Error: Commit unstaged files first, and then run this tool againt."
|
||||||
|
exit -1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
check_init() {
|
check_init() {
|
||||||
local _has_inited=false
|
local _has_inited=false
|
||||||
|
|
||||||
|
@ -40,25 +47,40 @@ check_init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
init_files() {
|
init_files() {
|
||||||
|
|
||||||
if $_no_gh; then
|
if $_no_gh; then
|
||||||
rm -rf .github
|
rm -rf .github
|
||||||
else
|
else
|
||||||
|
# change the files of `.github`
|
||||||
mv .github/workflows/$ACTIONS_WORKFLOW.hook .
|
mv .github/workflows/$ACTIONS_WORKFLOW.hook .
|
||||||
rm -rf .github
|
rm -rf .github
|
||||||
mkdir -p .github/workflows
|
mkdir -p .github/workflows
|
||||||
mv ./${ACTIONS_WORKFLOW}.hook .github/workflows/${ACTIONS_WORKFLOW}
|
mv ./${ACTIONS_WORKFLOW}.hook .github/workflows/${ACTIONS_WORKFLOW}
|
||||||
|
|
||||||
|
# ensure the gh-actions trigger branch
|
||||||
|
|
||||||
|
_workflow=".github/workflows/${ACTIONS_WORKFLOW}"
|
||||||
|
_default_branch="$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')"
|
||||||
|
_lineno="$(sed -n "/branches:/=" "$_workflow")"
|
||||||
|
sed -i "$((_lineno + 1))s/- .*/- ${_default_branch}/" "$_workflow"
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# trace the gem lockfile on user-end
|
||||||
|
sed -i "/Gemfile.lock/d" .gitignore
|
||||||
|
|
||||||
|
# remove the other fies
|
||||||
rm -f .travis.yml
|
rm -f .travis.yml
|
||||||
rm -rf _posts/* docs
|
rm -rf _posts/* docs
|
||||||
|
|
||||||
|
# save changes
|
||||||
git add -A && git add .github -f
|
git add -A && git add .github -f
|
||||||
git commit -m "[Automation] Initialize the environment." -q
|
git commit -m "[Automation] Initialize the environment." -q
|
||||||
|
|
||||||
echo "[INFO] Initialization successful!"
|
echo "[INFO] Initialization successful!"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_status
|
||||||
|
|
||||||
check_init
|
check_init
|
||||||
|
|
||||||
_no_gh=false
|
_no_gh=false
|
||||||
|
|
Loading…
Reference in a new issue