-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
35 additions
and
63 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,23 @@ | ||
name: Repository Traffic to PostHog | ||
|
||
name: Build and Push Usage Service Docker Images | ||
on: | ||
schedule: | ||
- cron: '0 0 * * *' # Run daily at midnight | ||
workflow_run: | ||
workflows: [ "Bump Usage Service Version" ] | ||
types: | ||
- completed | ||
workflow_dispatch: | ||
|
||
jobs: | ||
send_traffic_data: | ||
docker_push_chatbot: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Get repository traffic data and send to PostHog | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }} | ||
run: | | ||
# Get the repository owner and name | ||
OWNER=$(echo "${{ github.repository }}" | cut -d'/' -f1) | ||
REPO=$(echo "${{ github.repository }}" | cut -d'/' -f2) | ||
# Get the clone traffic data | ||
CLONES=$(gh api -H "Accept: application/vnd.github+json" /repos/$OWNER/$REPO/traffic/clones | jq '.count') | ||
UNIQUE_CLONES=$(gh api -H "Accept: application/vnd.github+json" /repos/$OWNER/$REPO/traffic/clones | jq '.uniques') | ||
# Get the view traffic data | ||
VIEWS=$(gh api -H "Accept: application/vnd.github+json" /repos/$OWNER/$REPO/traffic/views | jq '.count') | ||
UNIQUE_VIEWS=$(gh api -H "Accept: application/vnd.github+json" /repos/$OWNER/$REPO/traffic/views | jq '.uniques') | ||
# Prepare the payload for PostHog | ||
PAYLOAD=$(cat <<EOF | ||
{ | ||
"event": "repository_traffic", | ||
"properties": { | ||
"clones": $CLONES, | ||
"unique_clones": $UNIQUE_CLONES, | ||
"views": $VIEWS, | ||
"unique_views": $UNIQUE_VIEWS, | ||
"repository": "${{ github.repository }}" | ||
} | ||
} | ||
EOF | ||
) | ||
# Send the payload to PostHog | ||
curl -X POST -H "Content-Type: application/json" -d "$PAYLOAD" "https://app.posthog.com/capture?api_key=${{ secrets.POSTHOG_API_KEY }}" | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
- run: make chatbot_push | ||
working-directory: usage-service/usage-server |
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