-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (129 loc) · 6.14 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
name: Fetch GitHub Traffic Data - taylanu (2024.03.25)
on:
schedule:
# - cron: '0 0 * * *' # Runs every day at midnight UTC
- cron: "0 0 * * 0" # Runs every Sunday at midnight UTC
push:
branches:
- main
jobs:
fetch-traffic:
runs-on: ubuntu-latest
strategy:
matrix:
repo_name: [
"taylauna/ArboretumID",
# "aws-samples/amazon-q-in-connect-s3-integration-template",
] # Add more repositories as needed
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Fetch traffic data for each Repo
id: traffic
run: |
AUTH_HEADER="Authorization: token ${{ secrets.PAT }}"
for repo in ${{ matrix.repo_name }}; do
mkdir -p "$repo"
cd "$repo"
for i in {0..13}; do
DATE=$(date -d "$i days ago" +%Y-%m-%d)
API_URL_CLONES="https://api.github.com/repos/$repo/traffic/clones?per=day×tamp=${DATE}"
API_URL_TOP_PATHS="https://api.github.com/repos/$repo/traffic/popular/paths?per=day×tamp=${DATE}"
API_URL_TOP_REFERRERS="https://api.github.com/repos/$repo/traffic/popular/referrers?per=day×tamp=${DATE}"
API_URL_VIEWS="https://api.github.com/repos/$repo/traffic/views?per=day×tamp=${DATE}"
curl -sSL -H "${AUTH_HEADER}" "${API_URL_CLONES}" > "clones_${DATE}.json"
curl -sSL -H "${AUTH_HEADER}" "${API_URL_TOP_PATHS}" > "top_paths_${DATE}.json"
curl -sSL -H "${AUTH_HEADER}" "${API_URL_TOP_REFERRERS}" > "top_referrers_${DATE}.json"
curl -sSL -H "${AUTH_HEADER}" "${API_URL_VIEWS}" > "views_${DATE}.json"
done
cd ..
done
- name: Debug - Check contents of current directory
run: |
ls -lR
- name: GIT commit and push docs
if: success() # Only run if previous steps are successful
env:
CI_COMMIT_MESSAGE: "Add Traffic Data for ${{ matrix.repo_name }} on $(date +%Y-%m-%d)"
CI_COMMIT_AUTHOR: taylanu
run: |
git config --global user.name "${{ env.CI_COMMIT_AUTHOR }}"
git config --global user.email "${{ env.CI_COMMIT_AUTHOR }}@users.noreply.github.com"
git config --global advice.addIgnoredFile false # Ensure untracked files are added
# Pull Latest Remote
git pull origin main
# Check if there are changes
if git status --porcelain | grep .; then
git add .
git commit -m "${{ env.CI_COMMIT_MESSAGE }}"
git push origin main # push to remote
else
echo "No changes to commit."
fi
# name: Fetch GitHub Traffic Data - taylanu (Self + Repo)
# on:
# schedule:
# # - cron: '0 0 * * *' # Runs every day at midnight UTC
# - cron: '0 0 * * 0' # Runs every Sunday at midnight UTC
# push:
# branches:
# - main
# jobs:
# fetch-traffic:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout repository
# uses: actions/checkout@v4
# - name: Check contents of current directory
# run: ls
# - name: Fetch traffic data
# id: traffic
# run: |
# API_URL_CLONES="https://api.github.com/repos/${{ github.repository }}/traffic/clones"
# API_URL_TOP_PATHS="https://api.github.com/repos/${{ github.repository }}/traffic/popular/paths"
# API_URL_TOP_REFERRERS="https://api.github.com/repos/${{ github.repository }}/traffic/popular/referrers"
# API_URL_VIEWS="https://api.github.com/repos/${{ github.repository }}/traffic/views"
# AUTH_HEADER="Authorization: token ${{ secrets.PAT }}"
# mkdir -p traffic_data
# # curl -sSL -H "${AUTH_HEADER}" "${API_URL_CLONES}" > traffic_data/clones.json
# # curl -sSL -H "${AUTH_HEADER}" "${API_URL_TOP_PATHS}" > traffic_data/top_paths.json
# # curl -sSL -H "${AUTH_HEADER}" "${API_URL_TOP_REFERRERS}" > traffic_data/top_referrers.json
# # curl -sSL -H "${AUTH_HEADER}" "${API_URL_VIEWS}" > traffic_data/views.json
# # For the past 14 days, write a file with Date Timestamp
# for i in {0..13}; do
# DATE=$(date -d "$i days ago" +%Y-%m-%d)
# curl -sSL -H "${AUTH_HEADER}" "${API_URL_CLONES}?per=day×tamp=${DATE}" > "traffic_data/clones_${DATE}.json"
# curl -sSL -H "${AUTH_HEADER}" "${API_URL_TOP_PATHS}?per=day×tamp=${DATE}" > "traffic_data/top_paths_${DATE}.json"
# curl -sSL -H "${AUTH_HEADER}" "${API_URL_TOP_REFERRERS}?per=day×tamp=${DATE}" > "traffic_data/top_referrers_${DATE}.json"
# curl -sSL -H "${AUTH_HEADER}" "${API_URL_VIEWS}?per=day×tamp=${DATE}" > "traffic_data/views_${DATE}.json"
# done
# - name: Debug - Check contents of traffic_data directory
# run: |
# ls
# ls -l traffic_data
# # cat traffic_data/*.json # Very Verbose. Keep commented unless debugging.
# # Github Commit Changed Files
# # https://joht.github.io/johtizen/build/2022/01/20/github-actions-push-into-repository.html#git-commands
# - name: GIT commit and push docs
# env:
# CI_COMMIT_MESSAGE: "Add Traffic Data on $(date +%Y-%m-%d)"
# CI_COMMIT_AUTHOR: taylanu
# run: |
# git config --global user.name "${{ env.CI_COMMIT_AUTHOR }}"
# git config --global user.email "${{ env.CI_COMMIT_AUTHOR }}@users.noreply.github.com"
# # Check if there are changes
# if git diff --quiet; then
# echo "No changes to commit."
# else
# git add traffic_data
# git commit -m "${{ env.CI_COMMIT_MESSAGE }}"
# git push
# fi
# - name: Commit and push changes
# uses: ad-m/[email protected]
# with:
# # Valid Inputs: ['github_token', 'github_url', 'ssh', 'repository', 'branch', 'force', 'force_with_lease', 'atomic', 'tags', 'directory']
# github_token: ${{ secrets.PAT }}
# repository: ${{ github.repository }}
# branch: main
# directory: traffic_data