|
| 1 | +name: Javadoc |
| 2 | + |
| 3 | +on: |
| 4 | + # 支持手动触发构建 |
| 5 | + workflow_dispatch: |
| 6 | + release: |
| 7 | + # 创建release的时候触发 |
| 8 | + types: [ published ] |
| 9 | + # push: # 可选,在推送主分支时触发 |
| 10 | + # branches: |
| 11 | + # - main |
| 12 | + # - master |
| 13 | + |
| 14 | + jobs: |
| 15 | + apidoc-deploy: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Checkout the repo |
| 19 | + uses: actions/checkout@v2 |
| 20 | + |
| 21 | + - name: Set up the Java JDK |
| 22 | + uses: actions/setup-java@v2 |
| 23 | + with: |
| 24 | + java-version: '11' |
| 25 | + distribution: 'adopt' |
| 26 | + |
| 27 | + - name: Generate docs #生成Javadoc |
| 28 | + run: mvn javadoc:javadoc |
| 29 | + |
| 30 | + - name: Copy to Location # 复制Javadoc到一个新文件夹,便于进行git操作 |
| 31 | + run: | |
| 32 | + rm -rf docs |
| 33 | + mkdir -vp docs |
| 34 | + cp -vrf target/site/apidocs/* docs/ |
| 35 | +
|
| 36 | + - name: Generate the sitemap # 可选,生成sitemap |
| 37 | + id: sitemap |
| 38 | + uses: cicirello/generate-sitemap@v1 |
| 39 | + with: |
| 40 | + base-url-path: https://carmjos.github.io/userprefix |
| 41 | + path-to-root: docs |
| 42 | + |
| 43 | + - name: Configure Git # 配置Git |
| 44 | + env: |
| 45 | + DEPLOY_PRI: ${{secrets.DEPLOY_PRI}} # 这里就是刚刚配置的私钥了 |
| 46 | + GIT_USERNAME: ${{ github.repository_owner }} #Github用户名,这里用了Actions自带的变量,也可以写死。 |
| 47 | + GIT_EMAIL: ${{ github.repository_owner }}@user.github.com # 邮箱,可以写自己的邮箱。 |
| 48 | + run: | |
| 49 | + sudo timedatectl set-timezone "Asia/Shanghai" |
| 50 | + mkdir -p ~/.ssh/ |
| 51 | + echo "$DEPLOY_PRI" > ~/.ssh/id_rsa |
| 52 | + chmod 600 ~/.ssh/id_rsa |
| 53 | + ssh-keyscan github.com >> ~/.ssh/known_hosts |
| 54 | + git config --global user.name '$DEPLOY_PRI' |
| 55 | + git config --global user.email '$DEPLOY_PRI' |
| 56 | +
|
| 57 | +
|
| 58 | + - name: Commit documentation # 提交文档到Git仓库 |
| 59 | + env: |
| 60 | + GIT_URL: "git@github.com:<USERNAME>/<PROJECT>.git" # 项目的地址,注意要用SSH格式的。 |
| 61 | + run: | |
| 62 | + cd docs |
| 63 | + git init |
| 64 | + git remote add origin $GIT_URL |
| 65 | + git checkout -b gh-pages |
| 66 | + git add -A |
| 67 | + git commit -m "API Document generated." |
| 68 | +
|
| 69 | + - name: Push javadocs # 推送 |
| 70 | + run: | |
| 71 | + cd docs |
| 72 | + git push origin HEAD:gh-pages --force |
0 commit comments