Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added ci pipeline for unit test #1

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .github/workflows/unit_test_pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: TM1Py Integration Tests

on:
workflow_dispatch:
inputs:
environments:
description: 'Comma-separated list of environments to test'
required: true
default: 'tm1-11-onprem,tm1-11-cloud,tm1-12-mcsp'

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
environment: ${{ fromJson('["' + github.event.inputs.environments + '"]') }}
environment: ${{ matrix.environment }}
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install dependencies
run: |
pip install -e .
pip install pytest

- name: Retrieve TM1 Connection Details
id: get-connection
run: echo "Retrieving TM1 connection details"
env:
TM1_CONNECTION: ${{ vars.TM1_CONNECTION }}
TM1_CONNECTION_SECRET: ${{ secrets.TM1_CONNECTION_SECRET }}

- name: Generate config.ini
run: |
python Tests/resources/generate_config.py
env:
TM1_CONNECTION: ${{ vars.TM1_CONNECTION }}
TM1_CONNECTION_SECRET: ${{ secrets.TM1_CONNECTION_SECRET }}

- name: Run tests
run: pytest Tests/

- name: Upload test results
if: always()
uses: actions/upload-artifact@v3
with:
name: test-results-${{ matrix.environment }}
path: Tests/test-reports/

# Optional: Post results to PR
- name: Post comment to PR
if: always() && github.event_name == 'workflow_dispatch' && github.event.pull_request
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: 'Tests completed for environment: ${{ matrix.environment }}. Check artifacts for details.'
})
20 changes: 20 additions & 0 deletions Tests/resources/generate_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import json
import os

tm1_connection = os.environ.get('TM1_CONNECTION')
tm1_connection_secret = os.environ.get('TM1_CONNECTION_SECRET')

config_content = '[tm1srv01]\n'

if tm1_connection:
conn_data = json.loads(tm1_connection)
for key, value in conn_data.items():
config_content += f"{key}={value}\n"

if tm1_connection_secret:
secret_data = json.loads(tm1_connection_secret)
for key, value in secret_data.items():
config_content += f"{key}={value}\n"

with open('Tests/config.ini', 'w') as f:
f.write(config_content)