-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (68 loc) · 2.92 KB
/
update-docs.yml
File metadata and controls
82 lines (68 loc) · 2.92 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
name: Update Hyperliquid Documentation
on:
schedule:
- cron: '0 */3 * * *' # Every 3 hours
workflow_dispatch: # Manual trigger
permissions:
contents: write
issues: write
jobs:
update-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
ref: main
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Fetch latest documentation
id: fetch-docs
env:
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_REF_NAME: ${{ github.ref_name }}
run: uv run scripts/fetch_docs.py || echo "fetch_failed=true" >> $GITHUB_OUTPUT
continue-on-error: true
- name: Check for changes
id: verify-changed-files
run: git diff --exit-code docs/ || echo "changed=true" >> $GITHUB_OUTPUT
- name: Check for new files
id: verify-new-files
run: |
if [ -n "$(git ls-files --others --exclude-standard docs/)" ]; then
echo "new_files=true" >> $GITHUB_OUTPUT
fi
- name: Generate commit message
if: steps.verify-changed-files.outputs.changed == 'true' || steps.verify-new-files.outputs.new_files == 'true'
id: commit-msg
run: |
git add docs/
CHANGED=$(git diff --name-status --cached | grep "^M" | cut -f2 | grep -E "\.md$" | sed 's|docs/||' | paste -sd ", " -)
ADDED=$(git diff --name-status --cached | grep "^A" | cut -f2 | grep -E "\.md$" | sed 's|docs/||' | paste -sd ", " -)
DELETED=$(git diff --name-status --cached | grep "^D" | cut -f2 | grep -E "\.md$" | sed 's|docs/||' | paste -sd ", " -)
MSG="docs: sync $(date +'%Y-%m-%d')"
[ -n "$CHANGED" ] && MSG="$MSG | updated: $CHANGED"
[ -n "$ADDED" ] && MSG="$MSG | added: $ADDED"
[ -n "$DELETED" ] && MSG="$MSG | removed: $DELETED"
echo "message=$MSG" >> $GITHUB_OUTPUT
- name: Commit and push
if: steps.verify-changed-files.outputs.changed == 'true' || steps.verify-new-files.outputs.new_files == 'true'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -m "${{ steps.commit-msg.outputs.message }}"
git push
- name: Create issue on failure
if: steps.fetch-docs.outputs.fetch_failed == 'true'
uses: actions/github-script@v7
with:
script: |
const date = new Date().toISOString().split('T')[0];
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `Documentation sync failed - ${date}`,
body: `The automated documentation sync failed on ${date}.\n\nCheck the [workflow run](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}) for details.`,
labels: ['bug', 'automation']
});