diff --git a/.github/workflows/run-checks.yml b/.github/workflows/run-checks.yml new file mode 100644 index 0000000..61759b8 --- /dev/null +++ b/.github/workflows/run-checks.yml @@ -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/sleep-random@v1.0.0 + 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 diff --git a/scripts/get_token.py b/scripts/get_token.py new file mode 100644 index 0000000..a52c383 --- /dev/null +++ b/scripts/get_token.py @@ -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}")