-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5cf52f1
commit 6fbbd8d
Showing
7 changed files
with
100 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,13 +22,13 @@ jobs: | |
steps: | ||
- name: Checkout action | ||
uses: actions/checkout@v2 | ||
- name: Gitbook Action | ||
uses: ZanderZhao/[email protected].3 # -> or ZanderZhao/gitbook-action@master | ||
- name: Gitbook Action # https://github.com/ZanderZhao/gitbook-action/releases | ||
uses: ZanderZhao/[email protected].4 # -> or ZanderZhao/gitbook-action@master. If not use master click above, use latest please | ||
with: # or fork this repo and use YourName/gitbook-action@master | ||
token: ${{ secrets.PERSONAL_TOKEN }} # -> remember add this in settings/secrets as following | ||
``` | ||
[Detailed step](https://zanderzhao.github.io/gitbook-action/how-to-use.html#addaction) [Official introduction](https://help.github.com/cn/actions/getting-started-with-github-actions/starting-with-preconfigured-workflow-templates) | ||
[Detailed step](https://zanderzhao.github.io/gitbook-action/how-to-use.html#addaction) | [Official introduction](https://help.github.com/cn/actions/getting-started-with-github-actions/starting-with-preconfigured-workflow-templates) | ||
### **STEP2** Generate Token and add to Secrets | ||
|
@@ -37,14 +37,14 @@ Create token from https://github.com/settings/tokens | |
+ choose repo | ||
+ click Generate token | ||
[Detailed step](https://zanderzhao.github.io/gitbook-action/how-to-use.html#createtoken) [Official introduction](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line#creating-a-token) | ||
[Detailed step](https://zanderzhao.github.io/gitbook-action/how-to-use.html#createtoken) | [Official introduction](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line#creating-a-token) | ||
Add your token to https://github.com/ **yourname/yourrepo** /settings/secrets | ||
+ Name: PERSONAL_TOKEN | ||
+ Value: which you get before | ||
[Detail step](https://zanderzhao.github.io/gitbook-action/how-to-use.html#addtoken) [Official introduction](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets#creating-encrypted-secrets) | ||
[Detail step](https://zanderzhao.github.io/gitbook-action/how-to-use.html#addtoken) | [Official introduction](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets#creating-encrypted-secrets) | ||
### **STEP3** Choose options | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/bin/sh -x | ||
|
||
|
||
####################### prepare sh config ############################### | ||
# print missage style | ||
# error 31XX | ||
print_error(){ | ||
|
@@ -18,6 +18,7 @@ print_warning(){ | |
echo "\033[32m Find Detail From: https://ZanderZhao.github.io/gitbook-action/warning \033[0m" | ||
} | ||
|
||
################################ prepare global config and show config ############################### | ||
# prepare var and env | ||
echo "--------------------------------------------" | ||
print_info "STEP1 env_config" | ||
|
@@ -520,6 +521,8 @@ else | |
echo "PUBLISH3 default false, if need you can publish different repo/branch" | ||
fi | ||
|
||
# install gitbook if not default version | ||
|
||
echo "--------------------" | ||
echo "FOR git node npm gitbook-cli" | ||
echo "----------" | ||
|
@@ -538,6 +541,9 @@ else | |
echo "gitbook-cli 2.3.2" | ||
fi | ||
|
||
|
||
######################## clone source ###################################3 | ||
|
||
# git clone source from repo/branch | ||
# source is must have. source2 can be not | ||
|
||
|
@@ -614,6 +620,8 @@ if [ ${INPUT_SOURCE2_REPO} != "null" ]; then | |
fi | ||
fi | ||
|
||
########################### clone publish branch #################################### | ||
# maybe different repo and need history before or be a part of repo | ||
|
||
# git clone publish history, prepare for the gitbook build file is apart of other object | ||
|
||
|
@@ -684,24 +692,40 @@ if [ ${INPUT_PUBLISH3_REPO} != "null" ]; then | |
fi | ||
fi | ||
|
||
|
||
################ Build #################################3 | ||
|
||
echo "--------------------------------------------" | ||
print_info "STEP4 build_gitbook_and_generate_file" | ||
echo "-----------------------------------" | ||
|
||
|
||
cd local_source | ||
ls | ||
|
||
# prepare install | ||
if [ -n "${INPUT_PREPARE_INSTALL}" ]; then | ||
print_info "Message:Runing user's prepare_install" | ||
${INPUT_PREPARE_INSTALL} | ||
# npm i --unsafe-perm -g [email protected] | ||
# just like npm i --unsafe-perm -g [email protected] | ||
# which has been installed before ? -> https://hub.docker.com/r/zanderzhao/gitbook-action/dockerfile | ||
else | ||
echo "no prepare_install" | ||
fi | ||
|
||
# install font | ||
if ${INPUT_GITBOOK_PDF} || ${INPUT_GITBOOK_EPUB} || ${INPUT_GITBOOK_MOBI} ; then | ||
if [ -n "${INPUT_FONT_INSTALL}" ]; then | ||
apt-get update | ||
apt-get install sudo -y | ||
print_info "Message:Runing user's font_install" | ||
${INPUT_FONT_INSTALL} | ||
#sudo apt-get install fonts-noto-cjk | ||
#sudo apt-get install ttf-mscorefonts-installer | ||
else | ||
print_warning "3308:Not install any font, maybe affect the pdf/mobi/epub, can add font_install at book.json" | ||
fi | ||
fi | ||
|
||
gitbook build --gitbook=${GITBOOK_BUILD_VERSION} | ||
if [ $? -eq 0 ]; then | ||
print_info "Message:gitbook built success" | ||
|
@@ -714,23 +738,10 @@ else # need plugins or README.md SUMMARY.md | |
print_info "Message:gitbook built success(with plugins)" | ||
else | ||
print_error "3105:gitbook built fail,please check is there something wrong with your book.json or others" | ||
|
||
fi | ||
fi | ||
|
||
# install font | ||
if ${INPUT_GITBOOK_PDF} || ${INPUT_GITBOOK_EPUB} || ${INPUT_GITBOOK_MOBI} ; then | ||
if [ -n "${INPUT_FONT_INSTALL}" ]; then | ||
apt-get update | ||
apt-get install sudo -y | ||
print_info "Message:Runing user's font_install" | ||
${INPUT_FONT_INSTALL} | ||
#sudo apt-get install fonts-noto-cjk | ||
#sudo apt-get install ttf-mscorefonts-installer | ||
else | ||
print_warning "3308:Not install any font, maybe affect the pdf/mobi/epub, can add font_install at book.json" | ||
fi | ||
fi | ||
|
||
|
||
# gitbook pdf | ||
if ${INPUT_GITBOOK_PDF} ; then | ||
|
@@ -753,6 +764,8 @@ print_info "STEP5 push_to_pages" | |
echo "--------------------------------------------" | ||
|
||
# remove cname in source or source2 | ||
# why? maybe use other src_repo which we can't control whether it has cname before | ||
# if need cname please add at config | ||
if [ -f local_source/_book/CNAME ]; then | ||
rm -rf local_source/_book/CNAME; | ||
if [ $? -eq 0 ]; then | ||
|
@@ -766,19 +779,24 @@ fi | |
|
||
######################### For publish ######################################### | ||
|
||
# if branch is new, need pubilsh_dir(if not /) | ||
if [ ! -d "./local_publish/${INPUT_PUBLISH_DIR}" ] ; then | ||
mkdir ./local_publish/${INPUT_PUBLISH_DIR} | ||
fi | ||
|
||
# need or not gitbook build history | ||
### need or not gitbook build history | ||
# I want use this config setting keep build history to get different time https://github.com/ZanderZhao/gitbook-action/issues/1 | ||
# But I fine it can't work, because some plugins still use the time when the action git clone src | ||
# So I use https://github.com/Dream4ever/Knowledge-Base/issues/69 replace it like 'source_edit_time' | ||
if [ ${INPUT_PUBLISH_REMOVE_LAST_BUILD} = "true" ] ; then | ||
cd local_publish | ||
git rm -rf --ignore-unmatch ./${INPUT_PUBLISH_DIR}/* | ||
# git rm -rf --ignore-unmatch ./${INPUT_PUBLISH_DIR}/.* | ||
cd .. | ||
fi | ||
|
||
# if branch is new, need pubilsh_dir(if not /) or rm by this action before | ||
# this is below INPUT_PUBLISH_REMOVE_LAST_BUILD -> https://github.com/ZanderZhao/gitbook-action/issues/5 | ||
if [ ! -d "./local_publish/${INPUT_PUBLISH_DIR}" ] ; then | ||
mkdir ./local_publish/${INPUT_PUBLISH_DIR} | ||
fi | ||
|
||
# move build file to each publish dir | ||
cp -rfp local_source/_book/. local_publish/${INPUT_PUBLISH_DIR} | ||
|
||
|
@@ -793,6 +811,7 @@ if [ "${INPUT_PUBLISH_CNAME}" != "null" ]; then # CNAME | |
fi | ||
fi | ||
|
||
# may push sucessfully, but built fail, try use this option in config -> https://github.com/ZanderZhao/gitbook-action/issues/4 | ||
if [ "${INPUT_PUBLISH_NOJEKYLL}" != "false" ]; then # add .nojekyll | ||
touch .nojekyll | ||
if [ $? -eq 0 ]; then | ||
|
@@ -801,29 +820,30 @@ if [ "${INPUT_PUBLISH_NOJEKYLL}" != "false" ]; then # add .nojekyll | |
fi | ||
|
||
# git config | ||
# maybe someone need different name for publish | ||
git config --local user.name ${PUBLISH_GIT_NAME} | ||
git config --local user.email ${PUBLISH_GIT_EMAIL} | ||
|
||
# git commit | ||
# need or not publish commit history | ||
if [ ${INPUT_PUBLISH_COMMIT_HISTORY} = "false" ] ; then # Clean commit history | ||
# https://stackoverflow.com/a/26000395 | ||
# Checkout | ||
# https://stackoverflow.com/a/26000395 | ||
# Checkout | ||
git checkout --orphan latest_branch | ||
# Add all the files | ||
# Add all the files | ||
git add . | ||
# Commit the changes | ||
# Commit the changes | ||
git commit -am "${PUBLISH_COMMIT_MESSAGE}" | ||
# Delete the branch | ||
# Delete the branch | ||
git branch -D ${INPUT_PUBLISH_BRANCH} | ||
# Rename the current branch | ||
# Rename the current branch | ||
git branch -m ${INPUT_PUBLISH_BRANCH} | ||
# Finally, force update your repository | ||
# git push -f origin master | ||
# -------- | ||
# rm -rf ./.git | ||
# git init | ||
# git checkout -b ${INPUT_PUBLISH_BRANCH} | ||
# Finally, force update your repository | ||
# git push -f origin master | ||
# -------- | ||
# rm -rf ./.git | ||
# git init | ||
# git checkout -b ${INPUT_PUBLISH_BRANCH} | ||
print_info "Message:Clean commit history success" | ||
else | ||
git add . | ||
|
@@ -842,7 +862,6 @@ elif [ ${INPUT_PUBLISH_PUSH_FORCE} = "true" ] ; then # try push force | |
print_warning "3306:Push force success" | ||
else | ||
print_error "3106:Can't push publish_repo/branch, maybe not add publish_token(with access) in gitbook_action.yml" | ||
|
||
fi | ||
else | ||
print_error "3107:Can't push publish_repo/branch, maybe not add publish_token(with access) in gitbook_action.yml or try set publish_push_force true" | ||
|
@@ -851,15 +870,12 @@ cd .. | |
|
||
|
||
######################### For publish2 ######################################### | ||
# why publish2 exists ? maybe someone need publish for different place, eg gitlib. | ||
# The following is the same with above except if. | ||
# Can use loop, but for different function later(like backup), I'm not | ||
# Can use loop, but for different function later(like backup), I'm not now | ||
|
||
if [ ${INPUT_PUBLISH2_REPO} != "null" ]; then | ||
|
||
if [ ! -d "./local_publish2/${INPUT_PUBLISH2_DIR}" ]; then | ||
mkdir ./local_publish2/${INPUT_PUBLISH2_DIR} | ||
fi | ||
|
||
# need or not gitbook build history | ||
if [ ${INPUT_PUBLISH2_REMOVE_LAST_BUILD} = "true" ] ; then | ||
cd local_publish2 | ||
|
@@ -868,6 +884,10 @@ if [ ${INPUT_PUBLISH2_REPO} != "null" ]; then | |
cd .. | ||
fi | ||
|
||
if [ ! -d "./local_publish2/${INPUT_PUBLISH2_DIR}" ]; then | ||
mkdir ./local_publish2/${INPUT_PUBLISH2_DIR} | ||
fi | ||
|
||
cp -rfp local_source/_book/. local_publish2/${INPUT_PUBLISH2_DIR} | ||
cd local_publish2 | ||
|
||
|
@@ -922,9 +942,7 @@ fi | |
|
||
if [ ${INPUT_PUBLISH3_REPO} != "null" ]; then | ||
|
||
if [ ! -d "./local_publish3/${INPUT_PUBLISH3_DIR}" ]; then | ||
mkdir ./local_publish3/${INPUT_PUBLISH3_DIR} | ||
fi | ||
|
||
|
||
# need or not gitbook build history | ||
if [ ${INPUT_PUBLISH3_REMOVE_LAST_BUILD} = "true" ] ; then | ||
|
@@ -934,6 +952,10 @@ if [ ${INPUT_PUBLISH3_REPO} != "null" ]; then | |
cd .. | ||
fi | ||
|
||
if [ ! -d "./local_publish3/${INPUT_PUBLISH3_DIR}" ]; then | ||
mkdir ./local_publish3/${INPUT_PUBLISH3_DIR} | ||
fi | ||
|
||
cp -rfp local_source/_book/. local_publish3/${INPUT_PUBLISH3_DIR} | ||
cd local_publish3 | ||
|
||
|
@@ -985,7 +1007,8 @@ if [ ${INPUT_PUBLISH3_REPO} != "null" ]; then | |
cd .. | ||
fi | ||
|
||
# TODO prepare for other gitbook action (if two or more gitbook-action in one action)(local_source exists), but at same time remove the plugins file (node_modules) for cache, maybe can remove to one place | ||
# TODO prepare for other gitbook action (if two or more gitbook-action in one action)(local_source exists), | ||
# but at same time remove the plugins file (node_modules) for cache, maybe can remove to one place | ||
|
||
if [ "${INPUT_NOT_CLEAN}" = "false" ]; then | ||
rm -rf local_source | ||
|
Oops, something went wrong.