Skip to content

Track Visitors and Generate Summaries #35

Track Visitors and Generate Summaries

Track Visitors and Generate Summaries #35

name: Track Visitors and Generate Summaries
on:
push:
branches:
- main # Trigger the workflow on push to the main branch
schedule:
- cron: '*/10 * * * *' # Runs every 10 minutes
workflow_dispatch: # Allows manual triggering
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 to a new branch and create a pull request
- 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]"
git fetch origin
if git show-ref --verify --quiet refs/heads/visitors-count; then
git checkout visitors-count
else
git checkout -b visitors-count
git push origin visitors-count # Create the branch on the remote
fi
# Check for local changes and stash them if present
if [ -n "$(git status --porcelain)" ]; then
git stash || true
git pull origin visitors-count --rebase || true
git stash pop || true # Ignore error if no stash entries to pop or pull fails
else
git pull origin visitors-count --rebase || true # 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 pull origin visitors-count --rebase # Ensure the branch is up to date
git push origin visitors-count
fi