Skip to content

xfer help info from GSAS-II docs repo #56

xfer help info from GSAS-II docs repo

xfer help info from GSAS-II docs repo #56

Workflow file for this run

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