Skip to content

Commit c606ab8

Browse files
Copilotneilime
andcommitted
refactor: use GitHub Actions artifacts instead of base64 payload for documentation transfer
Co-authored-by: neilime <314088+neilime@users.noreply.github.com>
1 parent a7d36a8 commit c606ab8

File tree

4 files changed

+70
-42
lines changed

4 files changed

+70
-42
lines changed

.github/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,14 @@ The dispatcher workflow accepts these inputs:
9494
1. **Checkout** source repository
9595
2. **Collect** documentation files from `docs_path` and optionally `README.md`
9696
3. **Add frontmatter** with source metadata to each file
97-
4. **Bundle** documentation into compressed tar.gz
98-
5. **Encode** bundle as base64
99-
6. **Send** repository_dispatch event to public-docs with the encoded bundle
97+
4. **Upload** documentation as GitHub Actions artifact
98+
5. **Send** repository_dispatch event to public-docs with artifact metadata (name, run_id, repository)
10099

101100
## How the Receiver Works
102101

103102
1. **Listen** for `repository_dispatch` events with type `sync-documentation`
104-
2. **Validate** required inputs (source_repo, target_path, documentation)
105-
3. **Decode** and extract documentation bundle
103+
2. **Validate** required inputs (source_repo, target_path, artifact_name, run_id, repository)
104+
3. **Download** artifact from the source repository using the provided metadata
106105
4. **Inject** documentation into `application/docs/{target_path}`
107106
5. **Build** documentation site to validate
108107
6. **If build succeeds**: Commit changes and deploy to GitHub Pages

.github/workflows/sync-docs-dispatcher.yml

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ jobs:
5050
5151
echo "📦 Preparing documentation bundle from ${{ inputs.source_repo }}"
5252
53-
# Create temporary directory for documentation
54-
TEMP_DIR=$(mktemp -d)
55-
DOCS_DIR="$TEMP_DIR/docs"
56-
mkdir -p "$DOCS_DIR"
53+
# Create artifact directory
54+
ARTIFACT_DIR="documentation-artifact"
55+
mkdir -p "$ARTIFACT_DIR"
5756
5857
# Function to add frontmatter
5958
add_frontmatter() {
@@ -91,8 +90,8 @@ jobs:
9190
# Copy README if requested
9291
if [ "${{ inputs.include_readme }}" = "true" ] && [ -f "README.md" ]; then
9392
echo "📄 Including README.md"
94-
cp "README.md" "$DOCS_DIR/README.md"
95-
add_frontmatter "$DOCS_DIR/README.md" "README.md"
93+
cp "README.md" "$ARTIFACT_DIR/README.md"
94+
add_frontmatter "$ARTIFACT_DIR/README.md" "README.md"
9695
fi
9796
9897
# Copy documentation directory if it exists
@@ -102,7 +101,7 @@ jobs:
102101
# Find and copy all markdown files
103102
find "${{ inputs.docs_path }}" -type f \( -name "*.md" -o -name "*.mdx" \) | while read file; do
104103
rel_path="${file#${{ inputs.docs_path }}/}"
105-
target_file="$DOCS_DIR/$rel_path"
104+
target_file="$ARTIFACT_DIR/$rel_path"
106105
107106
# Create directory structure
108107
mkdir -p "$(dirname "$target_file")"
@@ -121,7 +120,7 @@ jobs:
121120
fi
122121
123122
# Create index file
124-
cat > "$DOCS_DIR/_index.md" << EOF
123+
cat > "$ARTIFACT_DIR/_index.md" << 'EOF'
125124
---
126125
title: ${{ inputs.source_repo }}
127126
description: Documentation for ${{ inputs.source_repo }}
@@ -136,23 +135,21 @@ jobs:
136135
**Last Synced:** $(date -u +"%Y-%m-%dT%H:%M:%SZ")
137136
EOF
138137
139-
# Create compressed archive and encode in base64
140-
cd "$TEMP_DIR"
141-
tar -czf docs.tar.gz -C docs .
142-
ENCODED=$(base64 -w 0 docs.tar.gz)
143-
144-
# Save to output (GitHub Actions has a limit, so we need to handle large content)
145-
echo "encoded_docs=$ENCODED" >> $GITHUB_OUTPUT
146-
147138
# Show summary
148139
echo "📊 Documentation bundle prepared:"
149-
find docs -type f | while read file; do
150-
echo " - ${file#docs/}"
140+
find "$ARTIFACT_DIR" -type f | while read file; do
141+
echo " - ${file#$ARTIFACT_DIR/}"
151142
done
152143
153-
# Cleanup
154-
cd -
155-
rm -rf "$TEMP_DIR"
144+
# Save artifact name for later use
145+
echo "artifact_name=docs-${{ inputs.source_repo }}-${{ github.run_id }}" >> $GITHUB_OUTPUT
146+
147+
- name: Upload documentation artifact
148+
uses: actions/upload-artifact@v4
149+
with:
150+
name: ${{ steps.prepare.outputs.artifact_name }}
151+
path: documentation-artifact/
152+
retention-days: 1
156153

157154
- name: Dispatch to public-docs
158155
uses: peter-evans/repository-dispatch@v3
@@ -165,7 +162,9 @@ jobs:
165162
"source_repo": "${{ inputs.source_repo }}",
166163
"target_path": "${{ inputs.target_path }}",
167164
"branch": "${{ inputs.branch }}",
168-
"documentation": "${{ steps.prepare.outputs.encoded_docs }}"
165+
"artifact_name": "${{ steps.prepare.outputs.artifact_name }}",
166+
"run_id": "${{ github.run_id }}",
167+
"repository": "${{ github.repository }}"
169168
}
170169
171170
- name: Summary
@@ -177,6 +176,7 @@ jobs:
177176
echo "- **Docs Path**: ${{ inputs.docs_path }}" >> $GITHUB_STEP_SUMMARY
178177
echo "- **Target Path**: ${{ inputs.target_path }}" >> $GITHUB_STEP_SUMMARY
179178
echo "- **Include README**: ${{ inputs.include_readme }}" >> $GITHUB_STEP_SUMMARY
180-
echo "- **Status**: ✅ Dispatched to public-docs" >> $GITHUB_STEP_SUMMARY
179+
echo "- **Artifact**: ${{ steps.prepare.outputs.artifact_name }}" >> $GITHUB_STEP_SUMMARY
180+
echo "- **Status**: ✅ Artifact uploaded and dispatched to public-docs" >> $GITHUB_STEP_SUMMARY
181181
echo "" >> $GITHUB_STEP_SUMMARY
182-
echo "The public-docs repository will process this documentation and publish it to the portal." >> $GITHUB_STEP_SUMMARY
182+
echo "The public-docs repository will download the artifact and publish the documentation to the portal." >> $GITHUB_STEP_SUMMARY

.github/workflows/sync-docs-receiver.yml

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,36 @@ jobs:
4343
exit 1
4444
fi
4545
46-
if [ -z "${{ github.event.client_payload.documentation }}" ]; then
47-
echo "❌ Error: documentation content is required"
46+
if [ -z "${{ github.event.client_payload.artifact_name }}" ]; then
47+
echo "❌ Error: artifact_name is required"
48+
exit 1
49+
fi
50+
51+
if [ -z "${{ github.event.client_payload.run_id }}" ]; then
52+
echo "❌ Error: run_id is required"
53+
exit 1
54+
fi
55+
56+
if [ -z "${{ github.event.client_payload.repository }}" ]; then
57+
echo "❌ Error: repository is required"
4858
exit 1
4959
fi
5060
5161
echo "✅ Input validation passed"
5262
echo "source_repo=${{ github.event.client_payload.source_repo }}" >> $GITHUB_OUTPUT
5363
echo "target_path=${{ github.event.client_payload.target_path }}" >> $GITHUB_OUTPUT
64+
echo "artifact_name=${{ github.event.client_payload.artifact_name }}" >> $GITHUB_OUTPUT
65+
echo "run_id=${{ github.event.client_payload.run_id }}" >> $GITHUB_OUTPUT
66+
echo "repository=${{ github.event.client_payload.repository }}" >> $GITHUB_OUTPUT
67+
68+
- name: Download documentation artifact
69+
uses: actions/download-artifact@v4
70+
with:
71+
name: ${{ steps.validate.outputs.artifact_name }}
72+
path: documentation-download
73+
github-token: ${{ secrets.GITHUB_TOKEN }}
74+
repository: ${{ steps.validate.outputs.repository }}
75+
run-id: ${{ steps.validate.outputs.run_id }}
5476

5577
- name: Inject documentation
5678
run: |
@@ -66,14 +88,18 @@ jobs:
6688
TARGET_DIR="application/docs/$TARGET_PATH"
6789
mkdir -p "$TARGET_DIR"
6890
69-
# Decode and write documentation files
70-
echo "${{ github.event.client_payload.documentation }}" | base64 -d | tar -xz -C "$TARGET_DIR"
71-
72-
echo "✅ Documentation injected into $TARGET_DIR"
91+
# Copy documentation files from downloaded artifact
92+
if [ -d "documentation-download" ]; then
93+
cp -r documentation-download/* "$TARGET_DIR/"
94+
echo "✅ Documentation injected into $TARGET_DIR"
95+
else
96+
echo "❌ Error: Downloaded artifact directory not found"
97+
exit 1
98+
fi
7399
74100
# List injected files
75101
echo "📁 Injected files:"
76-
find "$TARGET_DIR" -type f -name "*.md" -o -name "*.mdx" | while read file; do
102+
find "$TARGET_DIR" -type f \( -name "*.md" -o -name "*.mdx" \) | while read file; do
77103
echo " - ${file#application/docs/}"
78104
done
79105
@@ -133,6 +159,7 @@ jobs:
133159
echo "- **Source Repository**: ${{ github.event.client_payload.source_repo }}" >> $GITHUB_STEP_SUMMARY
134160
echo "- **Branch**: ${{ github.event.client_payload.branch || 'main' }}" >> $GITHUB_STEP_SUMMARY
135161
echo "- **Target Path**: ${{ github.event.client_payload.target_path }}" >> $GITHUB_STEP_SUMMARY
162+
echo "- **Artifact**: ${{ github.event.client_payload.artifact_name }}" >> $GITHUB_STEP_SUMMARY
136163
echo "- **Changes**: ${{ steps.changes.outputs.changed == 'true' && '✅ Committed and deployed' || '📄 No changes' }}" >> $GITHUB_STEP_SUMMARY
137164
echo "" >> $GITHUB_STEP_SUMMARY
138165
echo "🌐 **Documentation Portal**: [docs.hoverkraft.cloud](https://docs.hoverkraft.cloud)" >> $GITHUB_STEP_SUMMARY

application/docs/documentation-system.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ The reusable dispatcher workflow (`sync-docs-dispatcher.yml`) that projects call
2828
│ │ 1. On commit to docs/ or README.md │ │
2929
│ │ 2. Collects documentation files │ │
3030
│ │ 3. Adds source metadata frontmatter │ │
31-
│ │ 4. Creates compressed bundle (base64) │ │
32-
│ │ 5. Sends repository_dispatch event │ │
31+
│ │ 4. Uploads documentation as artifact │ │
32+
│ │ 5. Sends repository_dispatch event with metadata │ │
3333
│ └────────────────────────────────────────────────────┘ │
3434
└───────────────┬─────────────────────────────────────────┘
35-
│ repository_dispatch event
35+
│ repository_dispatch event (with artifact ref)
3636
3737
┌─────────────────────────────────────────────────────────┐
3838
│ Documentation Portal (public-docs) │
3939
│ ┌──────────────────────────────────────────────────┐ │
40-
│ │ 6. Receives documentation bundle │ │
40+
│ │ 6. Downloads artifact from source repository │ │
4141
│ │ 7. Validates and injects into docs/ │ │
4242
│ │ 8. Builds documentation site │ │
4343
│ │ 9. If build succeeds, commits and deploys │ │
@@ -49,17 +49,19 @@ The reusable dispatcher workflow (`sync-docs-dispatcher.yml`) that projects call
4949

5050
The receiver workflow (`sync-docs-receiver.yml`) in public-docs:
5151
- Listens for `repository_dispatch` events with type `sync-documentation`
52-
- Receives documentation bundle in the event payload
52+
- Downloads the documentation artifact from the source repository
5353
- Extracts and injects documentation into the appropriate location
5454
- Builds the documentation site to validate
5555
- If successful, commits changes and deploys to GitHub Pages
5656

5757
**Advantages:**
5858
- Real-time updates when documentation changes
59+
- No size limitations (artifacts can handle large documentation bundles)
5960
- Validation before publishing (build must succeed)
6061
- No direct write access to public-docs needed for project repos
61-
- Token only needs `repository_dispatch` permission
62+
- Token only needs `repo` scope for repository_dispatch and artifact access
6263
- Failed builds don't corrupt the documentation
64+
- Supports image-heavy documentation without payload size constraints
6365

6466
### Setup
6567

0 commit comments

Comments
 (0)