-
Notifications
You must be signed in to change notification settings - Fork 41
145 lines (127 loc) · 5.16 KB
/
update_help.yml
File metadata and controls
145 lines (127 loc) · 5.16 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
name: xfer help info from GSAS-II docs repo
# This updates the help file to match the contents of the MDhelp directory
# in the GSAS-II-tutorials repo. It is triggered from the builddocsite.yml
# workflow in the GSAS-II-tutorials repo, or runs daily, or can be triggered manually.
on:
repository_dispatch: # run from Web API
workflow_dispatch: # manual trigger for testing
schedule:
- cron: '0 0 * * *' # Run daily at midnight UTC
permissions:
contents: write
id-token: write
pages: write
jobs:
check_files: # Check if files need updating
runs-on: ubuntu-latest
outputs:
files_changed: ${{ steps.compare.outputs.files_changed }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout tutorials repo
uses: actions/checkout@v4
with:
repository: AdvancedPhotonSource/GSAS-II-tutorials
path: _docs
ref: main
fetch-depth: 0
- name: Compare files
id: compare
run: |
# Check if any .md files in _docs/MDhelp/docs are newer than .html files in GSASII/help
# Compare using git commit timestamps rather than filesystem modification times
files_changed="false"
if [ ! -d "GSASII/help" ]; then
echo "help directory does not exist, will build"
files_changed="true"
elif [ ! -d "_docs/MDhelp/docs" ]; then
echo "docs directory does not exist"
files_changed="false"
else
# Get the newest .md file commit time and filename from the tutorials repo (single git log call)
docs_info=$(git -C _docs log -1 --format="%ct %H" --name-only -- MDhelp/docs/*.md 2>/dev/null || echo "0")
docs_newest_time=$(echo "$docs_info" | head -1 | cut -d' ' -f1)
docs_newest_file=$(echo "$docs_info" | tail -1)
# Get the newest .html file commit time and filename from the main repo (single git log call)
help_info=$(git log -1 --format="%ct %H" --name-only -- GSASII/help/*.html 2>/dev/null || echo "0")
help_newest_time=$(echo "$help_info" | head -1 | cut -d' ' -f1)
help_newest_file=$(echo "$help_info" | tail -1)
if [ "$docs_newest_time" = "0" ]; then
echo "No markdown files found in docs directory"
files_changed="false"
elif [ "$help_newest_time" = "0" ]; then
echo "No HTML files in help directory, will build"
files_changed="true"
else
# Compare timestamps (integer comparison)
if [ "$docs_newest_time" -gt "$help_newest_time" ]; then
echo "Markdown docs are newer"
echo " Newest .md file commit: $docs_newest_file ($(date -d @$docs_newest_time '+%Y-%m-%d %H:%M:%S'))"
echo " Newest .html file commit: $help_newest_file ($(date -d @$help_newest_time '+%Y-%m-%d %H:%M:%S'))"
files_changed="true"
else
echo "Help directory is current"
echo " Newest .md file commit: $docs_newest_file ($(date -d @$docs_newest_time '+%Y-%m-%d %H:%M:%S'))"
echo " Newest .html file commit: $help_newest_file ($(date -d @$help_newest_time '+%Y-%m-%d %H:%M:%S'))"
files_changed="false"
fi
fi
fi
echo "files_changed=$files_changed" >> $GITHUB_OUTPUT
echo "Files changed: $files_changed"
build: # Build web pages (only if files changed)
needs: check_files
if: needs.check_files.outputs.files_changed == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Checkout
# get the help pages from GSAS-II docs repo
uses: actions/checkout@v4
with:
repository: AdvancedPhotonSource/GSAS-II-tutorials
path: _docs
ref: main
fetch-depth: 1
- name: Python setup
uses: actions/setup-python@v3
- name: mkdocs setup
run: |
pip install mkdocs mkdocs-material python-markdown-math mkdocs-static-i18n
pip install mkdocs-to-pdf pymdown-extensions
# MD help conversion
- name: convert MDhelp
run: |
pwd
cd _docs/MDhelp
mkdocs build
python findMDanchors.py # create an anchor index
rm -rf ../../GSASII/help/assets/javascripts/
rm -rf ../../GSASII/help/assets/stylesheets/
cp -vr site/* ../../GSASII/help
cd ../../GSASII/help
pwd
ls -lt
- name: git diagnostics
run: |
pwd
git status
git diff
git add GSASII/help
echo "After add"
git status
- name: commit changes
run: |
git add GSASII/help
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git commit -m"update help files"
- name: push help into repo
run: |
git push