|
1 | | -# This workflow is triggered on pushes and pull requests to any branch. |
2 | | -# The job name includes the branch name dynamically. |
| 1 | +# 文档构建与部署工作流 |
| 2 | +# - dev 分支:只构建,不部署(用于验证 PR 不破坏构建) |
| 3 | +# - main 分支:构建 + 部署到 Cloudflare Pages(生产环境) |
3 | 4 |
|
4 | 5 | name: Docs Build and Upload to Cloudflare |
5 | 6 |
|
6 | | -on: |
| 7 | +on: |
7 | 8 | workflow_dispatch: |
8 | 9 | push: |
9 | 10 | branches: |
10 | 11 | - dev |
11 | 12 | - main |
12 | | - paths: |
| 13 | + paths: |
| 14 | + - 'docs/**' |
| 15 | + - 'versioned_docs/**' |
| 16 | + - 'i18n/**' |
| 17 | + - 'src/**' |
| 18 | + - 'static/**' |
| 19 | + - '**.js' |
| 20 | + - '.github/workflows/**' |
| 21 | + - '!docs/_list' |
| 22 | + pull_request: |
| 23 | + branches: |
| 24 | + - dev |
| 25 | + paths: |
13 | 26 | - 'docs/**' |
14 | 27 | - 'versioned_docs/**' |
15 | 28 | - 'i18n/**' |
|
18 | 31 | - '**.js' |
19 | 32 | - '!docs/_list' |
20 | 33 |
|
| 34 | +concurrency: |
| 35 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 36 | + cancel-in-progress: true |
| 37 | + |
21 | 38 | jobs: |
22 | 39 | build: |
23 | 40 | name: Build on branch ${{ github.ref_name }} |
24 | 41 | runs-on: ubuntu-latest |
25 | | - #if: false # stop steps |
26 | 42 | steps: |
27 | | - - uses: actions/checkout@master |
| 43 | + - uses: actions/checkout@v4 |
| 44 | + |
28 | 45 | - uses: actions/setup-node@v4 |
29 | 46 | with: |
30 | | - node-version: 20 |
| 47 | + node-version: 20 |
| 48 | + |
| 49 | + - name: Cache yarn dependencies |
| 50 | + uses: actions/cache@v4 |
| 51 | + with: |
| 52 | + path: node_modules |
| 53 | + key: ${{ runner.os }}-yarn-${{ hashFiles('**/package.json') }} |
| 54 | + restore-keys: | |
| 55 | + ${{ runner.os }}-yarn- |
| 56 | +
|
31 | 57 | - name: Docusaurus build |
32 | 58 | run: | |
33 | 59 | yarn install |
34 | 60 | yarn run build |
35 | 61 | env: |
36 | 62 | CI: true |
37 | | - |
38 | | - - name: Debug |
39 | | - run: ls |
40 | 63 |
|
41 | 64 | - name: Create apidocs directory and add files |
| 65 | + continue-on-error: true |
42 | 66 | run: | |
43 | 67 | mkdir -p build/apidocs |
44 | 68 | cd build/apidocs |
45 | 69 | wget -O redoc.standalone.js https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js |
46 | 70 | wget -O README.md https://websoft9.github.io/websoft9/apphub/apidocs/README.md |
47 | 71 | wget -O index.html https://websoft9.github.io/websoft9/apphub/apidocs/index.html |
48 | 72 | docker run -d --name apphub -p 8080:8080 websoft9dev/apphub:latest |
49 | | - sleep 5 |
50 | | - max_attempts=10 |
51 | | - url="http://localhost:8080/openapi.json" |
52 | | - for attempt in $(seq 1 $max_attempts); do |
53 | | - echo "Attempt #$attempt to download $url..." |
54 | | - if wget -O openapi.json "$url"; then |
55 | | - echo "Successfully downloaded $url" |
56 | | - break |
57 | | - else |
58 | | - echo "Failed to download $url. Waiting for 5 seconds before retry..." |
59 | | - sleep 5 |
60 | | - fi |
61 | | - done |
| 73 | + sleep 5 |
| 74 | + max_attempts=10 |
| 75 | + url="http://localhost:8080/openapi.json" |
| 76 | + for attempt in $(seq 1 $max_attempts); do |
| 77 | + echo "Attempt #$attempt to download $url..." |
| 78 | + if wget -O openapi.json "$url"; then |
| 79 | + echo "Successfully downloaded $url" |
| 80 | + break |
| 81 | + else |
| 82 | + echo "Failed to download $url. Waiting for 5 seconds before retry..." |
| 83 | + sleep 5 |
| 84 | + fi |
| 85 | + done |
62 | 86 |
|
63 | 87 | - name: Publish to Cloudflare Pages |
| 88 | + if: github.ref == 'refs/heads/main' |
64 | 89 | uses: cloudflare/pages-action@v1 |
65 | 90 | with: |
66 | 91 | apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
67 | 92 | accountId: eb79f13320db531d8cf1f3720966b695 |
68 | 93 | projectName: doc-websoft9-com |
69 | 94 | directory: build |
70 | | - # Optional: Enable this if you want to have GitHub Deployments triggered |
71 | 95 | gitHubToken: ${{ secrets.GITHUB_TOKEN }} |
72 | | - # Optional: Switch what branch you are publishing to. |
73 | | - # By default this will be the branch which triggered this workflow |
74 | | - # branch: dev |
|
0 commit comments