Skip to content

Updated text-Fu/env (#277) #43

Updated text-Fu/env (#277)

Updated text-Fu/env (#277) #43

Workflow file for this run

name: Sync Lessons to LabEx
on:
push:
branches: [master]
paths:
- "lessons/**/*.md"
workflow_dispatch:
inputs:
sync_path:
description: "Path to sync specific lesson file (e.g., lessons/en/logging/syslog.md). Leave empty to sync all changed files."
required: false
default: ""
type: string
jobs:
sync-lessons:
name: Sync LabEx Lessons
runs-on: ubuntu-latest
env:
LABEX_USERNAME: ${{ secrets.LABEX_USERNAME }}
LABEX_PASSWORD: ${{ secrets.LABEX_PASSWORD }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
WORKSPACE: ${{ github.workspace }}
steps:
- name: Clean workspace
run: |
mkdir -p $WORKSPACE
rm -rf "$WORKSPACE/labex-auto"
echo "Workspace cleaned"
ls -la $WORKSPACE
- name: Checkout labex-auto
uses: actions/checkout@v4
with:
repository: labex-labs/labex-auto
path: labex-auto
token: ${{ env.GH_TOKEN }}
- name: Checkout linuxjourney (for getting changed files)
uses: actions/checkout@v4
with:
path: linuxjourney
fetch-depth: 2
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
cd labex-auto
pip install -e .
- name: Verify environment variables
run: |
for var in LABEX_USERNAME LABEX_PASSWORD; do
if [ -z "${!var}" ]; then
echo "Error: Missing environment variable $var"
exit 1
fi
done
echo "All required environment variables are set"
- name: Get changed lesson files
id: changed-files
run: |
cd linuxjourney
# Get list of changed files
if [[ "${{ github.event_name }}" == "push" ]]; then
# For push events, compare current commit with previous commit
if git rev-parse --verify HEAD~1 >/dev/null 2>&1; then
CHANGED_FILES=$(git diff --name-only HEAD~1..HEAD -- 'lessons/**/*.md' | tr '\n' ' ')
else
# If HEAD~1 doesn't exist (first commit), get all lesson files
CHANGED_FILES=$(git diff --name-only --diff-filter=A HEAD -- 'lessons/**/*.md' | tr '\n' ' ')
fi
elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]] && [[ -n "${{ github.event.inputs.sync_path }}" ]]; then
# For manual trigger with specified path, use the specified path
SYNC_PATH="${{ github.event.inputs.sync_path }}"
if [[ -f "$SYNC_PATH" ]] && [[ "$SYNC_PATH" =~ ^lessons/.*\.md$ ]]; then
CHANGED_FILES="$SYNC_PATH"
else
echo "Error: Specified path does not exist or is not a valid lesson document: $SYNC_PATH"
echo "Path should start with 'lessons/' and end with '.md'"
exit 1
fi
else
# For manual trigger without specified path, get all md files in lessons directory
CHANGED_FILES=$(find lessons -name "*.md" | tr '\n' ' ')
fi
echo "Changed files: $CHANGED_FILES"
echo "changed_files=$CHANGED_FILES" >> $GITHUB_OUTPUT
- name: Sync changed lessons to LabEx
run: |
cd labex-auto
# Get list of changed files
CHANGED_FILES="${{ steps.changed-files.outputs.changed_files }}"
if [ -z "$CHANGED_FILES" ]; then
echo "No changed files, skipping sync"
exit 0
fi
echo "Starting sync of changed documents to LabEx..."
echo "Execution time: $(date)"
# Build command arguments for batch sync
FILE_ARGS=""
for file in $CHANGED_FILES; do
if [ -f "../linuxjourney/$file" ]; then
FILE_ARGS="$FILE_ARGS -f ../linuxjourney/$file"
fi
done
if [ -z "$FILE_ARGS" ]; then
echo "No valid files to sync, skipping"
exit 0
fi
# Execute batch sync command
labex linuxjourney lesson sync $FILE_ARGS
- name: Notify completion
run: |
echo "Sync task completed"
echo "Completion time: $(date)"