Skip to content

Cancel scheduled maintenance tasks when all their components are missing #3271

Cancel scheduled maintenance tasks when all their components are missing

Cancel scheduled maintenance tasks when all their components are missing #3271

name: Build NAV and run full test suite
on:
push:
branches:
- master
- '[1-9][0-9]?.[0-9]+.x'
pull_request:
schedule: # Run daily at 08:00 CEST (06:00 UST)
- cron: '0 6 * * *'
jobs:
build-and-test:
name: "Test on Python ${{ matrix.python-version}}"
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: ["3.9", "3.10"]
steps:
- uses: actions/checkout@v4
- name: "Cache pip packages"
uses: actions/cache@v4
id: pip-cache
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/requirements/*.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: "Cache tox environments"
uses: actions/cache@v4
id: tox-cache
with:
path: .tox
key: ${{ runner.os }}-tox-${{ matrix.python-version }}-${{ hashFiles('**/requirements.txt', '**/requirements/*.txt', 'tox.ini') }}
- name: "Set up Python ${{ matrix.python-version }}"
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: "Set environment variables"
run: |
echo "WORKSPACE=$GITHUB_WORKSPACE" >> $GITHUB_ENV
echo "PGHOST=localhost" >> $GITHUB_ENV
echo "PGUSER=nav" >> $GITHUB_ENV
echo "PGPASSWORD=password" >> $GITHUB_ENV
- name: "Update APT package lists"
run: |
sudo apt-get update -y
- name: "Install test runner dependencies"
run: |
set -xe
python3 -m pip install --upgrade 'pip==23.1.0' setuptools wheel 'tox<4' tox-gh-actions coverage virtualenv
sudo apt-get install -y nbtscan
# virtualenv seems to currently be embedding a broken version of
# setuptools (2022-03-31). this ensures these embedded wheels are always
# up to date, but can potentially be removed again down the road.
- name: "Upgrade embedded virtualenv wheels"
run: |
virtualenv --upgrade-embed-wheel
- name: "Install libraries needed to build external dependencies"
run: |
set -xe
sudo apt-get install -y libldap2-dev libsasl2-dev libtidy5deb1 libsnmp40
- uses: browser-actions/setup-chrome@latest
- run: chrome --version
- uses: nanasess/setup-chromedriver@v2
- name: "Set up PostgreSQL"
uses: harmon758/postgresql-action@v1
with:
postgresql version: '13' # minimum NAV requirement
postgresql user: $PGUSER
postgresql password: $PGPASSWORD
- name: "Run tests"
run: |
export DISPLAY=:99
ulimit -c unlimited
sudo sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t
python3 -m tox
- name: Upload Selenium driver logs (${{ matrix.python-version }})
if: always()
uses: actions/upload-artifact@v4
with:
name: pytest-logs-${{ matrix.python-version }}
path: |
/tmp/pytest-of-runner
- name: Upload test reports (${{ matrix.python-version }})
if: always()
uses: actions/upload-artifact@v4
with:
name: test-reports-${{ matrix.python-version }}
path: |
reports/**/*
- name: Upload core dumps (${{ matrix.python-version }})
if: failure()
uses: actions/upload-artifact@v4
with:
name: core-dumps-${{ matrix.python-version }}
path: |
/tmp/core-*
- name: Print stack traces of core dumps (${{ matrix.python-version }})
if: failure()
run: |
sudo apt-get install -y gdb
set -x
for core in /tmp/core-*; do
echo "===== CORE: $core ====="
file "$core"
program=$(gdb -ex quit -c "$core" | grep -o "generated by.*" | awk '{print $3}' | tr -d '`')
gdb -ex bt "$program" "$core"
echo
done
javascript:
name: "Test Javascript code"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: browser-actions/setup-chrome@latest
- uses: browser-actions/setup-firefox@latest
- run: chrome --version
- uses: actions/setup-node@v4
with:
node-version: 18
- name: npm install
run: |
cd python/nav/web/static/js
npm ci
- name: npm test
run: OPENSSL_CONF=/dev/null xvfb-run -a npm test
working-directory: ./python/nav/web/static/js
- name: Upload JavaScript test reports
if: always()
uses: actions/upload-artifact@v4
with:
name: javascript-test-reports
path: |
reports/**/*
upload-pr-number-base-sha:
name: Save PR number and base SHA in artifact
runs-on: ubuntu-latest
if: ${{ github.event.number && always() }}
env:
PR_NUMBER: ${{ github.event.number }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
steps:
- name: Make PR number file
run: |
mkdir -p ./extra
echo $PR_NUMBER > ./extra/pr_number
- name: Make base SHA file
run: |
echo $BASE_SHA > ./extra/base_sha
- name: Upload PR number file and base SHA file
uses: actions/upload-artifact@v4
with:
name: extra
path: extra/