Skip to content

Track Visitors and Generate Summaries #28

Track Visitors and Generate Summaries

Track Visitors and Generate Summaries #28

name: Track Visitors and Generate Summaries
on:
push:
branches:
- main # Trigger the workflow on push to the main branch
schedule:
- cron: '*/30 * * * *' # Runs every 30 minutes
jobs:
track-and-summarize:
runs-on: ubuntu-latest # Use the latest Ubuntu environment
steps:
# Step 1: Checkout the repository
- name: Checkout repository
uses: actions/checkout@v2
# Step 2: Set up Python environment
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x' # Specify the Python version
# Step 3: Install Python dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests
# Step 4: Run the tracking script
- name: Run tracking script
run: python .github/workflows/track_visitors.py
# Step 5: Commit and push logs with considerations for local changes and stashing if needed
- name: Commit and push logs
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
# Check for local changes and stash them if present
if [ -n "$(git status --porcelain)" ]; then
git stash || true
git pull origin ${{ github.ref }} --rebase
git stash pop || true # Ignore error if no stash entries to pop or pull fails
else
git pull origin ${{ github.ref }} --rebase # Ignore error if pull fails
fi
git add -A # Add all changes including untracked files
# Check for changes before committing
if git diff-index --quiet HEAD --; then
echo "No changes to commit"
exit 0
else
# Commit the changes
git commit -m 'Update visitor logs and summaries'
git push origin HEAD:${{ github.ref }}
fi