@@ -11,7 +11,7 @@ concurrency:
1111 cancel-in-progress : false # Skip any intermediate builds but finish deploying
1212
1313jobs :
14- build :
14+ build-mdbook :
1515 runs-on : ubuntu-latest
1616 env :
1717 MDBOOK_ENV : 0.5.2 # Current `mdbook` version. See `https://crates.io/crates/mdbook`.
2626 ~/.cargo/registry/
2727 ~/.cargo/git/
2828 target/
29- key : ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
29+ key : ${{ runner.os }}-cargo-mdbook- ${{ hashFiles('**/Cargo.lock') }}
3030 - name : Install mdBook
3131 run : |
3232 export PATH=$PATH:$DEST_DIR
@@ -44,19 +44,90 @@ jobs:
4444 mkdir -p output/api
4545 cargo doc --no-deps
4646 cp -r ../target/doc/* output/api
47+ - name : Upload mdBook artifact
48+ uses : actions/upload-artifact@v4
49+ with :
50+ name : mdbook-output
51+ path : ./docs/output
52+ retention-days : 1
53+
54+ build-openapi :
55+ runs-on : ubuntu-latest
56+ steps :
57+ - uses : actions/checkout@v6
58+ - uses : actions/cache@v5
59+ with :
60+ path : |
61+ ~/.cargo/bin/
62+ ~/.cargo/registry/
63+ ~/.cargo/git/
64+ target/
65+ key : ${{ runner.os }}-cargo-openapi-${{ hashFiles('**/Cargo.lock') }}
66+ - name : Generate OpenAPI spec and setup Swagger UI
67+ run : |
68+ echo "🔧 Generating OpenAPI specification..."
69+ cargo run --example generate_openapi_spec > openapi.json
70+
71+ echo "Downloading Swagger UI..."
72+ SWAGGER_VERSION="5.10.0"
73+ wget -q "https://github.com/swagger-api/swagger-ui/archive/v${SWAGGER_VERSION}.tar.gz"
74+ tar -xzf "v${SWAGGER_VERSION}.tar.gz"
75+
76+ echo "Setting up Swagger UI for deployment..."
77+ mkdir -p swagger-ui-dist
78+ cp -r "swagger-ui-${SWAGGER_VERSION}/dist/"* swagger-ui-dist/
79+
80+ echo "Copying OpenAPI spec..."
81+ cp openapi.json swagger-ui-dist/openapi.json
82+
83+ echo "Configuring Swagger UI to use our OpenAPI spec (replacing Petstore URL)..."
84+ sed -i 's|https://petstore.swagger.io/v2/swagger.json|./openapi.json|g' swagger-ui-dist/swagger-initializer.js
85+
86+ echo "Updating page title..."
87+ sed -i 's|<title>Swagger UI</title>|<title>Syncstorage-rs API Documentation</title>|g' swagger-ui-dist/index.html
88+
89+ echo "Swagger UI setup complete!"
90+ - name : Upload Swagger UI artifact
91+ uses : actions/upload-artifact@v4
92+ with :
93+ name : swagger-ui-output
94+ path : ./swagger-ui-dist
95+ retention-days : 1
96+
97+ combine-and-prepare :
98+ needs : [build-mdbook, build-openapi]
99+ runs-on : ubuntu-latest
100+ steps :
101+ - name : Download mdBook artifact
102+ uses : actions/download-artifact@v4
103+ with :
104+ name : mdbook-output
105+ path : ./output
106+ - name : Download Swagger UI artifact
107+ uses : actions/download-artifact@v4
108+ with :
109+ name : swagger-ui-output
110+ path : ./output/swagger-ui
47111 - name : Debug output directory
48112 run : |
49- echo "Checking docs/ output:"
113+ echo "Checking combined output structure :"
50114 ls -lah output || true
51- echo "Listing output root files:"
52- find output -maxdepth 2 -type f -name "index.html" -print || true
53- - name : Upload artifact
115+ echo ""
116+ echo "Checking Rust API docs (output/api):"
117+ ls -lah output/api || true
118+ echo ""
119+ echo "Checking Swagger UI (output/swagger-ui):"
120+ ls -lah output/swagger-ui || true
121+ echo ""
122+ echo "Checking index.html files:"
123+ find output -maxdepth 3 -type f -name "index.html" -print || true
124+ - name : Upload combined artifact
54125 uses : actions/upload-pages-artifact@v4
55126 with :
56- path : ./docs/ output
127+ path : ./output
57128
58129 deploy :
59- needs : build
130+ needs : combine-and-prepare
60131 permissions :
61132 pages : write
62133 id-token : write
70141 uses : actions/deploy-pages@v4
71142 - name : Print deployed docs URL
72143 run : |
73- echo "Docs deployed to: ${{ steps.deployment.outputs.page_url }}"
144+ echo "Documentation deployed successfully."
145+ echo "Main Documentation: ${{ steps.deployment.outputs.page_url }}"
146+ echo "Rust API Docs: ${{ steps.deployment.outputs.page_url }}api/"
147+ echo "OpenAPI/Swagger UI: ${{ steps.deployment.outputs.page_url }}swagger-ui/"
0 commit comments