Skip to content

Commit

Permalink
DATAGO-78654 : Add CI (#4)
Browse files Browse the repository at this point in the history
DATAGO-78654: Add ci
  • Loading branch information
artyom-morozov authored Jul 8, 2024
1 parent f140ca6 commit df0fd3d
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 3 deletions.
156 changes: 156 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
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
env:
HATCH_CACHE_DIR: ${{ github.workspace }}/.hatch_cache
HATCH_DATA_DIR: ${{ github.workspace }}/.hatch_data

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install Hatch
uses: pypa/hatch@install

- name: Restore Hatch Directory
uses: actions/cache/restore@v4
id: cache-restore
with:
path: |
${{ env.HATCH_CACHE_DIR }}
${{ env.HATCH_DATA_DIR }}
key: ${{ runner.os }}-hatch-${{ hashFiles('pyproject.toml','requirements.txt') }}

- name: Install Dependencies
if: steps.cache-restore.outputs.cache-hit != 'true'
run: |
hatch python install 3.8 3.12
- name: Install Dependencies
if: steps.cache-restore.outputs.cache-hit != 'true'
run: |
hatch env create test
- name: Cache Hatch Directory
uses: actions/cache/save@v4
if: steps.cache-restore.outputs.cache-hit != 'true'
id: cache-hatch
with:
path: |
${{ env.HATCH_CACHE_DIR }}
${{ env.HATCH_DATA_DIR }}
key: ${{ runner.os }}-hatch-${{ hashFiles('pyproject.toml','requirements.txt') }}

- 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 Lint
continue-on-error: true
run: |
hatch run +py=312 lint:ruff check -o lint.json --output-format json ./src ./tests
shell: bash

- name: Run Structured Tests
run: |
hatch run +py=312 test:make structure-test
shell: bash

- name: Run Unit Tests
shell: bash
run: |
hatch test --cover --all --parallel --junitxml=junit.xml
- name: Combine Coverage Reports
continue-on-error: true
run: |
hatch run +py=312 test:coverage combine
shell: bash

- name: Report coverage
run: |
hatch run +py=312 test:coverage xml
shell: bash

- name: SonarQube Scan
if: always()
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 | hatch run +py=312 test:xargs -n1 twine check
ls dist/*.whl | hatch run +py=312 test: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: Unit Test results
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ RUN apt-get update && \
apt-get clean

#Install main program
COPY . /app
COPY /src /app/src
COPY requirements.txt /app

RUN python3.10 -m pip install -r requirements.txt
ENV PYTHONUNBUFFERED=1

Expand Down
21 changes: 20 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ dependencies = [
"PyYAML~=6.0.1",
"Requests~=2.32.3",
"solace_pubsubplus>=1.8.0",

]

[project.urls]
Expand All @@ -42,3 +41,23 @@ packages = ["src/solace_ai_connector"]

[tool.hatch.version]
path = "src/solace_ai_connector/__init__.py"

[tool.hatch.envs.test]
dependencies = [
"pytest>=8.2.2",
"coverage>=7.5.4",
"twine>=5.1.1",
]

[tool.hatch.envs.lint]
detached = true
dependencies = [
"ruff>=0.5.0",
]

[tool.ruff]
lint.select = ["E4", "E7", "E9", "F"]
lint.ignore = ["F401", "E731"]

[[tool.hatch.envs.test.matrix]]
python = ["38", "312"]
2 changes: 1 addition & 1 deletion tests/test_message_get_set_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,6 @@ def test_get_set_user_properties():
def test_get_set_previous():
"""Test getting and setting the previous data of a message"""
message = Message(payload=payloads["simple"])
assert message.get_previous() == None
assert message.get_previous() is None
message.set_previous(payloads["complex"])
assert message.get_previous() == payloads["complex"]

0 comments on commit df0fd3d

Please sign in to comment.