1+ name : Build and Deploy Documentation
2+
3+ on :
4+ workflow_call :
5+ inputs :
6+ ruby_version :
7+ description : " Ruby version for building docs"
8+ type : string
9+ default : " 3.2"
10+ enable_cache :
11+ description : " Enable bundler and other caching"
12+ type : boolean
13+ default : true
14+ publish_pages :
15+ description : " Publish to GitHub Pages"
16+ type : boolean
17+ default : true
18+ build_command :
19+ description : " Custom build command (default: auto-detect)"
20+ type : string
21+ required : false
22+ source_dir :
23+ description : " Source directory for docs"
24+ type : string
25+ default : " ."
26+ output_dir :
27+ description : " Output directory (relative to source_dir)"
28+ type : string
29+ default : " _site"
30+ secrets :
31+ GITHUB_TOKEN :
32+ description : " GitHub token for Pages deployment"
33+ required : false
34+
35+ # Set permissions for GitHub Pages deployment
36+ permissions :
37+ contents : read
38+ pages : write
39+ id-token : write
40+
41+ # Allow only one concurrent deployment
42+ concurrency :
43+ group : " pages"
44+ cancel-in-progress : false
45+
46+ jobs :
47+ build :
48+ runs-on : ubuntu-latest
49+ timeout-minutes : 30
50+ steps :
51+ - name : Checkout code
52+ uses : actions/checkout@v4
53+
54+ - name : Set up Ruby
55+ uses : ruby/setup-ruby@v1
56+ with :
57+ ruby-version : ${{ inputs.ruby_version }}
58+ bundler-cache : ${{ inputs.enable_cache }}
59+
60+ - name : Setup Pages
61+ id : pages
62+ if : inputs.publish_pages
63+ uses : actions/configure-pages@v4
64+
65+ - name : Sync DocOps Lab configs
66+ run : |
67+ if bundle exec rake -T | grep -q "labdev:sync:configs"; then
68+ bundle exec rake labdev:sync:configs
69+ fi
70+
71+ - name : Auto-detect and build documentation
72+ run : | # this block seems overwrought; let's review and trim
73+ if [ -n "${{ inputs.build_command }}" ]; then
74+ echo "Using custom build command: ${{ inputs.build_command }}"
75+ cd ${{ inputs.source_dir }}
76+ ${{ inputs.build_command }}
77+ elif [ -f "_config.yml" ]; then
78+ echo "Jekyll site detected - building with Jekyll"
79+ cd ${{ inputs.source_dir }}
80+ bundle exec jekyll build --baseurl "${{ steps.pages.outputs.base_path || '' }}"
81+ elif [ -f "config.ru" ]; then
82+ echo "Rack application detected"
83+ cd ${{ inputs.source_dir }}
84+ # For Rack apps, we might need a custom build process
85+ if bundle exec rake -T | grep -q "build\|assets"; then
86+ bundle exec rake build || bundle exec rake assets:precompile || echo "No build task found"
87+ fi
88+ elif [ -f "Rakefile" ] && bundle exec rake -T | grep -q "docs\|build"; then
89+ echo "Rakefile with docs task detected"
90+ cd ${{ inputs.source_dir }}
91+ if bundle exec rake -T | grep -q "docs"; then
92+ bundle exec rake docs
93+ elif bundle exec rake -T | grep -q "build"; then
94+ bundle exec rake build
95+ fi
96+ elif find . -name "*.adoc" -o -name "*.md" | head -1 | grep -q .; then
97+ echo "AsciiDoc/Markdown files detected - building with AsciiDoctor"
98+ cd ${{ inputs.source_dir }}
99+ # Create a simple build for AsciiDoc files
100+ mkdir -p ${{ inputs.output_dir }}
101+ if command -v asciidoctor &> /dev/null; then
102+ find . -name "*.adoc" -exec asciidoctor {} -D ${{ inputs.output_dir }} \;
103+ fi
104+ if command -v pandoc &> /dev/null; then
105+ find . -name "*.md" -exec pandoc {} -o ${{ inputs.output_dir }}/{}.html \;
106+ fi
107+ else
108+ echo "No recognized documentation format - creating minimal index"
109+ cd ${{ inputs.source_dir }}
110+ mkdir -p ${{ inputs.output_dir }}
111+ echo "<html><body><h1>Documentation</h1><p>Built from $(pwd)</p></body></html>" > ${{ inputs.output_dir }}/index.html
112+ fi
113+
114+ - name : Validate build output
115+ run : |
116+ cd ${{ inputs.source_dir }}
117+ if [ ! -d "${{ inputs.output_dir }}" ]; then
118+ echo "❌ Output directory ${{ inputs.output_dir }} not found!"
119+ exit 1
120+ fi
121+
122+ if [ ! -f "${{ inputs.output_dir }}/index.html" ]; then
123+ echo "⚠️ No index.html found in ${{ inputs.output_dir }}"
124+ # Try to find any HTML file to use as index
125+ html_file=$(find ${{ inputs.output_dir }} -name "*.html" | head -1)
126+ if [ -n "$html_file" ]; then
127+ echo "Using $html_file as index.html"
128+ cp "$html_file" "${{ inputs.output_dir }}/index.html"
129+ else
130+ echo "Creating minimal index.html"
131+ echo "<html><body><h1>Documentation</h1></body></html>" > ${{ inputs.output_dir }}/index.html
132+ fi
133+ fi
134+
135+ echo "✅ Build output validated"
136+ echo "Files in ${{ inputs.output_dir }}:"
137+ ls -la ${{ inputs.output_dir }}
138+
139+ - name : Upload Pages artifact
140+ if : inputs.publish_pages
141+ uses : actions/upload-pages-artifact@v3
142+ with :
143+ path : ${{ inputs.source_dir }}/${{ inputs.output_dir }}
144+
145+ - name : Upload build artifact
146+ if : ${{ !inputs.publish_pages }}
147+ uses : actions/upload-artifact@v4
148+ with :
149+ name : documentation
150+ path : ${{ inputs.source_dir }}/${{ inputs.output_dir }}
151+
152+ deploy :
153+ environment :
154+ name : github-pages
155+ url : ${{ steps.deployment.outputs.page_url }}
156+ runs-on : ubuntu-latest
157+ needs : build
158+ if : inputs.publish_pages
159+ timeout-minutes : 10
160+ outputs :
161+ page_url : ${{ steps.deployment.outputs.page_url }}
162+ steps :
163+ - name : Deploy to GitHub Pages
164+ id : deployment
165+ uses : actions/deploy-pages@v4
166+
167+ summary :
168+ runs-on : ubuntu-latest
169+ needs : [build, deploy]
170+ if : always()
171+ timeout-minutes : 2
172+ steps :
173+ - name : Documentation Build Summary
174+ run : |
175+ echo "## Documentation Build Results" >> $GITHUB_STEP_SUMMARY
176+ echo "" >> $GITHUB_STEP_SUMMARY
177+
178+ # Build Results
179+ if [ "${{ needs.build.result }}" = "success" ]; then
180+ echo "✅ **Build**: Documentation built successfully" >> $GITHUB_STEP_SUMMARY
181+ else
182+ echo "❌ **Build**: Documentation build failed" >> $GITHUB_STEP_SUMMARY
183+ fi
184+
185+ # Deploy Results
186+ if [ "${{ inputs.publish_pages }}" = "false" ]; then
187+ echo "⏭️ **Deploy**: GitHub Pages deployment disabled" >> $GITHUB_STEP_SUMMARY
188+ echo "📦 **Artifact**: Documentation available as build artifact" >> $GITHUB_STEP_SUMMARY
189+ elif [ "${{ needs.deploy.result }}" = "success" ]; then
190+ echo "✅ **Deploy**: Successfully deployed to GitHub Pages" >> $GITHUB_STEP_SUMMARY
191+ if [ -n "${{ needs.deploy.outputs.page_url }}" ]; then
192+ echo "🌐 **URL**: ${{ needs.deploy.outputs.page_url }}" >> $GITHUB_STEP_SUMMARY
193+ fi
194+ else
195+ echo "❌ **Deploy**: Failed to deploy to GitHub Pages" >> $GITHUB_STEP_SUMMARY
196+ fi
0 commit comments