Skip to content

Commit d8b2372

Browse files
authored
Merge pull request #301 from AdvancedPhotonSource/copilot/fix-workflow-build-issue
Fix workflow false positives by using git commit timestamps
2 parents e514c20 + 283f709 commit d8b2372

1 file changed

Lines changed: 19 additions & 21 deletions

File tree

.github/workflows/update_help.yml

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ jobs:
2323
- name: Checkout
2424
uses: actions/checkout@v4
2525
with:
26-
fetch-depth: 1
26+
fetch-depth: 0
2727

2828
- name: Checkout tutorials repo
2929
uses: actions/checkout@v4
3030
with:
3131
repository: AdvancedPhotonSource/GSAS-II-tutorials
3232
path: _docs
3333
ref: main
34-
fetch-depth: 1
34+
fetch-depth: 0
3535

3636
- name: Compare files
3737
id: compare
3838
run: |
3939
# Check if any .md files in _docs/MDhelp/docs are newer than .html files in GSASII/help
40-
# Compare using filesystem modification times rather than git history
40+
# Compare using git commit timestamps rather than filesystem modification times
4141
files_changed="false"
4242
4343
if [ ! -d "GSASII/help" ]; then
@@ -47,35 +47,33 @@ jobs:
4747
echo "docs directory does not exist"
4848
files_changed="false"
4949
else
50-
# Get the newest .md file in the docs directory
51-
docs_newest=$(find _docs/MDhelp/docs -name "*.md" -type f -printf '%T@ %p\n' 2>/dev/null | sort -rn | head -1)
50+
# Get the newest .md file commit time and filename from the tutorials repo (single git log call)
51+
docs_info=$(git -C _docs log -1 --format="%ct %H" --name-only -- MDhelp/docs/*.md 2>/dev/null || echo "0")
52+
docs_newest_time=$(echo "$docs_info" | head -1 | cut -d' ' -f1)
53+
docs_newest_file=$(echo "$docs_info" | tail -1)
5254
53-
# Get the newest .html file in the help directory
54-
help_newest=$(find GSASII/help -name "*.html" -type f -printf '%T@ %p\n' 2>/dev/null | sort -rn | head -1)
55+
# Get the newest .html file commit time and filename from the main repo (single git log call)
56+
help_info=$(git log -1 --format="%ct %H" --name-only -- GSASII/help/*.html 2>/dev/null || echo "0")
57+
help_newest_time=$(echo "$help_info" | head -1 | cut -d' ' -f1)
58+
help_newest_file=$(echo "$help_info" | tail -1)
5559
56-
if [ -z "$docs_newest" ]; then
60+
if [ "$docs_newest_time" = "0" ]; then
5761
echo "No markdown files found in docs directory"
5862
files_changed="false"
59-
elif [ -z "$help_newest" ]; then
63+
elif [ "$help_newest_time" = "0" ]; then
6064
echo "No HTML files in help directory, will build"
6165
files_changed="true"
6266
else
63-
# Extract timestamps (epoch seconds with decimal)
64-
docs_time=$(echo "$docs_newest" | cut -d' ' -f1)
65-
help_time=$(echo "$help_newest" | cut -d' ' -f1)
66-
docs_file=$(echo "$docs_newest" | cut -d' ' -f2-)
67-
help_file=$(echo "$help_newest" | cut -d' ' -f2-)
68-
69-
# Compare timestamps (using awk for floating point comparison)
70-
if awk "BEGIN {exit !($docs_time > $help_time)}"; then
67+
# Compare timestamps (integer comparison)
68+
if [ "$docs_newest_time" -gt "$help_newest_time" ]; then
7169
echo "Markdown docs are newer"
72-
echo " Newest .md file: $docs_file ($(date -d @${docs_time%.*} '+%Y-%m-%d %H:%M:%S'))"
73-
echo " Newest .html file: $help_file ($(date -d @${help_time%.*} '+%Y-%m-%d %H:%M:%S'))"
70+
echo " Newest .md file commit: $docs_newest_file ($(date -d @$docs_newest_time '+%Y-%m-%d %H:%M:%S'))"
71+
echo " Newest .html file commit: $help_newest_file ($(date -d @$help_newest_time '+%Y-%m-%d %H:%M:%S'))"
7472
files_changed="true"
7573
else
7674
echo "Help directory is current"
77-
echo " Newest .md file: $docs_file ($(date -d @${docs_time%.*} '+%Y-%m-%d %H:%M:%S'))"
78-
echo " Newest .html file: $help_file ($(date -d @${help_time%.*} '+%Y-%m-%d %H:%M:%S'))"
75+
echo " Newest .md file commit: $docs_newest_file ($(date -d @$docs_newest_time '+%Y-%m-%d %H:%M:%S'))"
76+
echo " Newest .html file commit: $help_newest_file ($(date -d @$help_newest_time '+%Y-%m-%d %H:%M:%S'))"
7977
files_changed="false"
8078
fi
8179
fi

0 commit comments

Comments
 (0)