Skip to content

Forecasting Operator #648

Forecasting Operator

Forecasting Operator #648

Workflow file for this run

name: tests/unitary/**
on:
workflow_dispatch:
pull_request:
branches:
- main
- "release/**"
- develop
paths:
- "ads/**"
- pyproject.toml
- "**requirements.txt"
- .github/workflows/run-unittests.yml
- .github/workflows/run-unittests-default_setup.yml
# Cancel in progress workflows on pull_requests.
# https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-a-fallback-value
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
permissions:
contents: read
pull-requests: write
# hack for https://github.com/actions/cache/issues/810#issuecomment-1222550359
env:
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 5
jobs:
test:
name: python ${{ matrix.python-version }}, ${{ matrix.name }}
runs-on: ubuntu-latest
timeout-minutes: 90
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10"]
test-path: ["tests/unitary/with_extras tests/unitary/default_setup", "tests/unitary/with_extras/model"]
include:
- test-path: "tests/unitary/with_extras tests/unitary/default_setup"
ignore-path: "--ignore tests/unitary/with_extras/model --ignore tests/unitary/with_extras/feature_store"
name: "unitary"
- test-path: "tests/unitary/with_extras/model"
name: "model"
- python-version: "3.8"
cov-reports: --cov=ads --cov-report=xml --cov-report=html
steps:
- uses: actions/checkout@v3
# Caching python libraries installed with pip
# https://github.com/actions/cache/blob/main/examples.md#python---pip
- uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/dev-requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: "Test config setup"
shell: bash
env:
HOME_RUNNER_DIR: /home/runner
run: |
set -x # print commands that are executed
mkdir -p "$HOME_RUNNER_DIR"/.oci
openssl genrsa -out $HOME_RUNNER_DIR/.oci/oci_ads_user.pem 2048
cat <<EOT >> "$HOME_RUNNER_DIR/.oci/config"
[DEFAULT]
user=ocid1.user.oc1..xxx
fingerprint=00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
tenancy=ocid1.tenancy.oc1..xxx
region=test_region
key_file=$HOME_RUNNER_DIR/.oci/oci_ads_user.pem
EOT
ls -lha "$HOME_RUNNER_DIR"/.oci
echo "Test config file:"
cat $HOME_RUNNER_DIR/.oci/config
- name: "Test env setup"
timeout-minutes: 20
shell: bash
run: |
set -x # print commands that are executed
sudo apt-get install libkrb5-dev graphviz
$CONDA/bin/conda init
source /home/runner/.bashrc
pip install -r dev-requirements.txt
- name: "Run unitary tests folder with maximum ADS dependencies"
timeout-minutes: 60
shell: bash
env:
CONDA_PREFIX: /usr/share/miniconda
run: |
set -x # print commands that are executed
# Setup project and tests folder for cov reports to not be overwritten by another parallel step
if [[ ! -z "${{ matrix.cov-reports }}" ]]; then
mkdir -p cov-${{ matrix.name }}
cd cov-${{ matrix.name }}
ln -s ../tests tests
ln -s ../ads ads
ln -s ../.coveragerc .coveragerc
fi
# Run tests
python -m pytest -v -p no:warnings --durations=5 \
-n auto --dist loadfile ${{ matrix.cov-reports }} \
${{ matrix.test-path }} ${{ matrix.ignore-path }}
- name: "Save coverage files"
uses: actions/upload-artifact@v3
if: ${{ matrix.cov-reports }}
with:
name: cov-reports-${{ matrix.name }}
path: |
cov-${{ matrix.name }}/htmlcov/
cov-${{ matrix.name }}/.coverage
cov-${{ matrix.name }}/coverage.xml
coverage-report:
name: "Coverage report"
runs-on: ubuntu-latest
continue-on-error: true
needs: test
if: ${{ success() }} && ${{ github.event.issue.pull_request }}
env:
COMPARE_BRANCH: main
steps:
- name: "Checkout current branch"
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: "Download coverage files"
uses: actions/download-artifact@v3
- name: "Calculate overall coverage"
run: |
set -x # print commands that are executed
# Prepare default cov body text
COV_BODY_INTRO="📌 Overall coverage:\n\n"
echo COV_BODY="$COV_BODY_INTRO No success to gather report. 😿" >> $GITHUB_ENV
# Prepare file paths to .coverage files
# Filenames taken from job.test last step with name - "Save coverage files"
FILE_UNITARY="cov-reports-unitary/.coverage"; [[ ! -f $FILE_UNITARY ]] && FILE_UNITARY=""
FILE_MODEL="cov-reports-model/.coverage"; [[ ! -f $FILE_MODEL ]] && FILE_MODEL=""
# Combine coverage files
pip install coverage
coverage combine $FILE_UNITARY $FILE_MODEL
# Make html report
coverage html
# Calculate overall coverage and update body message
COV=$(grep -E 'pc_cov' htmlcov/index.html | cut -d'>' -f 2 | cut -d'%' -f 1)
if [[ ! -z $COV ]]; then
if [[ $COV -lt 50 ]]; then COLOR=red; elif [[ $COV -lt 80 ]]; then COLOR=yellow; else COLOR=green; fi
echo COV_BODY="$COV_BODY_INTRO ![Coverage-$COV%](https://img.shields.io/badge/coverage-$COV%25-$COLOR)" >> $GITHUB_ENV
fi
- name: "Calculate coverage diff"
if: always()
run: |
set -x # print commands that are executed
# Prepare default diff body text
DIFF_BODY_INTRO="📌 Cov diff with **${{ env.COMPARE_BRANCH }}**:\n\n"
echo DIFF_BODY="$DIFF_BODY_INTRO No success to gather report. 😿" >> $GITHUB_ENV
# Prepare file paths to coverage xml files
# Filenames taken from job.test last step with name - "Save coverage files"
FILE1="cov-reports-unitary/coverage.xml"; [[ ! -f $FILE1 ]] && FILE1=""
FILE2="cov-reports-model/coverage.xml"; [[ ! -f $FILE2 ]] && FILE2=""
echo "FILE1=$FILE1" >> $GITHUB_ENV
echo "FILE2=$FILE2" >> $GITHUB_ENV
# Calculate coverage diff and update body message
pip install diff_cover
diff-cover $FILE1 $FILE2 --compare-branch=origin/${{ env.COMPARE_BRANCH }}
DIFF=$(diff-cover $FILE1 $FILE2 \
--compare-branch=origin/${{ env.COMPARE_BRANCH }} | grep Coverage: | cut -d' ' -f 2 | cut -d'%' -f 1)
if [[ -z $DIFF ]]; then
DIFF_INFO=$(diff-cover $FILE1 $FILE2 \
--compare-branch=origin/${{ env.COMPARE_BRANCH }} | grep "No lines");
echo DIFF_BODY="$DIFF_BODY_INTRO $DIFF_INFO">> $GITHUB_ENV
else
if [[ $DIFF -lt 50 ]]; then COLOR=red; elif [[ $DIFF -lt 80 ]]; then COLOR=yellow; else COLOR=green; fi
echo DIFF_BODY="$DIFF_BODY_INTRO ![Coverage-$DIFF%](https://img.shields.io/badge/coverage-$DIFF%25-$COLOR)" >> $GITHUB_ENV
fi
- name: "Add comment with cov diff to PR"
uses: actions/github-script@v6
if: always()
with:
github-token: ${{ github.token }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '${{ env.DIFF_BODY }}\n\n${{ env.COV_BODY }}'
})
- name: "Generate html difference report"
run: |
diff-cover ${{ env.FILE1 }} ${{ env.FILE2 }} \
--compare-branch=origin/${{ env.COMPARE_BRANCH }} \
--html-report=cov-diff.html
- name: "Save coverage difference report"
uses: actions/upload-artifact@v3
with:
name: cov-html-reports
path: |
cov-diff.html
htmlcov/
retention-days: 10