Skip to content

Merge pull request #61 from traktore-org/develop #80

Merge pull request #61 from traktore-org/develop

Merge pull request #61 from traktore-org/develop #80

Workflow file for this run

name: CI/CD - Run Tests and Deploy
on:
push:
branches: [ develop, main ]
pull_request:
branches: [ develop, main ]
workflow_dispatch:
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
run-integration-tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12", "3.13"]
steps:
- uses: actions/checkout@v4
with:
path: custom_components/solar_energy_management
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install -r custom_components/solar_energy_management/tests/requirements_test.txt
- name: Run tests
run: python -m pytest tests/ --ignore=tests/test_energy_flow_balance.py --ignore=tests/test_flow_accumulation.py -v
working-directory: custom_components/solar_energy_management
trigger-deployment:
needs: run-integration-tests
runs-on: ubuntu-latest
if: success() && github.ref == 'refs/heads/develop'
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Bump version
id: bump
run: |
python -c "
import json
from pathlib import Path
import os
manifest_path = Path('manifest.json')
with open(manifest_path, 'r') as f:
data = json.load(f)
version = data['version']
major, minor, patch = map(int, version.split('.'))
patch += 1
new_version = f'{major}.{minor}.{patch}'
data['version'] = new_version
with open(manifest_path, 'w') as f:
json.dump(data, f, indent=2)
f.write('\n')
print(f'Version bumped: {version} -> {new_version}')
# Export to GITHUB_OUTPUT for use in next steps
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
f.write(f'version={new_version}\n')
"
echo "Version bumped successfully"
- name: Commit and push version bump
run: |
git add manifest.json
git commit -m "🔖 Bump version [skip ci]" || echo "No changes to commit"
git push origin develop || echo "Nothing to push"
- name: Trigger n8n deployment workflow
env:
N8N_WEBHOOK_URL: ${{ secrets.N8N_WEBHOOK_URL }}
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
AUTHOR_NAME: ${{ github.event.head_commit.author.name }}
run: |
echo "✅ Tests passed! Ready for deployment."
echo "📦 Version: ${{ steps.bump.outputs.version }}"
# Send webhook to n8n with deployment info
if [ -n "$N8N_WEBHOOK_URL" ]; then
# Use jq to properly escape JSON values
PAYLOAD=$(jq -n \
--arg version "${{ steps.bump.outputs.version }}" \
--arg branch "${{ github.ref_name }}" \
--arg commit_sha "${{ github.sha }}" \
--arg commit_message "$COMMIT_MESSAGE" \
--arg author "$AUTHOR_NAME" \
--arg repository "${{ github.repository }}" \
--arg workflow "${{ github.workflow }}" \
--arg run_id "${{ github.run_id }}" \
--arg run_number "${{ github.run_number }}" \
--arg timestamp "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
'{
version: $version,
branch: $branch,
commit_sha: $commit_sha,
commit_message: $commit_message,
author: $author,
repository: $repository,
workflow: $workflow,
run_id: $run_id,
run_number: $run_number,
timestamp: $timestamp
}')
curl -X POST "$N8N_WEBHOOK_URL" \
-H "Content-Type: application/json" \
-d "$PAYLOAD"
echo "Webhook sent to n8n"
else
echo "N8N_WEBHOOK_URL not configured - skipping webhook"
fi