diff --git a/.github/workflows/gitbook-action.yml b/.github/workflows/gitbook-action.yml new file mode 100644 index 0000000..ba50cb1 --- /dev/null +++ b/.github/workflows/gitbook-action.yml @@ -0,0 +1,38 @@ +name: 'Gitbook-Action' + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout action + uses: actions/checkout@v1 + + # example1 + - name: Gitbook Action + uses: zanderzhao/gitbook-action@v1.2 + with: + token: ${{ secrets.PERSONAL_TOKEN }} + time_zone: Asia/Shanghai + source_dir: gitbook-source + source_edit_time: true + publish_commit_message: ${{ github.event.head_commit.message }} + + # example2 + - name: Gitbook Action + uses: zanderzhao/gitbook-action@v1.2 + with: + token: ${{ secrets.PERSONAL_TOKEN }} + time_zone: Asia/Shanghai + source_repo: GitbookIO/gitbook + source_branch: master + source_dir: docs + publish_dir: gitbook-docs + publish2_repo: gitbook-org/gitbook + + + diff --git a/gitbook-source/README.md b/gitbook-source/README.md new file mode 100644 index 0000000..2623bed --- /dev/null +++ b/gitbook-source/README.md @@ -0,0 +1,489 @@ +# Gitbook Action + +This action builds and publishes a gitbook to github pages and other pages. [Click here for more information](https://ZanderZhao.github.io/gitbook-action). + +## How to Use + +### **STEP1** Add Action + + Add `.github/workflows/gitbook-action.yml`in your repo, with following content. + +```yml +name: 'Gitbook Action Build' +on: + push: + branches: + - master # trigger branch +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout action + uses: actions/checkout@v2 + - name: Gitbook Action + uses: zanderzhao/gitbook-action@v2 + with: + token: ${{ secrets.PERSONAL_TOKEN }} +``` + +​ [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 + +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) + +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) + +### **STEP3** Choose options + ++ **Set Default Above** source branch is `master`, and the target branch is `gh-pages`. If `gh-pages` does not exist, it will be created automatically. ++ **The following** are options. + +## Option {#option} + + +### For global {#global} + ++ **git_name**: + + + description: ' If git name is different with github, please add' + + default: [GITHUB_ACTOR](https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables) + + ++ **git_email:** + + + description: ' If git name is different with github, please add' + + + default: [**@users.noreply.github.com](https://help.github.com/en/github/setting-up-and-managing-your-github-user-account/setting-your-commit-email-address#setting-your-commit-email-address-on-github) + + ++ **time_zone:** + + + description: 'System Default, if set, like [Asia/Shanghai](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)' + +### For Source Repo {#source} + ++ **source_repo**: + + description: 'Default this [GITHUB_REPOSITORY](https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables), if not please add like username/reponame ' + ++ **source_token**: + + + description: 'Default token, if not please add (clone)' + ++ **source_git_name**: + + + description: 'Default git_name, if not please add' + + ++ **source_hub**: + + + description: 'default is github.com,can be gitlib.com gitee.com ...' + + + default: 'github.com' + ++ **source_branch**: + + + description: 'Default master' + + + default: 'master' + ++ **source_dir**: + + + description: 'Where gitbook source. Default is root, if not add like mydir, instead of /mydir or mydir/' + + + default: '/' + ++ **source_edit_time**: + + + description: 'Default false, if plugins need last edit time, set true' + + + default: false + +### For Publish Repo {#publish} + ++ **publish_repo**: + + description: 'Default this [GITHUB_REPOSITORY](https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables), if not please add like username/reponame' + ++ **publish_token**: + + + description: 'Default token, if not please add (clone push)' + + ++ **publish_git_name**: + + + description: 'Default git_name, if not please add' + + ++ **publish_git_email**: + + + description: 'Default git_email, if not please add' + + ++ **publish_commit_message**: + + + description: 'Default Updated by gitbook-action and time, can use last commit message' + + Tip: can set `${{ github.event.head_commit.message }}` as [last commit message](https://help.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context) + + ++ **publish_hub**: + + + description: 'Default is github.com,can be gitlib.com gitee.com ...' + + + default: 'github.com' + ++ **publish_branch**: + + + description: 'Defaule is gh-pages, auto create' + + + default: '[gh-pages](https://help.github.com/en/github/working-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site)' + ++ **publish_dir**: + + + description: 'Default is root, if not add like docs ...' + + + default: '/' + ++ **publish_commit_history**: + + + description: 'set false will only one commit at publish_repo' + + + default: true + ++ **publish_cname**: + + + description: 'Default null' + + + default: 'null' + ++ **publish_push_force**: + + + description: 'Default false. Set true will enable git push force' + + + default: false + ++ **publish_remove_last_build**: + + + description: 'Default true. Set false not remove last build but rewrite same file' + + + default: true + +### For Gitbook Setting {#gitbooksetting} + ++ **gitbook_cli_version**: + + + description: 'Default is [2.3.2]( https://www.npmjs.com/package/gitbook-cli?activeTab=versions)' + + + default: '2.3.2' + ++ **gitbook_version**: + + + description: 'Default is [3.2.3](https://www.npmjs.com/package/gitbook?activeTab=versions)' + + + default: '3.2.3' + ++ **gitbook_pdf**: + + + description: 'Set true will generate pdf file' + + + default: false + ++ **gitbook_pdf_dir**: + + + description: 'Where the pdf to put. Default mybook, can change / for root, or myebook' + + + default: 'mybook' + ++ **gitbook_pdf_name**: + + + description: 'The name of your pdf. Default ebook' + + + default: 'ebook' + ++ **gitbook_epub**: + + + description: 'Set true will generate epub file' + + + default: false + ++ **gitbook_epub_dir**: + + + description: '' + + + default: 'mybook' + ++ **gitbook_epub_name**: + + + description: '' + + + default: 'ebook' + ++ **gitbook_mobi**: + + + description: 'Set true will generate mobi file' + + + default: false + ++ **gitbook_mobi_dir**: + + + description: '' + + + default: 'mybook' + ++ **gitbook_mobi_name**: + + + description: '' + + + default: 'ebook' + +### For other repo {#otherrepo} + +#### For Source2 repo {#source2} + ++ **source2_repo**: + + description: 'Default null, if use please add like username/reponame, (same with source will replace, different will mix)' + + default: 'null' + ++ **source2_git_name**: + + + description: 'Default git_name, if not please add' + + ++ **source2_token**: + + + description: 'Default token, if not please add (clone)' + ++ **source2_hub**: + + + description: '' + + + default: 'github.com' + ++ **source2_branch**: + + + description: '' + + + default: 'master' + ++ **source2_dir**: + + + description: '' + + + default: '/' + ++ **source2_edit_time**: + + + description: 'Default false if plugins need last edit time, set true' + + + default: false + +#### For Publish2 repo {#publish2} + ++ **publish2_repo**: + + description: 'Default null, if use please add like username/reponame' + + default: 'null' + ++ **publish2_git_name**: + + + description: 'Default git_name, if not please add' + + ++ **publish2_token**: + + + description: 'Default token, if not please add (clone push)' + required: 'false' + ++ **publish2_git_email**: + + + description: 'Default git_email, if not please add' + + ++ **publish2_commit_message**: + + + description: 'Default Updated by gitbook-action and time' + + ++ **publish2_hub**: + + + description: '' + + + default: 'github.com' + ++ **publish2_branch**: + + + description: 'Default gh-pages' + + + default: 'gh-pages' + ++ **publish2_dir**: + + + description: '' + + + default: '/' + ++ **publish2_cname**: + + + description: 'Default null' + + + default: 'null' + ++ **publish2_push_force**: + + + description: 'Default false. Set true will enable git push force' + + + default: false + ++ **publish_remove_last_build**: + + + description: 'Default true. Set false not remove last build but rewrite same file' + + + default: true + ++ **publish2_commit_history**: + + + description: 'set false will only one commit at publish2_repo' + + + default: true + +#### For Publish3 repo {#publish3} + ++ **publish3_git_name**: + + + description: 'Default git_name, if not please add' + + ++ **publish3_token**: + + + description: 'Default token, if not please add (clone push)' + ++ **publish3_git_email**: + + + description: 'Default git_email, if not please add' + + ++ **publish3_commit_message**: + + + description: 'Default Updated by gitbook-action and time' + + ++ **publish3_hub**: + + + description: '' + + + default: 'github.com' + ++ **publish3_repo**: + + + description: 'Default null, if use please add like username/reponame' + + + default: 'null' + ++ **publish3_branch**: + + + description: 'Default gh-pages' + + + default: 'gh-pages' + ++ **publish3_dir**: + + + description: 'Default root' + + + default: '/' + ++ **publish3_cname**: + + + description: 'Default null' + + + default: 'null' + ++ **publish3_push_force**: + + + description: 'Default false. Set true will enable git push force' + + + default: false + ++ **publish_remove_last_build**: + + + description: 'Default true. Set false not remove last build but rewrite same file' + + + default: true + ++ **publish3_commit_history**: + + + description: 'set false will only one commit at publish3_repo' + + default: true + +## Example {#example} + +```yml +name: 'Gitbook-Action' + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout action + uses: actions/checkout@v1 + + # example1--> https://ZanderZhao.github.io/gitbook-action + - name: Gitbook Action + uses: zanderzhao/gitbook-action@v1.2 + with: + token: ${{ secrets.PERSONAL_TOKEN }} + time_zone: Asia/Shanghai # set time zone + source_dir: source # clone from source + source_edit_time: true # source time + publish_commit_message: ${{ github.event.head_commit.message }} # use last commit message + + # example2--> https://ZanderZhao.github.io/gitbook-action/gitbook-docs + - name: Gitbook Action + uses: zanderzhao/gitbook-action@v1.2 + with: + token: ${{ secrets.PERSONAL_TOKEN }} + time_zone: Asia/Shanghai + source_repo: GitbookIO/gitbook # clone from https://github.com/GitbookIO/gitbook.git + source_branch: master # clone source master + source_dir: docs # gitbook-sorce at dir:docs + publish_dir: gitbook-docs # publish for this repo dir:gitbook-docs + publish2_repo: gitbook-org/gitbook # publish for another repo dir default root + +``` + + + +## FAQ {#faq} + +[ERROR](https://zanderzhao.github.io/error.html) + +[WARNING](https://zanderzhao.github.io/warning.html) + + + +## Community {#community} + +[Gitter](https://gitter.im/Gitbook-Action/community) + + + + +## External links {#external} + ++ ++ ++ ++ ++ \ No newline at end of file diff --git a/gitbook-source/SUMMARY.md b/gitbook-source/SUMMARY.md new file mode 100644 index 0000000..075e54c --- /dev/null +++ b/gitbook-source/SUMMARY.md @@ -0,0 +1,30 @@ +# Summary + +### Introduction + +* [README](README.md) +* [Add Action](how-to-use.md#addaction) +* [Create and Add Token](how-to-use.md#token) + * [Create token](how-to-use.md#createtoken) + * [Add token to repo](how-to-use.md#addtoken) +* [Choose Option](how-to-use.md#chooseoption) + +### Option + +* [For global](README.md#global) +* [For Source Repo](README.md#source) +* [For Publish Repo](README.md#publish) +* [For Gitbook Setting](README.md#gitbooksetting) +* [For other repo](README.md#otherrepo) + * [For Source2 repo](README.md#source2) + * [For Publish2 repo](README.md#publish2) + * [For Publish3 repo](README.md#publish3) + +### More + +* [Example](README.md#example) +* [FAQ](README.md#faq) + * [ERROR](error.md) + * [WARNING](warning.md) +* [Community](README.md#community) +* [External links](README.md#external) \ No newline at end of file diff --git a/gitbook-source/book.json b/gitbook-source/book.json new file mode 100644 index 0000000..2296bed --- /dev/null +++ b/gitbook-source/book.json @@ -0,0 +1,52 @@ +{ + "title": "Gitbook-Action", + "author": "Zander Zhao", + "description": "Gitbook-Action", + "gitbook": "3.2.3", + "links": { + "sidebar": { + "# Marketplace": "https://github.com/marketplace/actions/gitbook-action", + "# Github": "https://github.com/ZanderZhao/gitbook-action" + } + }, + "plugins": [ + "-lunr", + "-search", + "-sharing", + "theme-simple@git+https://github.com/plugins-zander/gitbook-plugin-theme-simple.git", + "search-pro@git+https://github.com/plugins-zander/gitbook-plugin-search-pro.git", + "splitter@git+https://github.com/plugins-zander/gitbook-plugin-splitter.git", + "mygitalk@git+https://github.com/plugins-zander/gitbook-plugin-mygitalk.git", + "edit-link@git+https://github.com/plugins-zander/gitbook-plugin-edit-link.git", + "sitemap-general@git+https://github.com/plugins-zander/gitbook-plugin-sitemap-general.git", + "tbfed-pagefooter@git+https://github.com/plugins-zander/gitbook-plugin-tbfed-pagefooter.git", + "todo@git+https://github.com/plugins-zander/gitbook-plugin-todo.git", + "chapter-fold@git+https://github.com/plugins-zander/gitbook-plugin-chapter-fold.git", + "copy-code-button@git+https://github.com/plugins-zander/gitbook-plugin-copy-code-button.git" + ], + "pluginsConfig": { + "mygitalk": { + "clientID": "364365ceb2659b383d73", + "clientSecret": "447ef6648e9dfffe2e2a65c34c8ead1dd4b7af54", + "repo": "talk", + "owner": "zanderzhao", + "admin": [ + "zanderzhao" + ], + "distractionFreeMode": false + }, + "edit-link": { + "base": "https://github.com/ZanderZhao/gitbook-action/edit/master/gitbook-source", + "label": "EDIT" + }, + "sitemap-general": { + "prefix": "https://zlogs.net/gitbook-action/" + }, + "tbfed-pagefooter": { + "copyright": "Edit by Zander Zhao ; ", + "modify_bszlabel": "View Count: ", + "modify_label": "Last Edit:", + "modify_format": "YYYY-MM-DD HH:mm:ss" + } + } +} \ No newline at end of file diff --git a/gitbook-source/error.md b/gitbook-source/error.md new file mode 100644 index 0000000..4e5c66f --- /dev/null +++ b/gitbook-source/error.md @@ -0,0 +1,80 @@ +# ERROR + +## 31XX + +3101 + ++ need token please + + need main token, which is other default token + + + +3102 3102-2 + ++ Source git clone success, but not find gitbook-source file in dir + + find repo, and clone repo success, + + but not find gitbook-source in `source_dir` + + + +3103 3103-2 3104 3104-2 3104-3 + ++ Can't find this source_repo/branch, maybe not add token or source_token(with access) in gitbook_action.yml + + can't git clone repo + + maybe not exists this `source_repo` + + or you don't add `token` + + or the `token` or`source_token`without oath + + + +3105 + ++ gitbook built fail,please check is there something wrong with your book.json or others + + build fail with plugins + + maybe something wrong with SUMMARY.md README.md + + or wrong with book.json + + or wrong other file + + or some plugins can't install + + or plugins run fail + + + +3016 3016-2 3016-3 + ++ Can't push publish_repo/branch, maybe not add publish_token(with access) in gitbook_action.yml + + can't push and push force sucess + + maybe your token without oath to push this repo + + + +3107 3017-2 3017-3 + ++ Can't push publish_repo/branch, maybe not add publish_token(with access) in gitbook_action.yml or try set publish_push_force true + + can't push sucess + + maybe your token without oath to push this repo + + or try to allow push force, add `publish_push_force: true` + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gitbook-source/how-to-use.md b/gitbook-source/how-to-use.md new file mode 100644 index 0000000..ad88799 --- /dev/null +++ b/gitbook-source/how-to-use.md @@ -0,0 +1,80 @@ +# STEP1 Add Action {#addaction} + + Add `.github/workflows/gitbook-action.yml`in your repo, with following content. + +![](https://cdn.jsdelivr.net/gh/ZanderZhao/img20/file/20200304203049.png) + +![](https://cdn.jsdelivr.net/gh/ZanderZhao/img20/file/20200304203445.png) + + +``` +name: 'Gitbook Action Build' +on: + push: + branches: + - master # trigger branch +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout action + uses: actions/checkout@v2 + - name: Gitbook Action + uses: zanderzhao/gitbook-action@v2 + with: + token: ${{ secrets.PERSONAL_TOKEN }} +``` + + +![](https://cdn.jsdelivr.net/gh/ZanderZhao/img20/file/20200304204230.png) + +![](https://cdn.jsdelivr.net/gh/ZanderZhao/img20/file/20200304204602.png) + + + +### **STEP2** Greate Token and add to Secrets {#token} + +#### step2.1 Create token {#createtoken} + +- click https://github.com/settings/tokens + +![](https://cdn.jsdelivr.net/gh/ZanderZhao/img20/file/20200304205657.png) + +![](https://cdn.jsdelivr.net/gh/ZanderZhao/img20/file/20200304205817.png) + +![](https://cdn.jsdelivr.net/gh/ZanderZhao/img20/file/20200304210004.png) + +![](https://cdn.jsdelivr.net/gh/ZanderZhao/img20/file/20200304210104.png) + +![](https://cdn.jsdelivr.net/gh/ZanderZhao/img20/file/20200304210306.png) + + +#### step2.2 Add token to repo {#addtoken} + +- go to https://github.com/ **yourname/yourrepo** /settings/secrets + +![](https://cdn.jsdelivr.net/gh/ZanderZhao/img20/file/20200304210813.png) + +![](https://cdn.jsdelivr.net/gh/ZanderZhao/img20/file/20200304210926.png) + +![](https://cdn.jsdelivr.net/gh/ZanderZhao/img20/file/20200304211301.png) + + + +### **STEP3** Choose options {#chooseoption} + +- **Set Default Above** + - Source branch is `master`, and the target branch is `gh-pages`. If `gh-pages` does not exist, it will be created automatically. +- **More Options And Example**. + - Introduction on + - Source repo and publish repo can be different + - Source git from other people + - Choose your own gitbook version + - Clean commit history + - Keep time setting of file + - ... ... + + + + + diff --git a/gitbook-source/warning.md b/gitbook-source/warning.md new file mode 100644 index 0000000..a5fb033 --- /dev/null +++ b/gitbook-source/warning.md @@ -0,0 +1,82 @@ +# WARNING + +## 33XX + +3301 + ++ Source2 git success. It will replace what we git before, when have same file + + Just Emphasize + + If source/dir and source2/dir have file with same name, will only source2 left + + If diffenent , both left + + They build together as one gitbook-source, not replace + + + +3302 3302-2 3302-3 + ++ Can't find this publish_branch, but find this repo, we checkout new branch + + clone this repo sucess + + but there no `publish_branch` + + create new branch sucess + + + +3303 + ++ gitbook built fail, maybe need some file or plugins, now we try again + + Just Emphasize + + build without plugins fail + + next will try to build again with plugins + + + +3304 + ++ Remove the CNAME(from source or source2), if need cname please add in gitbook_action.yml publish_cname:value + + Just Emphasize + + if source has CNAME, here will remove + + if use CNAME, can add `publish_cname: value`in action.yml + + + +3305 3305-2 3305-3 + ++ Can't push publish_repo/branch, try push force + + Just Emphasize + + you allow push force, and now can push normal success + + next will try to push force + + + +3306 3306-2 3306-3 + ++ Push force success + + Just Emphasize + + here publish force + + + +3307 + ++ NOT_CLEAN set true, if two gitbook-action in one workflow may run fatal. If don't use cache, (source build file-->node_modules), please set false(Default), and CLEAN is not remove gitbook-cli and gitbook + + Just Emphasize + + if two gitbook-action in one workflow may run fatal. + + If don't use cache, (source build file-->node_modules), please set false(Default) + + CLEAN is not remove gitbook-cli and gitbook + + + + + + + + + + + + + + + + +