test tracker #33
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
- name: Create Pull Request | |
uses: peter-evans/create-pull-request@v3 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
branch: visitors-count | |
base: main | |
title: "Update visitor logs and summaries" | |
body: "This pull request updates the visitor logs and summaries." |