Skip to content

Commit

Permalink
Merge pull request #22118 from mrclary/rate-limit
Browse files Browse the repository at this point in the history
PR: Use GITHUB_TOKEN to make authorized user requests against GitHub
  • Loading branch information
ccordoba12 authored May 24, 2024
2 parents cbed437 + 0505208 commit 1475484
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 24 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,21 @@ on:
- '!.github/workflows/build-subrepos.yml'

workflow_dispatch:
inputs:
ssh:
# github_cli: gh workflow run test-linux.yml --ref <branch> -f ssh=true
description: 'Enable ssh debugging'
required: false
default: false
type: boolean

concurrency:
group: test-linux-${{ github.ref }}
cancel-in-progress: true

env:
ENABLE_SSH: ${{ github.event_name == 'workflow_dispatch' && inputs.ssh }}

jobs:
build:
# Use this to disable the workflow
Expand Down Expand Up @@ -68,6 +78,12 @@ jobs:
PYTHON_VERSION: '3.8'
timeout-minutes: 90
steps:
- name: Setup Remote SSH Connection
if: env.ENABLE_SSH == 'true'
uses: mxschmitt/action-tmate@v3
timeout-minutes: 60
with:
detached: true
- name: Checkout Pull Requests
if: github.event_name == 'pull_request'
uses: actions/checkout@v4
Expand Down Expand Up @@ -130,10 +146,6 @@ jobs:
micromamba info
micromamba list
pip list
#- name: Setup tmate session
# if: env.USE_CONDA == 'true'
# uses: mxschmitt/action-tmate@v3
# timeout-minutes: 45
- name: Run manifest checks
shell: bash -l {0}
run: check-manifest
Expand Down
20 changes: 16 additions & 4 deletions .github/workflows/test-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,21 @@ on:
- '!.github/workflows/build-subrepos.yml'

workflow_dispatch:
inputs:
ssh:
# github_cli: gh workflow run test-mac.yml --ref <branch> -f ssh=true
description: 'Enable ssh debugging'
required: false
default: false
type: boolean

concurrency:
group: test-mac-${{ github.ref }}
cancel-in-progress: true

env:
ENABLE_SSH: ${{ github.event_name == 'workflow_dispatch' && inputs.ssh }}

jobs:
build:
# Use this to disable the workflow
Expand All @@ -63,6 +73,12 @@ jobs:
TEST_TYPE: ['fast', 'slow']
timeout-minutes: 90
steps:
- name: Setup Remote SSH Connection
if: env.ENABLE_SSH == 'true'
uses: mxschmitt/action-tmate@v3
timeout-minutes: 60
with:
detached: true
- name: Checkout Pull Requests
if: github.event_name == 'pull_request'
uses: actions/checkout@v4
Expand Down Expand Up @@ -101,10 +117,6 @@ jobs:
run: |
micromamba info
micromamba list
#- name: Setup tmate session
# if: env.USE_CONDA == 'true'
# uses: mxschmitt/action-tmate@v3
# timeout-minutes: 45
- name: Run manifest checks
shell: bash -l {0}
run: check-manifest
Expand Down
25 changes: 16 additions & 9 deletions .github/workflows/test-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,21 @@ on:
- '!.github/workflows/build-subrepos.yml'

workflow_dispatch:
inputs:
ssh:
# github_cli: gh workflow run test-win.yml --ref <branch> -f ssh=true
description: 'Enable ssh debugging'
required: false
default: false
type: boolean

concurrency:
group: test-win-${{ github.ref }}
cancel-in-progress: true

env:
ENABLE_SSH: ${{ github.event_name == 'workflow_dispatch' && inputs.ssh }}

jobs:
build:
# Use this to disable the workflow
Expand All @@ -63,6 +73,12 @@ jobs:
TEST_TYPE: ['fast', 'slow']
timeout-minutes: 90
steps:
- name: Setup Remote SSH Connection
if: env.ENABLE_SSH == 'true'
uses: mxschmitt/action-tmate@v3
timeout-minutes: 60
with:
detached: true
- name: Checkout Pull Requests
if: github.event_name == 'pull_request'
uses: actions/checkout@v4
Expand Down Expand Up @@ -120,15 +136,6 @@ jobs:
micromamba info
micromamba list
pip list
# Notes:
# 1. This only works for conda, probably because it has the necessary
# MSYS2 packages to create the connection.
# 2. Check https://github.com/marketplace/actions/debugging-with-tmate for
# usage.
#- name: Setup remote ssh connection
# if: env.USE_CONDA == 'true'
# uses: mxschmitt/action-tmate@v3
# timeout-minutes: 45
- name: Run manifest checks
shell: bash -l {0}
run: check-manifest
Expand Down
12 changes: 8 additions & 4 deletions spyder/plugins/updatemanager/tests/test_update_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def worker():
# ---- Test WorkerUpdate

@pytest.mark.parametrize("version", ["1.0.0", "1000.0.0"])
def test_updates_appenv(qtbot, mocker, version):
def test_updates_appenv(qtbot, mocker, version, caplog):
"""
Test whether or not we offer updates for our installers according to the
current Spyder version.
Expand All @@ -51,9 +51,13 @@ def test_updates_appenv(qtbot, mocker, version):
return_value=("conda-forge", "https://conda.anaconda.org/conda-forge")
)

um = UpdateManagerWidget(None)
um.start_check_update()
qtbot.waitUntil(um.update_thread.isFinished)
with caplog.at_level(logging.DEBUG, logger='spyder.plugins.updatemanager'):
# Capture >=DEBUG logging messages for spyder.plugins.updatemanager
# while checking for updates. Messages will be reported at the end
# of the pytest run, and only if this test fails.
um = UpdateManagerWidget(None)
um.start_check_update()
qtbot.waitUntil(um.update_thread.isFinished)

update_available = um.update_worker.update_available
if version.split('.')[0] == '1':
Expand Down
31 changes: 28 additions & 3 deletions spyder/plugins/updatemanager/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# (see spyder/__init__.py for details)

# Standard library imports
from datetime import datetime as dt
import logging
import os
import os.path as osp
Expand All @@ -20,7 +21,8 @@

# Local imports
from spyder import __version__
from spyder.config.base import _, is_stable_version, is_conda_based_app
from spyder.config.base import (_, is_stable_version, is_conda_based_app,
running_in_ci)
from spyder.config.utils import is_anaconda
from spyder.utils.conda import get_spyder_conda_channel
from spyder.utils.programs import check_version
Expand All @@ -46,6 +48,23 @@
)


def _rate_limits(page):
"""Log rate limits for GitHub.com"""
if page.headers.get('Server') != 'GitHub.com':
return

xrlr = dt.utcfromtimestamp(int(page.headers['X-RateLimit-Reset']))
msg_items = [
"Rate Limits:",
f"Resource: {page.headers['X-RateLimit-Resource']}",
f"Reset: {xrlr}",
f"Limit: {page.headers['X-RateLimit-Limit']:>5s}",
f"Used: {page.headers['X-RateLimit-Used']:>5s}",
f"Remaining: {page.headers['X-RateLimit-Remaining']:>5s}",
]
logger.debug("\n\t".join(msg_items))


class UpdateDownloadCancelledException(Exception):
"""Download for installer to update was cancelled."""
pass
Expand Down Expand Up @@ -150,12 +169,18 @@ def start(self):
else:
url = pypi_url

headers = {}
token = os.getenv('GITHUB_TOKEN')
if running_in_ci() and url == github_url and token:
headers.update(Authorization=f"Bearer {token}")

logger.info(f"Checking for updates from {url}")
try:
page = requests.get(url)
page = requests.get(url, headers=headers)
_rate_limits(page)
page.raise_for_status()
data = page.json()

data = page.json()
if self.releases is None:
if url == github_url:
self.releases = [
Expand Down

0 comments on commit 1475484

Please sign in to comment.