Skip to content

xfer help info from GSAS-II docs repo #49

xfer help info from GSAS-II docs repo

xfer help info from GSAS-II docs repo #49

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: 1
- name: Checkout tutorials repo
uses: actions/checkout@v4
with:
repository: AdvancedPhotonSource/GSAS-II-tutorials
path: _docs
ref: main
fetch-depth: 1
- 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 filesystem modification times rather than git history
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 in the docs directory
docs_newest=$(find _docs/MDhelp/docs -name "*.md" -type f -printf '%T@ %p\n' 2>/dev/null | sort -rn | head -1)
# Get the newest .html file in the help directory
help_newest=$(find GSASII/help -name "*.html" -type f -printf '%T@ %p\n' 2>/dev/null | sort -rn | head -1)
if [ -z "$docs_newest" ]; then
echo "No markdown files found in docs directory"
files_changed="false"
elif [ -z "$help_newest" ]; then
echo "No HTML files in help directory, will build"
files_changed="true"
else
# Extract timestamps (epoch seconds with decimal)
docs_time=$(echo "$docs_newest" | cut -d' ' -f1)
help_time=$(echo "$help_newest" | cut -d' ' -f1)
docs_file=$(echo "$docs_newest" | cut -d' ' -f2-)
help_file=$(echo "$help_newest" | cut -d' ' -f2-)
# Compare timestamps (using awk for floating point comparison)
if awk "BEGIN {exit !($docs_time > $help_time)}"; then
echo "Markdown docs are newer"
echo " Newest .md file: $docs_file ($(date -d @${docs_time%.*} '+%Y-%m-%d %H:%M:%S'))"
echo " Newest .html file: $help_file ($(date -d @${help_time%.*} '+%Y-%m-%d %H:%M:%S'))"
files_changed="true"
else
echo "Help directory is current"
echo " Newest .md file: $docs_file ($(date -d @${docs_time%.*} '+%Y-%m-%d %H:%M:%S'))"
echo " Newest .html file: $help_file ($(date -d @${help_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