@@ -31,39 +31,28 @@ jobs:
3131
3232 - name : Validate input
3333 id : validate
34- run : |
35- # Validate required inputs
36- if [ -z "${{ github.event.client_payload.source_repo }}" ]; then
37- echo "❌ Error: source_repo is required"
38- exit 1
39- fi
40-
41- if [ -z "${{ github.event.client_payload.target_path }}" ]; then
42- echo "❌ Error: target_path is required"
43- exit 1
44- fi
45-
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"
58- exit 1
59- fi
60-
61- echo "✅ Input validation passed"
62- echo "source_repo=${{ github.event.client_payload.source_repo }}" >> $GITHUB_OUTPUT
63- 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
34+ uses : actions/github-script@v7
35+ with :
36+ script : |
37+ const payload = context.payload.client_payload;
38+
39+ // Validate required inputs
40+ const required = ['source_repo', 'target_path', 'artifact_name', 'run_id', 'repository'];
41+ const missing = required.filter(field => !payload[field]);
42+
43+ if (missing.length > 0) {
44+ core.setFailed(`❌ Missing required inputs: ${missing.join(', ')}`);
45+ return;
46+ }
47+
48+ core.info('✅ Input validation passed');
49+
50+ // Set outputs
51+ core.setOutput('source_repo', payload.source_repo);
52+ core.setOutput('target_path', payload.target_path);
53+ core.setOutput('artifact_name', payload.artifact_name);
54+ core.setOutput('run_id', payload.run_id);
55+ core.setOutput('repository', payload.repository);
6756
6857 - name : Download documentation artifact
6958 uses : actions/download-artifact@v4
@@ -75,33 +64,41 @@ jobs:
7564 run-id : ${{ steps.validate.outputs.run_id }}
7665
7766 - name : Inject documentation
78- run : |
79- set -e
80-
81- SOURCE_REPO="${{ github.event.client_payload.source_repo }}"
82- TARGET_PATH="${{ github.event.client_payload.target_path }}"
83- BRANCH="${{ github.event.client_payload.branch || 'main' }}"
84-
85- echo "🚀 Starting documentation injection from $SOURCE_REPO"
86-
87- # Create target directory
88- TARGET_DIR="application/docs/$TARGET_PATH"
89- mkdir -p "$TARGET_DIR"
90-
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
99-
100- # List injected files
101- echo "📁 Injected files:"
102- find "$TARGET_DIR" -type f \( -name "*.md" -o -name "*.mdx" \) | while read file; do
103- echo " - ${file#application/docs/}"
104- done
67+ uses : actions/github-script@v7
68+ with :
69+ script : |
70+ const fs = require('fs');
71+ const path = require('path');
72+ const { execSync } = require('child_process');
73+
74+ const sourceRepo = context.payload.client_payload.source_repo;
75+ const targetPath = context.payload.client_payload.target_path;
76+ const branch = context.payload.client_payload.branch || 'main';
77+
78+ core.info(`🚀 Starting documentation injection from ${sourceRepo}`);
79+
80+ // Create target directory
81+ const targetDir = `application/docs/${targetPath}`;
82+ fs.mkdirSync(targetDir, { recursive: true });
83+
84+ // Copy documentation files from downloaded artifact
85+ if (fs.existsSync('documentation-download')) {
86+ execSync(`cp -r documentation-download/* "${targetDir}/"`);
87+ core.info(`✅ Documentation injected into ${targetDir}`);
88+
89+ // List injected files
90+ core.info('📁 Injected files:');
91+ const files = execSync(`find "${targetDir}" -type f \\( -name "*.md" -o -name "*.mdx" \\)`)
92+ .toString()
93+ .trim()
94+ .split('\n');
95+ files.forEach(file => {
96+ const relativePath = file.replace('application/docs/', '');
97+ core.info(` - ${relativePath}`);
98+ });
99+ } else {
100+ core.setFailed('❌ Error: Downloaded artifact directory not found');
101+ }
105102
106103 - name : Build documentation
107104 run : |
@@ -122,25 +119,28 @@ jobs:
122119 git diff --name-only
123120 fi
124121
125- - name : Commit changes
122+ - name : Create and merge pull request
126123 if : steps.changes.outputs.changed == 'true'
127- run : |
128- git config --local user.email "action@github.com"
129- git config --local user.name "GitHub Action"
130- git add -A
131- git commit -m "docs: sync documentation from ${{ github.event.client_payload.source_repo }}
132-
133- Source: hoverkraft-tech/${{ github.event.client_payload.source_repo }}@${{ github.event.client_payload.branch || 'main' }}
134- Target: ${{ github.event.client_payload.target_path }}
135- Timestamp: $(date -u +"%Y-%m-%dT%H:%M:%SZ")
136-
137- Triggered by repository_dispatch from ${{ github.event.client_payload.source_repo }}"
138-
139- - name : Push changes
140- if : steps.changes.outputs.changed == 'true'
141- run : |
142- git push
143- echo "✅ Changes pushed to main branch"
124+ uses : hoverkraft-tech/ci-github-common/actions/create-and-merge-pull-request@0.5.1
125+ with :
126+ github-token : ${{ secrets.GITHUB_TOKEN }}
127+ commit-message : |
128+ docs: sync documentation from ${{ github.event.client_payload.source_repo }}
129+
130+ Source: hoverkraft-tech/${{ github.event.client_payload.source_repo }}@${{ github.event.client_payload.branch || 'main' }}
131+ Target: ${{ github.event.client_payload.target_path }}
132+ Timestamp: ${{ github.event.repository.updated_at }}
133+
134+ Triggered by repository_dispatch from ${{ github.event.client_payload.source_repo }}
135+ pr-title : " docs: sync documentation from ${{ github.event.client_payload.source_repo }}"
136+ pr-body : |
137+ Automated documentation sync from `${{ github.event.client_payload.source_repo }}`.
138+
139+ - **Source**: hoverkraft-tech/${{ github.event.client_payload.source_repo }}@${{ github.event.client_payload.branch || 'main' }}
140+ - **Target**: ${{ github.event.client_payload.target_path }}
141+ - **Artifact**: ${{ github.event.client_payload.artifact_name }}
142+ branch-name : docs/sync-${{ github.event.client_payload.source_repo }}-${{ github.run_id }}
143+ auto-merge : true
144144
145145 - name : Deploy to GitHub Pages
146146 if : steps.changes.outputs.changed == 'true'
@@ -153,13 +153,23 @@ jobs:
153153 commit_message : " deploy: update from ${{ github.event.client_payload.source_repo }} [skip ci]"
154154
155155 - name : Summary
156- run : |
157- echo "## 📊 Documentation Sync Summary" >> $GITHUB_STEP_SUMMARY
158- echo "" >> $GITHUB_STEP_SUMMARY
159- echo "- **Source Repository**: ${{ github.event.client_payload.source_repo }}" >> $GITHUB_STEP_SUMMARY
160- echo "- **Branch**: ${{ github.event.client_payload.branch || 'main' }}" >> $GITHUB_STEP_SUMMARY
161- echo "- **Target Path**: ${{ github.event.client_payload.target_path }}" >> $GITHUB_STEP_SUMMARY
162- echo "- **Artifact**: ${{ github.event.client_payload.artifact_name }}" >> $GITHUB_STEP_SUMMARY
163- echo "- **Changes**: ${{ steps.changes.outputs.changed == 'true' && '✅ Committed and deployed' || '📄 No changes' }}" >> $GITHUB_STEP_SUMMARY
164- echo "" >> $GITHUB_STEP_SUMMARY
165- echo "🌐 **Documentation Portal**: [docs.hoverkraft.cloud](https://docs.hoverkraft.cloud)" >> $GITHUB_STEP_SUMMARY
156+ if : always()
157+ uses : actions/github-script@v7
158+ with :
159+ script : |
160+ const payload = context.payload.client_payload;
161+ const changed = '${{ steps.changes.outputs.changed }}' === 'true';
162+
163+ await core.summary
164+ .addHeading('📊 Documentation Sync Summary', 2)
165+ .addRaw('\n')
166+ .addList([
167+ `**Source Repository**: ${payload.source_repo}`,
168+ `**Branch**: ${payload.branch || 'main'}`,
169+ `**Target Path**: ${payload.target_path}`,
170+ `**Artifact**: ${payload.artifact_name}`,
171+ `**Changes**: ${changed ? '✅ Committed and deployed' : '📄 No changes'}`
172+ ])
173+ .addRaw('\n')
174+ .addRaw('🌐 **Documentation Portal**: [docs.hoverkraft.cloud](https://docs.hoverkraft.cloud)')
175+ .write();
0 commit comments