Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge working actions into branch for upstream PR #124

Merged
merged 66 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
8914529
Create metrics.md
jukent Mar 11, 2024
a19462d
Update footer-menu.html with metrics
jukent Mar 11, 2024
cdc525c
Update footer-menu.html
jukent Mar 11, 2024
1918bae
Delete portal/metrics.md
jukent Mar 11, 2024
d5c040c
Merge pull request #119 from jukent/metrics-api
jukent Mar 11, 2024
3e3f9ed
Merge pull request #120 from jukent/metrics-api
jukent Mar 11, 2024
47da077
Merge pull request #121 from jukent/metrics-api
jukent Mar 11, 2024
f2a4612
[pre-commit.ci] pre-commit autoupdate (#409)
pre-commit-ci[bot] Mar 13, 2024
402188c
Merge pull request #122 from jukent/metrics-api
jukent Mar 13, 2024
de6db3e
Update automate-metrics.yaml to use wget
jukent Mar 13, 2024
57b494f
Merge branch 'ProjectPythia:main' into main
jukent Mar 13, 2024
949ca30
Update automate-metrics.yaml
jukent Mar 13, 2024
b9335c2
Merge pull request #123 from jukent/metrics-api
jukent Mar 15, 2024
bb435b5
Update automate-metrics.yaml
jukent Mar 15, 2024
efbcb3e
Update automate-metrics.yaml fix file name
jukent Mar 15, 2024
5975536
Update automate-metrics.yaml
jukent Mar 15, 2024
5000655
Update automate-metrics.yaml
jukent Mar 15, 2024
6e3d0d5
Update automate-metrics.yaml
jukent Mar 15, 2024
7158ed6
Update get-metrics.py
jukent Mar 15, 2024
2d60b08
Update get-metrics.py
jukent Mar 15, 2024
3896a5e
Update automate-metrics.yaml
jukent Mar 15, 2024
6536a35
Update get-metrics.py
jukent Mar 15, 2024
9aeb2ac
Update automate-metrics.yaml
jukent Mar 15, 2024
5055a20
Update get-metrics.py
jukent Mar 15, 2024
5e51a43
Update get-metrics.py
jukent Mar 15, 2024
c3109d7
Update get-metrics.py
jukent Mar 15, 2024
f87d309
Update get-metrics.py
jukent Mar 15, 2024
c35f622
Update get-metrics.py
jukent Mar 15, 2024
3259172
Update get-metrics.py
jukent Mar 15, 2024
03d4c64
Update get-metrics.py
jukent Mar 15, 2024
b8a47fc
Update get-metrics.py
jukent Mar 15, 2024
6d0defc
Update get-metrics.py
jukent Mar 15, 2024
98d72b1
Update get-metrics.py
jukent Mar 15, 2024
1bd42b6
Update get-metrics.py
jukent Mar 15, 2024
3c4333b
Update get-metrics.py
jukent Mar 15, 2024
6778a5f
Update get-metrics.py to build dict
jukent Mar 15, 2024
83cc193
Update automate-metrics.yaml
jukent Mar 15, 2024
e601526
Update get-metrics.py
jukent Mar 15, 2024
49ee717
Update get-metrics.py
jukent Mar 15, 2024
7a4a66d
Update automate-metrics.yaml
jukent Mar 15, 2024
fe4f03b
Update get-metrics.py
jukent Mar 15, 2024
3779b3a
Update get-metrics.py
jukent Mar 15, 2024
b0e94ec
Update get-metrics.py
jukent Mar 15, 2024
7dc9faa
Update get-metrics.py
jukent Mar 15, 2024
c1cf304
Update automate-metrics.yaml
jukent Mar 15, 2024
8d65de2
Update get-metrics.py
jukent Mar 15, 2024
2742484
Update get-metrics.py
jukent Mar 15, 2024
def65be
Update get-metrics.py
jukent Mar 15, 2024
4d738c7
Update get-metrics.py
jukent Mar 15, 2024
151f56c
Update get-metrics.py
jukent Mar 15, 2024
9252577
Update get-metrics.py
jukent Mar 15, 2024
41b9f35
Update get-metrics.py
jukent Mar 15, 2024
32763a4
Update get-metrics.py
jukent Mar 15, 2024
983e830
Update get-metrics.py
jukent Mar 15, 2024
ababfc3
Update get-metrics.py
jukent Mar 15, 2024
d451527
Update get-metrics.py
jukent Mar 15, 2024
c1516f6
Update get-metrics.py
jukent Mar 15, 2024
6958ce4
Update automate-metrics.yaml
jukent Mar 15, 2024
39743c4
Update write-metrics-md.py
jukent Mar 15, 2024
404ff7f
Update get-metrics.py
jukent Mar 15, 2024
f419437
Update automate-metrics.yaml
jukent Mar 15, 2024
80331d0
Update nightly-build.yaml
jukent Mar 15, 2024
0b03712
Update publish-site.yaml
jukent Mar 15, 2024
715a3c4
Update trigger-preview.yaml
jukent Mar 15, 2024
eed44c5
Update trigger-site-build.yaml
jukent Mar 15, 2024
c000323
change from workflow_dispatch to workflow_call
jukent Mar 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions .github/workflows/automate-metrics.yaml
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
name: Update User Metrics

on:
workflow_dispatch:
workflow_call:

env:
portal_id: ${{ secrets.GA4_PORTAL_ID }}
foundations_id: ${{ secrets.GA4_FOUNDATIONS_ID }}
cookbooks_id: ${{ secrets.GA4_COOKBOOKS_ID }}
PORTAL_ID: ${{ secrets.PORTAL_ID }}
FOUNDATIONS_ID: ${{ secrets.FOUNDATIONS_ID }}
COOKBOOKS_ID: ${{ secrets.COOKBOOKS_ID }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
PRIVATE_KEY_ID: ${{ secrets.PRIVATE_KEY_ID }}

jobs:
main:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Set Credentials
uses: mobiledevops/secret-to-file-action@v1
with:
base64-encoded-secret: ${{ secrets.GOOGLE_ANALYTICS_API_CREDENTIALS }}
filename: "credentials.json"
is-executable: true
working-directory: "."
- run: export GOOGLE_APPLICATION_CREDENTIALS="credentials.json"

- name: Set-Up Virtual Environment
run: |
python -m venv analytics-api
source analytics-api/bin/activate
pip install google-analytics-data

- name: Get and Write Metrics to JSON
- name: Write Metrics to JSON
run: |
curl -O https://raw.githubusercontent.com/jukent/projectpythia.github.io/metrics-api/.github/workflows/get-metrics.py
python get_metrics.py
source analytics-api/bin/activate
curl -O https://raw.githubusercontent.com/jukent/projectpythia.github.io/main/.github/workflows/get-metrics.py
python get-metrics.py

- name: Write Markdown File
run: python write-metrics-md.py
run: |
source analytics-api/bin/activate
curl -O https://raw.githubusercontent.com/jukent/projectpythia.github.io/main/.github/workflows/write-metrics-md.py
python write-metrics-md.py
38 changes: 28 additions & 10 deletions .github/workflows/get-metrics.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
import json
import os
import base64
import hashlib

from google.analytics.data_v1beta import BetaAnalyticsDataClient
from google.analytics.data_v1beta.types import DateRange, Metric, RunReportRequest

PORTAL_ID = os.environ['portal_id']
FOUNDATIONS_ID = os.environ['foundations_id']
COOKBOOKS_ID = os.environ['cookbook_id']
PORTAL_ID = os.environ.get('PORTAL_ID')
FOUNDATIONS_ID = os.environ.get('FOUNDATIONS_ID')
COOKBOOKS_ID = os.environ.get('COOKBOOKS_ID')

PRIVATE_KEY_ID = os.environ.get('PRIVATE_KEY_ID')
PRIVATE_KEY = os.environ.get('PRIVATE_KEY').replace('$','\n')

def _run_total_users_report(property_id):
credentials_dict = {
"type": "service_account",
"project_id": "cisl-vast-pythia",
"private_key_id": PRIVATE_KEY_ID,
"private_key": PRIVATE_KEY,
"client_email": "[email protected]",
"client_id": "113402578114110723940",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/pythia-metrics-api%40cisl-vast-pythia.iam.gserviceaccount.com",
"universe_domain": "googleapis.com"
}

client = BetaAnalyticsDataClient.from_service_account_info(credentials_dict)

client = BetaAnalyticsDataClient()

def _run_total_users_report(property_id):
request = RunReportRequest(
property=f'properties/{property_id}',
dimensions=[],
Expand All @@ -29,15 +47,15 @@ def _run_total_users_report(property_id):
return total_users


def get_metrics(portal_id, foundations_id, cookbooks_id):
def get_metrics():
metrics_dict = {}
metrics_dict['Portal'] = _run_total_users_report(str(portal_id))
metrics_dict['Foundations'] = _run_total_users_report(str(foundations_id))
metrics_dict['Cookbooks'] = _run_total_users_report(str(cookbooks_id))
metrics_dict['Portal'] = _run_total_users_report(str(PORTAL_ID))
metrics_dict['Foundations'] = _run_total_users_report(str(FOUNDATIONS_ID))
metrics_dict['Cookbooks'] = _run_total_users_report(str(COOKBOOKS_ID))

with open('user_metrics.json', 'w') as outfile:
json.dump(metrics_dict, outfile)


if __name__ == '__main__':
get_metrics(PORTAL_ID, FOUNDATIONS_ID, COOKBOOKS_ID)
get_metrics()
2 changes: 1 addition & 1 deletion .github/workflows/nightly-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
update-metrics:
uses: automate-metrics.yaml@main
uses: ./.github/workflows/automate-metrics.yaml

build:
if: ${{ github.repository_owner == 'ProjectPythia' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-site.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

jobs:
update-metrics:
uses: automate-metrics.yaml@main
uses: ./.github/workflows/automate-metrics.yaml

build:
uses: ProjectPythia/cookbook-actions/.github/workflows/build-book.yaml@main
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/trigger-preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
- completed

jobs:
update-metrics:
uses: ./.github/workflows/automate-metrics.yaml

find-pull-request:
uses: ProjectPythia/cookbook-actions/.github/workflows/find-pull-request.yaml@main
deploy-preview:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/trigger-site-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:

jobs:
update-metrics:
uses: automate-metrics.yaml@main
uses: ./.github/workflows/automate-metrics.yaml

build:
uses: ProjectPythia/cookbook-actions/.github/workflows/build-book.yaml@main
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/write-metrics-md.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ def process_user_data(user_data_file, markdown_file):

if __name__ == '__main__':
user_data_file = 'user_metrics.json'
markdown_file = '../../portal/metrics.md'
markdown_file = 'portal/metrics.md'
process_user_data(user_data_file, markdown_file)
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ repos:
- id: isort

- repo: https://github.com/nbQA-dev/nbQA
rev: 1.7.1
rev: 1.8.4
hooks:
- id: nbqa-black
- id: nbqa-pyupgrade
Loading