-
Notifications
You must be signed in to change notification settings - Fork 0
171 lines (150 loc) · 6.93 KB
/
trigger-docs-update.yml
File metadata and controls
171 lines (150 loc) · 6.93 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
# =============================================================================
# Trigger Docs Update Workflow
# =============================================================================
#
# Sends a repository_dispatch event to the agentfront-docs repo when the
# Publish Release workflow completes successfully.
#
# NOTE: This workflow uses workflow_run trigger instead of release:published
# because releases created with GITHUB_TOKEN don't trigger other workflows
# (GitHub Actions limitation to prevent infinite loops).
#
# SETUP REQUIRED:
# Create a repository secret named DOCS_SYNC_TOKEN:
# - Go to your repo Settings > Secrets and variables > Actions
# - Create a new secret named DOCS_SYNC_TOKEN
# - Value: A GitHub PAT with 'repo' scope that has access to agentfront-docs
#
# =============================================================================
name: Trigger Docs Update
on:
workflow_run:
workflows: ["Publish Release"]
types: [completed]
permissions:
contents: read
env:
REPO_NAME: vectoriadb
jobs:
trigger-docs-sync:
# Only run if publish-release succeeded
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
- name: Get release info
id: release
uses: actions/github-script@v7
with:
script: |
// Get the workflow run to check when it completed
const workflowRun = context.payload.workflow_run;
const workflowRunCreatedAt = new Date(workflowRun.created_at);
// Get the most recent release
const { data: releases } = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 5
});
if (releases.length === 0) {
console.log('No releases found - likely a dry run. Skipping docs sync.');
core.setOutput('should_trigger', 'false');
return;
}
// Find a release created after the workflow run started (within 1 hour)
const recentRelease = releases.find(r => {
const releaseCreatedAt = new Date(r.created_at);
const timeDiff = releaseCreatedAt - workflowRunCreatedAt;
// Release should be created after workflow started but within 1 hour
return timeDiff >= 0 && timeDiff < 3600000;
});
if (!recentRelease) {
console.log('No release was created by this workflow run - likely a dry run. Skipping docs sync.');
core.setOutput('should_trigger', 'false');
return;
}
const release = recentRelease;
const tag = release.tag_name;
// Check if this is a pre-release (rc/beta) - skip docs sync for pre-releases
if (release.prerelease) {
console.log(`Release ${tag} is a pre-release. Skipping docs sync.`);
core.setOutput('should_trigger', 'false');
return;
}
// Also check tag name for rc/beta patterns (extra safety)
if (tag.includes('-rc.') || tag.includes('-beta.')) {
console.log(`Release ${tag} appears to be a pre-release based on tag name. Skipping docs sync.`);
core.setOutput('should_trigger', 'false');
return;
}
// Extract version minor from tag (e.g., "v2.1.0" -> "2.1")
const versionMatch = tag.match(/^v?(\d+)\.(\d+)/);
const versionMinor = versionMatch ? `${versionMatch[1]}.${versionMatch[2]}` : null;
// Get the commit SHA for the tag
const { data: ref } = await github.rest.git.getRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${tag}`
});
const sha = ref.object.sha;
core.setOutput('should_trigger', 'true');
core.setOutput('tag', tag);
core.setOutput('sha', sha);
core.setOutput('version_minor', versionMinor);
console.log(`Release: ${tag}`);
console.log(`SHA: ${sha}`);
console.log(`Version minor: ${versionMinor}`);
console.log('Will trigger docs sync for stable release.');
- name: Trigger docs sync
if: steps.release.outputs.should_trigger == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.DOCS_SYNC_TOKEN }}
script: |
const repoName = process.env.REPO_NAME;
const tag = '${{ steps.release.outputs.tag }}';
const sha = '${{ steps.release.outputs.sha }}';
const versionMinor = '${{ steps.release.outputs.version_minor }}';
console.log(`Triggering docs sync for ${repoName}`);
console.log(` Tag: ${tag}`);
console.log(` SHA: ${sha}`);
console.log(` Version minor: ${versionMinor}`);
try {
await github.rest.repos.createDispatchEvent({
owner: 'agentfront',
repo: 'docs',
event_type: 'sync-docs',
client_payload: {
repo: repoName,
sha: sha,
tag: tag,
version_minor: versionMinor
}
});
console.log(`Successfully triggered docs sync for ${tag}`);
} catch (error) {
console.error(`Failed to trigger docs sync: ${error.message}`);
if (error.status === 404) {
console.error('Check that DOCS_SYNC_TOKEN has access to agentfront/docs');
} else if (error.status === 401) {
console.error('Check that DOCS_SYNC_TOKEN secret is set correctly');
}
throw error;
}
- name: Summary
run: |
if [ "${{ steps.release.outputs.should_trigger }}" == "true" ]; then
echo "## Docs Sync Triggered" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Repository:** ${{ env.REPO_NAME }}" >> $GITHUB_STEP_SUMMARY
echo "- **Tag:** ${{ steps.release.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
echo "- **SHA:** ${{ steps.release.outputs.sha }}" >> $GITHUB_STEP_SUMMARY
echo "- **Version:** ${{ steps.release.outputs.version_minor }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "The [agentfront-docs](https://github.com/agentfront/docs) repository will sync the documentation shortly." >> $GITHUB_STEP_SUMMARY
else
echo "## Docs Sync Skipped" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Docs sync was skipped. This happens when:" >> $GITHUB_STEP_SUMMARY
echo "- The publish workflow was a dry run (no release created)" >> $GITHUB_STEP_SUMMARY
echo "- The release is a pre-release (rc/beta)" >> $GITHUB_STEP_SUMMARY
fi