-
Notifications
You must be signed in to change notification settings - Fork 6
262 lines (226 loc) · 10.9 KB
/
build-and-deploy-tutorial.yml
File metadata and controls
262 lines (226 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# GitHub Actions workflow for building and deploying MicroProfile Tutorial documentation
# This workflow uses Antora to generate a static documentation site from AsciiDoc sources
# and deploys it to GitHub Pages
name: Generate MicroProfile Tutorial
on:
# Allows manual triggering of the workflow from the GitHub Actions tab
workflow_dispatch:
# Automatically runs when code is pushed to the main branch
push:
branches:
- main
# Runs on pull requests to validate the build (but doesn't deploy)
pull_request:
branches:
- main
# Prevent concurrent deployments to avoid conflicts and race conditions
# Only allow one deployment at a time, but don't cancel in-progress runs
# as we want to allow production deployments to complete
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
# Validation job for pull requests - builds but doesn't deploy
validate-build:
# Only run this job on pull requests
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
# Minimal permissions needed for PR validation
permissions:
contents: read # Required to read repository contents
steps:
# Checkout the repository source code
- name: Checkout Repository
uses: actions/checkout@v4
# Set up Node.js runtime environment for Antora
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20' # LTS version compatible with Antora
cache: 'npm' # Cache npm dependencies for faster builds
# Set up Ruby for AsciiDoc extensions
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
bundler-cache: false
# Install Antora CLI, site generator, and advanced extensions
- name: Install Antora and Extensions
run: |
npm install @antora/cli @antora/site-generator-default
npm install @antora/lunr-extension @antora/pdf-extension @asciidoctor/tabs
gem install asciidoctor-pdf asciidoctor-kroki asciidoctor-plantuml
# Make update-repo-url.sh executable and run it to update URLs
- name: Make update-repo-url.sh executable
run: chmod +x ./update-repo-url.sh
- name: Update repository URLs in configuration files
run: ./update-repo-url.sh
# Generate the documentation site to validate it builds correctly
- name: Validate Site Generation
run: npx antora --fetch --stacktrace antora-assembler.yml
# Verify the build output exists
- name: Verify Build Output
run: |
if [ -d "./build/site" ]; then
echo "✅ Site generated successfully"
ls -la ./build/site
# Check if PDF was generated (it's actually generated as index.pdf in _exports)
echo "🔍 Looking for generated PDF files..."
find . -name "*.pdf" -type f
if [ -f "./build/assembler/microprofile-tutorial/6.1/_exports/index.pdf" ] || [ -f "./build/site/microprofile-tutorial/6.1/_exports/index.pdf" ]; then
echo "✅ PDF generated successfully (found as index.pdf in _exports)"
else
echo "⚠️ PDF not generated in expected location"
find . -name "*.pdf" -type f
fi
else
echo "❌ Site generation failed - output directory not found"
exit 1
fi
# Main job that builds the Antora documentation and deploys to GitHub Pages
build-and-deploy:
# Only deploy to Pages on pushes to main branch, not on PRs
# This prevents deploying from pull request builds
if: github.event_name != 'pull_request'
# Use GitHub Pages environment for deployment tracking and protection
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
# GitHub token permissions required for this workflow
permissions:
id-token: write # Required for OIDC authentication to GitHub Pages
contents: read # Required to read repository contents and checkout code
pages: write # Required to deploy artifacts to GitHub Pages
steps:
# Checkout the repository source code
- name: Checkout Repository
uses: actions/checkout@v4
# Set up Node.js runtime environment for Antora
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20' # LTS version compatible with Antora
cache: 'npm' # Cache npm dependencies for faster builds
# Set up Ruby for AsciiDoc extensions
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
bundler-cache: false
# Install Antora CLI, site generator, and advanced extensions
- name: Install Antora and Extensions
run: |
npm install @antora/cli @antora/site-generator-default
npm install @antora/lunr-extension @antora/pdf-extension @asciidoctor/tabs
gem install asciidoctor-pdf asciidoctor-kroki asciidoctor-plantuml
# Verify that Antora was installed correctly (useful for debugging)
- name: Verify Antora Installation
run: npm list @antora/cli @antora/site-generator-default || echo "Antora packages are not installed."
# Clean previous build directory to ensure fresh generation
- name: Clean previous build directory
run: |
if [ -d "./build" ]; then
rm -rf ./build
echo "✅ Previous build directory cleaned for fresh generation"
else
echo "ℹ️ No previous build directory found"
fi
# Generate the documentation site using Antora playbook configuration
# --fetch: Downloads remote content sources defined in playbook
# --stacktrace: Shows detailed error information for troubleshooting
- name: Generate Site with Antora
run: npx antora --fetch --stacktrace antora-assembler.yml
# Ensure GitHub Pages is enabled and configure deployment settings
# This will enable Pages if it's not already enabled and set the source to GitHub Actions
- name: Setup Pages
uses: actions/configure-pages@v5
with:
# Automatically enable Pages if not already enabled
enablement: true
# Set the publishing source to GitHub Actions (vs. legacy branch-based)
# This ensures the repository is configured to accept deployments from Actions
token: ${{ secrets.GITHUB_TOKEN }}
# Verify Pages configuration and provide helpful debugging info
- name: Verify Pages Configuration
run: |
echo "🔧 GitHub Pages Configuration Check:"
echo "Repository: ${{ github.repository }}"
echo "Branch: ${{ github.ref_name }}"
echo "Event: ${{ github.event_name }}"
echo "Actor: ${{ github.actor }}"
echo ""
echo "✅ Pages setup completed successfully"
echo "📄 Site will be deployed from ./build/site directory"
# Verify PDF generation and copy to correct location for download
- name: Verify PDF generation and copy to correct location for download
run: |
echo "🔍 Looking for generated PDF files..."
find . -name "*.pdf" -type f
# The PDF is actually generated as index.pdf in _exports subdirectory
PDF_SOURCE=""
if [ -f "./build/assembler/microprofile-tutorial/6.1/_exports/index.pdf" ]; then
PDF_SOURCE="./build/assembler/microprofile-tutorial/6.1/_exports/index.pdf"
echo "✅ PDF found in assembler/_exports location"
elif [ -f "./build/site/microprofile-tutorial/6.1/_exports/index.pdf" ]; then
PDF_SOURCE="./build/site/microprofile-tutorial/6.1/_exports/index.pdf"
echo "✅ PDF found in site/_exports location"
else
echo "❌ PDF not found in expected locations"
echo "Available PDF files:"
find . -name "*.pdf" -type f
exit 1
fi
if [ -n "$PDF_SOURCE" ]; then
PDF_SIZE=$(stat -f%z "$PDF_SOURCE" 2>/dev/null || stat -c%s "$PDF_SOURCE")
echo "PDF Size: ${PDF_SIZE} bytes"
# Copy PDF to the exact location the download link expects
# The download link is ../../microprofile-tutorial/6.1/microprofile-tutorial.pdf
# From /microprofile-tutorial/6.1/index.html, this resolves to /microprofile-tutorial/6.1/microprofile-tutorial.pdf
mkdir -p "./build/site/microprofile-tutorial/6.1/"
cp "$PDF_SOURCE" "./build/site/microprofile-tutorial/6.1/microprofile-tutorial.pdf"
echo "✅ PDF copied to download location: /microprofile-tutorial/6.1/microprofile-tutorial.pdf"
# Verify the copy was successful
if [ -f "./build/site/microprofile-tutorial/6.1/microprofile-tutorial.pdf" ]; then
echo "✅ PDF verification successful"
ls -la ./build/site/microprofile-tutorial/6.1/microprofile-tutorial.pdf
else
echo "❌ PDF copy failed"
exit 1
fi
# Create .htaccess for GitHub Pages to ensure proper PDF serving
cat > ./build/site/.htaccess << 'EOF'
# Set proper MIME type for PDF files
<Files "*.pdf">
AddType application/pdf .pdf
Header set Content-Type "application/pdf"
Header set Content-Disposition "attachment; filename=\"microprofile-tutorial.pdf\""
Header set Cache-Control "no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "0"
</Files>
EOF
# Also create PDF-specific .htaccess in the PDF directory
cp supplemental-ui/pdf-htaccess "./build/site/microprofile-tutorial/6.1/.htaccess"
echo "✅ PDF-specific .htaccess created"
echo "✅ PDF download headers configured"
fi
# Copy assembler directory to site for PDF access via UI bundle
- name: Copy assembler directory to site for PDF access
run: |
if [ -d "./build/assembler" ]; then
cp -r ./build/assembler ./build/site/
echo "✅ Assembler directory copied to site for web access"
ls -la ./build/site/assembler/microprofile-tutorial/6.1/
else
echo "⚠️ Assembler directory not found"
fi
# Upload the generated Antora site as a GitHub Pages artifact
- name: Upload Antora Site to GitHub Pages
uses: actions/upload-pages-artifact@v3
with:
path: ./build/site # Antora's default output directory
# Deploy the uploaded artifact to GitHub Pages
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4