Skip to content

Commit ce81b23

Browse files
codemillmattCopilotCopilot
authored
Add GitHub Actions workflow for traffic reporting (#470)
* Add GitHub Actions workflow for traffic reporting * Update .github/workflows/traffic-reporting.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update .github/workflows/traffic-reporting.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add HTTPS scheme validation for REPORTING_URL in traffic-reporting workflow (#471) * Initial plan * Add HTTPS scheme validation for REPORTING_URL Co-authored-by: codemillmatt <2053639+codemillmatt@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: codemillmatt <2053639+codemillmatt@users.noreply.github.com> * Add timeout and retry configuration to curl command in traffic-reporting workflow (#472) * Initial plan * Add timeout and retry configuration to curl command Co-authored-by: codemillmatt <2053639+codemillmatt@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: codemillmatt <2053639+codemillmatt@users.noreply.github.com> * Use --silent --show-error flags in traffic-reporting curl command (#473) * Initial plan * Update curl to use --silent --show-error flags for better error handling Co-authored-by: codemillmatt <2053639+codemillmatt@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: codemillmatt <2053639+codemillmatt@users.noreply.github.com> Co-authored-by: Matt Soucoup <masoucou@microsoft.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: codemillmatt <2053639+codemillmatt@users.noreply.github.com>
1 parent dfb9d33 commit ce81b23

1 file changed

Lines changed: 89 additions & 0 deletions

File tree

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Traffic Reporting
2+
3+
on:
4+
# Run on-demand only
5+
workflow_dispatch:
6+
7+
jobs:
8+
report-traffic:
9+
runs-on: ubuntu-latest
10+
11+
permissions:
12+
actions: none
13+
checks: none
14+
contents: read
15+
deployments: none
16+
issues: none
17+
discussions: none
18+
packages: none
19+
pages: none
20+
pull-requests: none
21+
repository-projects: none
22+
security-events: none
23+
statuses: none
24+
25+
steps:
26+
- name: Fetch GitHub traffic statistics
27+
id: traffic
28+
env:
29+
GH_TOKEN: ${{ secrets.REPORTING_TOKEN }}
30+
REPO: ${{ github.repository }}
31+
run: |
32+
# Fetch page views for the last 14 days
33+
echo "Fetching traffic statistics for ${REPO}..."
34+
35+
# Get views data
36+
VIEWS_DATA=$(gh api \
37+
-H "Accept: application/vnd.github+json" \
38+
-H "X-GitHub-Api-Version: 2022-11-28" \
39+
/repos/${REPO}/traffic/views)
40+
41+
echo "Views data retrieved successfully"
42+
echo "$VIEWS_DATA" | jq '.'
43+
44+
# Save the data to a file for the next step
45+
echo "$VIEWS_DATA" > "$RUNNER_TEMP/traffic_data.json"
46+
47+
- name: Output traffic data to console
48+
run: |
49+
echo "📊 Traffic data JSON (for debugging):"
50+
echo "========================================"
51+
cat "$RUNNER_TEMP/traffic_data.json" | jq '.'
52+
echo "========================================"
53+
echo "✅ Traffic data output complete!"
54+
55+
- name: Send traffic data to reporting endpoint
56+
env:
57+
REPORTING_URL: ${{ vars.REPORTING_POST_URL }}
58+
API_KEY: ${{ secrets.REPORTING_API_KEY }}
59+
run: |
60+
echo "📤 Sending traffic data to reporting endpoint..."
61+
62+
# Validate that REPORTING_URL is set
63+
if [ -z "${REPORTING_URL}" ]; then
64+
echo "❌ Error: REPORTING_URL environment variable is not set. Please configure vars.REPORTING_POST_URL."
65+
exit 1
66+
fi
67+
68+
# Validate that REPORTING_URL uses HTTPS
69+
if [[ ! "${REPORTING_URL}" =~ ^https:// ]]; then
70+
echo "❌ Error: REPORTING_URL must start with https:// to ensure secure transmission of sensitive traffic data."
71+
exit 1
72+
fi
73+
74+
# Send POST request with API key header, reading file directly
75+
HTTP_STATUS=$(curl -f --max-time 30 --retry 3 -s -o /dev/null -w "%{http_code}" \
76+
-X POST \
77+
-H "Content-Type: application/json" \
78+
-H "X-API-KEY: ${API_KEY}" \
79+
--data-binary "@${RUNNER_TEMP}/traffic_data.json" \
80+
"${REPORTING_URL}")
81+
82+
echo "HTTP Status Code: ${HTTP_STATUS}"
83+
84+
if [ "${HTTP_STATUS}" -ge 200 ] && [ "${HTTP_STATUS}" -lt 300 ]; then
85+
echo "✅ Traffic data sent successfully!"
86+
else
87+
echo "❌ Error: Failed to send traffic data. Received HTTP status ${HTTP_STATUS}"
88+
exit 1
89+
fi

0 commit comments

Comments
 (0)