|
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: |
13 | 14 | - 'docs/**' |
14 | 15 | - 'versioned_docs/**' |
15 | 16 | - 'i18n/**' |
16 | 17 | - 'src/**' |
17 | 18 | - 'static/**' |
18 | 19 | - '**.js' |
| 20 | + - '.github/workflows/**' |
19 | 21 | - '!docs/_list' |
20 | 22 |
|
| 23 | +concurrency: |
| 24 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 25 | + cancel-in-progress: true |
| 26 | + |
21 | 27 | jobs: |
22 | 28 | build: |
23 | 29 | name: Build on branch ${{ github.ref_name }} |
24 | 30 | runs-on: ubuntu-latest |
25 | | - #if: false # stop steps |
26 | 31 | steps: |
27 | | - - uses: actions/checkout@master |
| 32 | + - uses: actions/checkout@v4 |
| 33 | + |
28 | 34 | - uses: actions/setup-node@v4 |
29 | 35 | with: |
30 | | - node-version: 20 |
| 36 | + node-version: 20 |
| 37 | + |
| 38 | + - name: Cache yarn dependencies |
| 39 | + uses: actions/cache@v4 |
| 40 | + with: |
| 41 | + path: node_modules |
| 42 | + key: ${{ runner.os }}-yarn-${{ hashFiles('**/package.json') }} |
| 43 | + restore-keys: | |
| 44 | + ${{ runner.os }}-yarn- |
| 45 | +
|
31 | 46 | - name: Docusaurus build |
32 | 47 | run: | |
33 | 48 | yarn install |
34 | 49 | yarn run build |
35 | 50 | env: |
36 | 51 | CI: true |
37 | | - |
38 | | - - name: Debug |
39 | | - run: ls |
40 | 52 |
|
41 | 53 | - name: Create apidocs directory and add files |
| 54 | + continue-on-error: true |
42 | 55 | run: | |
43 | 56 | mkdir -p build/apidocs |
44 | 57 | cd build/apidocs |
45 | 58 | wget -O redoc.standalone.js https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js |
46 | 59 | wget -O README.md https://websoft9.github.io/websoft9/apphub/apidocs/README.md |
47 | 60 | wget -O index.html https://websoft9.github.io/websoft9/apphub/apidocs/index.html |
48 | 61 | 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 |
| 62 | + sleep 5 |
| 63 | + max_attempts=10 |
| 64 | + url="http://localhost:8080/openapi.json" |
| 65 | + for attempt in $(seq 1 $max_attempts); do |
| 66 | + echo "Attempt #$attempt to download $url..." |
| 67 | + if wget -O openapi.json "$url"; then |
| 68 | + echo "Successfully downloaded $url" |
| 69 | + break |
| 70 | + else |
| 71 | + echo "Failed to download $url. Waiting for 5 seconds before retry..." |
| 72 | + sleep 5 |
| 73 | + fi |
| 74 | + done |
62 | 75 |
|
63 | 76 | - name: Publish to Cloudflare Pages |
| 77 | + if: github.ref == 'refs/heads/main' |
64 | 78 | uses: cloudflare/pages-action@v1 |
65 | 79 | with: |
66 | 80 | apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
67 | 81 | accountId: eb79f13320db531d8cf1f3720966b695 |
68 | 82 | projectName: doc-websoft9-com |
69 | 83 | directory: build |
70 | | - # Optional: Enable this if you want to have GitHub Deployments triggered |
71 | 84 | 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