Skip to content

Commit

Permalink
Add CI checks
Browse files Browse the repository at this point in the history
  • Loading branch information
parafoxia committed Sep 26, 2021
1 parent 27e7153 commit 0775d19
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/run-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Run checks

on:
workflow_dispatch:
inputs:
token:
description: 'YouTube API token (you will need to get this through the scripts/get_token.py script)'
required: true

jobs:
test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.6, 3.7, 3.8, 3.9, 3.10-dev]

runs-on: ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Write data
run: |
mkdir secrets
echo '${{ secrets.SECRETS_FILE }}' > secrets/secrets.json
mkdir ~/.analytix
echo '{"token": "${{ github.event.inputs.token }}", "expires": 9999999999.9999999}' > ~/.analytix/youtube-analytics-token.json
- name: Sleep to avoid ratelimits
uses: 1itachi/[email protected]
with:
minutes: '5'
random: 'true'

- name: Run checks (Ubuntu)
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -U pip nox
nox
- name: Run checks (MacOS)
if: ${{ matrix.os == 'macos-latest' }}
run: |
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -U pip nox
nox
- name: Run checks (Windows)
if: ${{ matrix.os == 'windows-latest' }}
run: |
python -m venv .venv
. .venv\Scripts\activate.bat
python -m pip install -U pip nox
nox
28 changes: 28 additions & 0 deletions scripts/get_token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import json

import requests
from requests_oauthlib import OAuth2Session

SCOPES = (
"https://www.googleapis.com/auth/yt-analytics.readonly",
"https://www.googleapis.com/auth/yt-analytics-monetary.readonly",
)

with open("./secrets/secrets-tests.json", mode="r", encoding="utf-8") as f:
secrets = json.load(f)["installed"]

session = OAuth2Session(
secrets["client_id"],
redirect_uri=secrets["redirect_uris"][0],
scope=SCOPES,
)

url, _ = session.authorization_url(secrets["auth_uri"])
code = input(f"Use this link to get your OAuth code: {url}\nCODE > ")
token = session.fetch_token(
secrets["token_uri"],
code=code,
client_secret=secrets["client_secret"],
)
token = token["access_token"]
print(f"\nHere's your token! Paste it into the action input.\n{token}")

0 comments on commit 0775d19

Please sign in to comment.