Add CI #41
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
types: [opened, synchronize] | |
permissions: | |
id-token: write | |
checks: write | |
issues: read | |
pull-requests: write | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: | | |
3.8 | |
3.10 | |
3.12 | |
- name: Install Hatch | |
run: pipx install hatch twine | |
- name: get python version | |
id: pips | |
shell: bash | |
run: | | |
echo "PIP_38_CACHE=$(hatch run +py=38 test:python -m pip cache dir)" >> $GITHUB_OUTPUT | |
echo "PIP_310_CACHE=$(hatch run +py=310 test:python -m pip cache dir)" >> $GITHUB_OUTPUT | |
echo "PIP_312_CACHE=$(hatch run +py=312 test:python -m pip cache dir)" >> $GITHUB_OUTPUT | |
- name: Set up pip cache | |
if: runner.os == 'Linux' | |
uses: actions/cache@v3 | |
with: | |
path: ${{ steps.pips.outputs.PIP_312_CACHE }} | |
key: ${{ runner.os }}-3.12-pip-${{ hashFiles('pyproject.toml', 'requirements.txt') }} | |
restore-keys: ${{ runner.os }}-3.12-pip- | |
- name: Set up Docker Buildx | |
id: builder | |
uses: docker/setup-buildx-action@v3 | |
- name: Prepare env file | |
run: | | |
cp .env_template .env | |
shell: bash | |
- name: Build Docker Image | |
uses: docker/build-push-action@v6 | |
with: | |
push: false | |
tags: solace/solace-ai-connector:local | |
platforms: linux/amd64 | |
builder: ${{ steps.builder.outputs.name }} | |
load: true | |
- name: Run Structured Tests | |
run: | | |
hatch run test:make structure-test | |
shell: bash | |
- name: Run Lint | |
run: | | |
hatch run lint:ruff check -o lint.json --output-format json ./src ./tests | |
shell: bash | |
- name: Run Unit Tests | |
run: | | |
hatch test --cover --all --junitxml=junit.xml | |
- name: Report coverage | |
run: | | |
hatch run test:coverage xml | |
shell: bash | |
- name: SonarQube Scan | |
uses: sonarsource/[email protected] | |
env: | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
SONAR_HOST_URL: ${{ vars.SONAR_HOST_URL }} | |
with: | |
args: > | |
-Dsonar.tests=tests/ | |
-Dsonar.verbose=true | |
-Dsonar.sources=src/ | |
-Dsonar.projectKey=${{github.repository_owner}}_${{github.event.repository.name}} | |
-Dsonar.python.coverage.reportPaths=coverage.xml | |
-Dsonar.python.ruff.reportPaths=lint.json | |
- name: SonarQube Quality Gate check | |
id: sonarqube-quality-gate-check | |
uses: sonarsource/sonarqube-quality-gate-action@master | |
env: | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
SONAR_HOST_URL: ${{ vars.SONAR_HOST_URL }} | |
# Build and verify packages | |
- name: Build | |
run: hatch build | |
- name: Verify Packages | |
run: | | |
ls dist/*.tar.gz | xargs -n1 twine check | |
ls dist/*.whl | xargs -n1 twine check | |
shell: bash | |
- name: Surface failing tests | |
if: always() | |
uses: pmeier/pytest-results-action@main | |
with: | |
# A list of JUnit XML files, directories containing the former, and wildcard | |
# patterns to process. | |
# See @actions/glob for supported patterns. | |
path: junit.xml | |
# (Optional) Add a summary of the results at the top of the report | |
summary: true | |
# (Optional) Select which results should be included in the report. | |
# Follows the same syntax as `pytest -r` | |
display-options: fEX | |
# (Optional) Fail the workflow if no JUnit XML was found. | |
fail-on-empty: true | |
# (Optional) Title of the test results section in the workflow summary | |
title: Test results |