-
Notifications
You must be signed in to change notification settings - Fork 52
74 lines (65 loc) · 2.65 KB
/
trigger-docs-update.yml
File metadata and controls
74 lines (65 loc) · 2.65 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
# Triggers documentation repository workflow when Polymesh main branch is updated
# Uses GitHub API directly for cross-repository communication
name: Trigger Documentation Update on Polymesh develop Update
on:
push:
branches: [ develop ]
jobs:
trigger-docs-update:
runs-on: ubuntu-latest
steps:
- name: Trigger documentation repository workflow
env:
GITHUB_TOKEN: ${{ secrets.DOCS_REPO_TRIGGER_TOKEN }}
TARGET_REPO: "PolymeshAssociation/polymesh-core-docs"
EVENT_TYPE: "polymesh-develop-updated"
run: |
#!/bin/bash
# Script to trigger repository dispatch event in documentation repository
# Uses GitHub REST API for secure cross-repository communication
# Validate required environment variables
if [[ -z "$GITHUB_TOKEN" ]]; then
echo "Error: DOCS_REPO_TRIGGER_TOKEN secret is required"
exit 1
fi
if [[ -z "$TARGET_REPO" ]]; then
echo "Error: TARGET_REPO environment variable is required"
exit 1
fi
# Prepare payload with current commit information
PAYLOAD=$(cat <<EOF
{
"event_type": "$EVENT_TYPE",
"client_payload": {
"polymesh_ref": "$GITHUB_SHA",
"polymesh_branch": "$GITHUB_REF_NAME",
"polymesh_repository": "$GITHUB_REPOSITORY",
"triggered_by": "$GITHUB_ACTOR",
"workflow_run_id": "$GITHUB_RUN_ID",
"timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
}
}
EOF
)
echo "Triggering documentation update in repository: $TARGET_REPO"
echo "Event type: $EVENT_TYPE"
echo "Polymesh commit SHA: $GITHUB_SHA"
# Send repository dispatch event using GitHub API
HTTP_STATUS=$(curl -s -w "%{http_code}" -o response.json \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $GITHUB_TOKEN" \
-H "User-Agent: GitHub-Actions-Trigger" \
-d "$PAYLOAD" \
"https://api.github.com/repos/$TARGET_REPO/dispatches")
# Check response status
if [[ "$HTTP_STATUS" -eq 204 ]]; then
echo "✅ Successfully triggered documentation update in $TARGET_REPO"
else
echo "❌ Failed to trigger workflow. HTTP Status: $HTTP_STATUS"
echo "Response:"
cat response.json
exit 1
fi
# Clean up temporary files
rm -f response.json