Skip to content

cli - use library.collectors #1304

cli - use library.collectors

cli - use library.collectors #1304

Workflow file for this run

name: "Pytest tests"
on:
push:
branches: ['devel']
pull_request_target:
jobs:
pytest:
runs-on: ubuntu-latest
steps:
- name: "Checkout metrics-utility (${{ github.ref }})"
uses: actions/checkout@v5
if: ${{ ! github.base_ref }}
- name: "Checkout metrics-utility (${{ github.event.pull_request.head.ref }})"
uses: actions/checkout@v5
if: ${{ github.base_ref }}
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: "Install uv"
uses: astral-sh/setup-uv@v7
- name: "Set up Python"
uses: actions/setup-python@v6
with:
python-version-file: "pyproject.toml"
- name: "Set up postgresql"
run: |
sudo apt install postgresql postgresql-client
sudo systemctl start postgresql.service # ubuntu
- name: "Wait for postgresql"
timeout-minutes: 1
run: |
until pg_isready; do
sleep 4
done
- name: "Import SQL dump"
run: |
cat tools/docker/{roles,latest,conf_setting,main_hostmetric,main_instance,main_jobhostsummary}.sql | sudo su - postgres -c psql
- name: "Set up minio"
env:
MINIO_ROOT_USER: minioaccess
MINIO_ROOT_PASSWORD: miniosecret
run: |
mkdir -p ~/.local/bin
curl https://dl.min.io/client/mc/release/linux-amd64/mc -o ~/.local/bin/mc
curl https://dl.min.io/server/minio/release/linux-amd64/minio -o ~/.local/bin/minio
chmod +x ~/.local/bin/{mc,minio}
mkdir minio-data
minio server ./minio-data --console-address ":9001" &
- name: "Wait for minio"
timeout-minutes: 1
env:
MINIO_ROOT_USER: minioaccess
MINIO_ROOT_PASSWORD: miniosecret
run: |
until mc alias set local http://localhost:9000 minioaccess miniosecret; do
sleep 4
done
- name: "Create minio user"
env:
MINIO_ROOT_USER: minioaccess
MINIO_ROOT_PASSWORD: miniosecret
run: |
mc alias set local http://localhost:9000 minioaccess miniosecret
mc mb --ignore-existing local/metricsutilitys3
mc admin user add local mynewuser mysecretpassword
mc admin policy attach local readwrite --user=mynewuser
mc admin accesskey create local mynewuser --access-key myuseraccesskey --secret-key myusersecretkey
- name: "Patch mock_awx postgres config"
run: |
sed -i '/NAME/s/awx/postgres/' mock_awx/settings/__init__.py
sed -i '/USER/s/myuser/awx/' mock_awx/settings/__init__.py
sed -i '/PASSWORD/s/mypassword/awx/' mock_awx/settings/__init__.py
- name: "Run pytest"
env:
METRICS_UTILITY_BUCKET_ACCESS_KEY: "myuseraccesskey"
METRICS_UTILITY_BUCKET_ENDPOINT: "http://localhost:9000"
METRICS_UTILITY_BUCKET_NAME: "metricsutilitys3"
METRICS_UTILITY_BUCKET_REGION: "us-east-1"
METRICS_UTILITY_BUCKET_SECRET_KEY: "myusersecretkey"
METRICS_UTILITY_DB_HOST: "localhost"
run: |
uv run pytest -s -v --cov=. --cov-report=xml
- name: "Send code coverage report to Sonar Cloud"
uses: SonarSource/sonarqube-scan-action@v6
if: ${{ github.base_ref }}
env:
SONAR_HOST_URL: https://sonarcloud.io
SONAR_ORGANIZATION: ansible
SONAR_PROJECT_KEY: ansible_metrics-utility
SONAR_TOKEN: ${{ secrets.CICD_ORG_SONAR_TOKEN_CICD_BOT }}
with:
projectBaseDir: .
args: >
-Dsonar.host.url=https://sonarcloud.io
-Dsonar.organization=ansible
-Dsonar.projectKey=ansible_metrics-utility
"-Dsonar.pullrequest.base=${{ github.base_ref }}"
"-Dsonar.pullrequest.branch=${{ github.head_ref }}"
"-Dsonar.pullrequest.key=${{ github.event.pull_request.number }}"
-Dsonar.pullrequest.provider=github
-Dsonar.python.coverage.reportPaths=coverage.xml
- name: "Send code coverage report to Sonar Cloud"
uses: SonarSource/sonarqube-scan-action@v6
if: ${{ ! github.base_ref }}
env:
SONAR_HOST_URL: https://sonarcloud.io
SONAR_ORGANIZATION: ansible
SONAR_PROJECT_KEY: ansible_metrics-utility
SONAR_TOKEN: ${{ secrets.CICD_ORG_SONAR_TOKEN_CICD_BOT }}
with:
projectBaseDir: .
args: >
-Dsonar.host.url=https://sonarcloud.io
-Dsonar.organization=ansible
-Dsonar.projectKey=ansible_metrics-utility
-Dsonar.python.coverage.reportPaths=coverage.xml