Skip to content

ci: Change how poetry deps are cached (#310) #968

ci: Change how poetry deps are cached (#310)

ci: Change how poetry deps are cached (#310) #968

Workflow file for this run

name: Test tap-github
on:
# Run on all pull requests and on pushes to main.
pull_request:
paths:
- .github/workflows/test_tap.yml
- poetry.lock
- pyproject.toml
- 'tap_github/**'
push:
branches:
- main
paths:
- .github/workflows/test_tap.yml
- poetry.lock
- pyproject.toml
- 'tap_github/**'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
tests:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
ORG_LEVEL_TOKEN: ${{secrets.ORG_LEVEL_TOKEN}}
strategy:
matrix:
python-version:
- "3.12"
- "3.11"
- "3.10"
- "3.9"
- "3.8"
# run the matrix jobs one after the other so they can benefit from caching
max-parallel: 1
steps:
- uses: actions/checkout@v4
- name: Get Date
id: get-date
run: |
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
- name: Cache github API responses
uses: actions/cache@v4
with:
# must match the path in tests/__init__.py
path: '.cache/api_calls_tests_cache.sqlite'
# github cache expires after 1wk, and we expire the content after 24h
# this key is rotated every 24h so that the code does not find a stale
# file in the cache. See issue #119
key: api-cache-v4-${{ steps.get-date.outputs.date }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
# Version of Poetry to use
version: 1.8.3
virtualenvs-create: true
virtualenvs-in-project: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: poetry
- name: Install dependencies
run: |
poetry env use ${{ matrix.python-version }}
poetry install
- name: Test with pytest
id: test_pytest
continue-on-error: true
run: |
LOGLEVEL=WARNING poetry run pytest --capture=no
- name: Test with pytest (run 2)
id: retry_test_pytest
if: steps.test_pytest.outcome=='failure' # check the step outcome, wait and retry
run: |
# sleep as little as possible to reduce CI run time
# This assumes that REST quota is the one that caused problem
# (which is most likely/often the case)
target_ts=$(curl -s -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GITHUB_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/rate_limit | grep reset | head -n 1 | awk -F: '{ print $2 }')
current_ts=$(date +%s)
seconds_to_sleep=$(echo "$target_ts - $current_ts" | bc)
sleep $seconds_to_sleep
LOGLEVEL=WARNING poetry run pytest --capture=no