Repository navigation
163 lines (142 loc) · 6.69 KB
/
Copy pathsync-documentation.yml
File metadata and controls
163 lines (142 loc) · 6.69 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
name: Sync Documentation from SharpMUSH
on:
schedule:
# Run daily at 6 AM UTC
- cron: '0 6 * * *'
workflow_dispatch:
# Allow manual triggering
push:
branches:
- main
paths:
- '.github/workflows/sync-documentation.yml'
- '.github/scripts/**'
env:
# SharpMUSH's help-export branch: the general help as the game serves it, plugin help
# and the plugin listings on the index topics included, with a manifest of every article.
# SharpMUSH's help-export workflow publishes it from main.
UPSTREAM_DOCS: temp-sharpmush
jobs:
sync-docs:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
# Re-arms the schedule; see "Keep the schedule alive".
actions: write
steps:
- name: Checkout current repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
- name: Fetch the SharpMUSH help export
run: git clone --depth 1 --branch help-export https://github.com/SharpMUSH/SharpMUSH.git temp-sharpmush
- name: Verify the help export layout
run: |
# Fail loudly rather than "succeeding" with an empty sync: a silent
# no-op here is indistinguishable from "upstream had no changes", and
# would hide an upstream layout change for months.
if [ ! -f "$UPSTREAM_DOCS/articles.json" ] || [ ! -d "$UPSTREAM_DOCS/help" ]; then
echo "::error::$UPSTREAM_DOCS is not a help export (no articles.json or help/). Did SharpMUSH change its help-export branch?"
exit 1
fi
missing=0
for helpfile in sharpfunc.md sharpcmd.md sharpconf.md; do
if [ ! -f "$UPSTREAM_DOCS/help/$helpfile" ]; then
echo "::error::Expected helpfile '$helpfile' is missing from $UPSTREAM_DOCS/help"
missing=1
fi
done
if [ "$missing" -ne 0 ]; then
echo "Files actually present:"
ls -la "$UPSTREAM_DOCS/help"
exit 1
fi
echo "Help export layout verified."
- name: Make scripts executable
run: chmod +x .github/scripts/*.sh
- name: Process and organize documentation
id: process_docs
run: ./.github/scripts/process_documentation.sh "$UPSTREAM_DOCS" "temp-processed"
- name: Update documentation folders
run: ./.github/scripts/update_documentation_folders.sh temp-processed
- name: Clean up temporary files
if: always()
run: rm -rf temp-sharpmush temp-processed
- name: Check for changes
id: check_changes
run: |
git add -A
if git diff --cached --quiet; then
echo "changes=false" >> $GITHUB_OUTPUT
echo "No changes detected"
else
echo "changes=true" >> $GITHUB_OUTPUT
echo "Changes detected"
git diff --cached --stat
fi
- name: Open or update the sync pull request
# main only accepts changes through a pull request, so the sync commit
# goes to a branch of its own and a PR carries it. The branch is rebuilt
# from main on every run, so an open PR always shows the latest sync.
# Guarded on main: workflow_dispatch can run on any branch, and the
# sync must be computed against main.
if: steps.check_changes.outputs.changes == 'true' && github.ref == 'refs/heads/main'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SYNC_BRANCH: docs-sync
run: |
git commit -m "docs: sync documentation from SharpMUSH/SharpMUSH" -m "Updated documentation:
- Functions: ${{ steps.process_docs.outputs.function_count }} files
- Commands: ${{ steps.process_docs.outputs.command_count }} files
- Configuration: ${{ steps.process_docs.outputs.config_count }} files
Source: SharpMUSH/SharpMUSH help-export branch
Date: $(date -u '+%Y-%m-%d %H:%M:%S UTC')"
git push --force origin "HEAD:refs/heads/$SYNC_BRANCH"
open_pr=$(gh pr list --head "$SYNC_BRANCH" --base main --state open --json url --jq '.[0].url')
if [ -n "$open_pr" ]; then
echo "Updated $open_pr"
else
gh pr create --head "$SYNC_BRANCH" --base main \
--title "docs: sync documentation from SharpMUSH/SharpMUSH" \
--body "Regenerated from the help export in SharpMUSH/SharpMUSH (its help-export branch) by the daily sync. Each run replaces this branch with a fresh sync against main, so merging this PR takes the latest helpfiles."
fi
- name: Keep the schedule alive
if: github.ref == 'refs/heads/main'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# GitHub disables a scheduled workflow after 60 days without repository
# activity. Upstream helpfiles went untouched from 2026-03-04 to
# 2026-06-14 (102 days), which is exactly what silently disabled this
# workflow once. main only takes pull requests, so instead of a
# keepalive commit this re-enables the workflow through the API,
# which resets the inactivity timer.
gh api -X PUT "repos/${{ github.repository }}/actions/workflows/sync-documentation.yml/enable"
- name: Create summary
if: always()
run: |
{
echo "## Documentation Sync Summary"
echo ""
if [ "${{ job.status }}" != "success" ]; then
echo "❌ **Sync failed** - see the failing step above"
elif [ "${{ steps.check_changes.outputs.changes }}" == "true" ]; then
echo "✅ **Documentation sync pull request opened or updated** (branch \`docs-sync\`)"
echo ""
echo "### Entries extracted:"
echo "- **Functions**: ${{ steps.process_docs.outputs.function_count }} files"
echo "- **Commands**: ${{ steps.process_docs.outputs.command_count }} files"
echo "- **Configuration**: ${{ steps.process_docs.outputs.config_count }} files"
elif [ "${{ steps.check_changes.outputs.changes }}" == "false" ]; then
echo "✅ **No changes detected** - documentation is already up to date"
else
echo "❌ **Sync failed before the change check** - see the failing step above"
fi
echo ""
echo "📅 **Sync Date**: $(date -u '+%Y-%m-%d %H:%M:%S UTC')"
} >> $GITHUB_STEP_SUMMARY