Skip to content

tests

tests #788

Workflow file for this run

name: tests
on:
push:
branches:
- master
pull_request:
schedule:
# At 00:25 every day
- cron: '25 0 * * *'
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
pipx install ruff
ruff check
test:
needs: lint
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install poetry
poetry install
- name: Run tests
run: |
poetry run pytest --exitfirst --disable-warnings --log-cli-level=DEBUG
update:
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/master' && github.actor != 'dependabot[bot]' && (github.event_name == 'push' || github.event_name == 'schedule')
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install dependencies
run: |
pip install poetry
poetry install
- name: Install ASN database
run: |
poetry run pip install pyasn
poetry run pyasn_util_download.py --latestv46
poetry run pyasn_util_convert.py --single rib.*.bz2 asn.db
- name: Update cloud_providers.json
run: poetry run cloudcheck forceupdate
- name: git add cloud_providers.json
uses: EndBug/add-and-commit@v9
with:
add: "cloud_providers.json"
default_author: github_actions
message: "update cloud_providers.json"
publish:
runs-on: ubuntu-latest
needs: update
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry build
poetry self add "poetry-dynamic-versioning[plugin]"
- name: Get current version from Poetry
id: get_version
run: |
VERSION=$(poetry version --short)
echo "VERSION=$VERSION" | tee -a $GITHUB_ENV
- name: Fetch latest tag
run: |
git fetch --tags
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null || echo "v0.0.0")
echo "LATEST_TAG=$LATEST_TAG" | tee -a $GITHUB_ENV
- name: Detect version change
run: |
# Retrieve and strip "v" prefix if present
PREVIOUS_VERSION="${{ env.LATEST_TAG }}"
CURRENT_VERSION="${{ env.VERSION }}"
echo "PREVIOUS_VERSION=$PREVIOUS_VERSION"
echo "CURRENT_VERSION=$CURRENT_VERSION"
# Extract major.minor for comparison
CURRENT_MAJOR_MINOR=$(echo "${CURRENT_VERSION#v}" | cut -d '.' -f 1-2)
PREVIOUS_MAJOR_MINOR=$(echo "${PREVIOUS_VERSION#v}" | cut -d '.' -f 1-2)
# Compare versions
if [ "$CURRENT_MAJOR_MINOR" == "$PREVIOUS_MAJOR_MINOR" ]; then
echo "VERSION_CHANGE=false" | tee -a $GITHUB_ENV
else
echo "VERSION_CHANGE=true" | tee -a $GITHUB_ENV
fi
shell: bash
- name: Build PyPi package
if: github.ref == 'refs/heads/master'
run: python -m build
- name: Publish PyPi package
if: github.ref == 'refs/heads/master'
uses: pypa/gh-action-pypi-publish@release/v1.5
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Tag the release
if: github.ref == 'refs/heads/master' && env.VERSION_CHANGE == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "${{ env.VERSION }}" -m "Release ${{ env.VERSION }}"
git push origin "refs/tags/${{ env.VERSION }}"