-
Notifications
You must be signed in to change notification settings - Fork 0
164 lines (142 loc) · 6.42 KB
/
Copy pathsync-documentation.yml
File metadata and controls
164 lines (142 loc) · 6.42 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
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:
UPSTREAM_DOCS: temp-sharpmush/SharpMUSH.Documentation/Helpfiles/SharpMUSH
jobs:
sync-docs:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout current repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
# Needed so the keepalive step can read the age of the last commit.
fetch-depth: 0
- 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: Clone SharpMUSH repository
run: |
# Only the helpfiles are needed; the rest of the tree is a large
# checkout we would immediately throw away.
git clone --depth 1 --filter=blob:none --sparse \
https://github.com/SharpMUSH/SharpMUSH.git temp-sharpmush
git -C temp-sharpmush sparse-checkout set SharpMUSH.Documentation/Helpfiles
- name: Verify upstream documentation 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 path rename for months.
if [ ! -d "$UPSTREAM_DOCS" ]; then
echo "::error::Upstream documentation folder not found at $UPSTREAM_DOCS. Did SharpMUSH/SharpMUSH move its helpfiles?"
exit 1
fi
missing=0
for helpfile in sharpfunc.md sharpcmd.md sharpconf.md; do
if [ ! -f "$UPSTREAM_DOCS/$helpfile" ]; then
echo "::error::Expected helpfile '$helpfile' is missing from $UPSTREAM_DOCS"
missing=1
fi
done
if [ "$missing" -ne 0 ]; then
echo "Files actually present:"
ls -la "$UPSTREAM_DOCS"
exit 1
fi
echo "Upstream documentation 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: Commit and push changes
# Guarded on main for the same reason as the keepalive step below:
# workflow_dispatch can run on any branch, actions/checkout takes the
# triggering ref, and this pushes HEAD to main.
if: steps.check_changes.outputs.changes == 'true' && github.ref == 'refs/heads/main'
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 repository
Date: $(date -u '+%Y-%m-%d %H:%M:%S UTC')"
git push origin HEAD:main
- name: Keep the schedule alive
if: steps.check_changes.outputs.changes != 'true' && github.ref == 'refs/heads/main'
run: |
# GitHub disables a scheduled workflow after 60 days without repository
# activity, and a sync commit is the only activity this repo normally
# gets. Upstream helpfiles went untouched from 2026-03-04 to
# 2026-06-14 (102 days), which is exactly what silently disabled this
# workflow. Commit a dated marker before the repo reaches the cutoff.
last_commit_epoch=$(git log -1 --format=%ct)
age_days=$(( ( $(date -u +%s) - last_commit_epoch ) / 86400 ))
echo "Days since last commit: $age_days"
if [ "$age_days" -lt 45 ]; then
echo "Below the 45-day keepalive threshold; nothing to do."
exit 0
fi
date -u '+%Y-%m-%dT%H:%M:%SZ' > .github/last-sync-check
git add .github/last-sync-check
git commit -m "chore: keepalive commit so the docs sync schedule is not auto-disabled"
git push origin HEAD:main
echo "keepalive=true" >> $GITHUB_ENV
- 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 successfully synced**"
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"
if [ "${keepalive:-}" == "true" ]; then
echo ""
echo "A keepalive commit was pushed to stop GitHub auto-disabling this schedule."
fi
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