-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (117 loc) · 4.24 KB
/
deploy.yml
File metadata and controls
138 lines (117 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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