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: every_day_view | |
on: | |
push: | |
branches: | |
- main # Этот workflow запускается при пуше в основную ветку | |
schedule: | |
- cron: '0 0 * * *' # Работает каждый день в полночь по UTC | |
jobs: | |
fetch_traffic: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Fetch traffic data from GitHub API | |
id: fetch_traffic | |
run: | | |
# Получаем данные о трафике с GitHub API, используя переменную ${{ github.repository }} | |
response=$(curl -H "Authorization: token ${{ secrets.PUBLIC_REPO_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/${{ github.repository }}/traffic/views) | |
# Извлекаем данные за текущий день | |
today=$(date -I) # Получаем текущую дату в формате YYYY-MM-DD | |
today_data=$(echo "$response" | jq --arg today "$today" '.views[] | select(.timestamp | startswith($today))') | |
echo ${today} | |
echo ${today_data} | |
# Если данные за текущий день есть, извлекаем count и uniques | |
count=$(echo "$today_data" | jq '.count') | |
uniques=$(echo "$today_data" | jq '.uniques') | |
echo ${count} | |
echo ${uniques} | |
# Извлекаем текущие значения Total Views и Unique Views из test.md | |
current_total=$(grep -oP 'Total Views All-Time-\K\d+' test.md) | |
current_unique=$(grep -oP 'Unique Views All-Time-\K\d+' test.md) | |
echo ${current_total} | |
echo ${current_unique} | |
# Прибавляем новые значения к текущим | |
new_total_views=$((current_total + count)) | |
new_total_uniques=$((current_unique + uniques)) | |
echo ${new_total_views} | |
echo ${new_total_uniques} | |
- name: Set git configuration | |
run: | | |
git config --global user.name "cortez24rus" | |
git config --global user.email "cortez24rus@gmail.com" | |
- name: Pull latest changes | |
run: | | |
git pull origin main || echo "No changes to pull" | |
- name: Commit and push changes to day_view.md | |
run: | | |
git add day_view.md | |
git commit -m "Update traffic data for $today in day_view.md" || echo "No changes to commit" | |
git push origin main |