-
-
Notifications
You must be signed in to change notification settings - Fork 73
198 lines (196 loc) · 6.66 KB
/
cicd.yaml
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
name: CI/CD
on:
push:
branches: [main]
tags: ["v*"]
pull_request:
branches: [main]
jobs:
test:
name: Tests
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install poetry
uses: snok/[email protected]
with:
version: 1.4.0
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: "{project-dir}/.venv"
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: tests-venv-${{ matrix.python-version }}-v1-${{ hashFiles('poetry.lock') }}
- name: Install dependencies
run: poetry install --only main,test
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
- name: Testing
run: poetry run pytest tests --doctest-modules --junitxml=junit/test-results.xml --cov=apps --cov-report=xml --cov-report=html
- name: Upload coverage
uses: codecov/codecov-action@v4
pre-commit:
name: pre-commit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install pre-commit
run: pip install pre-commit
- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
- name: Run pre-commit
run: pre-commit run --all-files --show-diff-on-failure
hacs:
name: HACS validation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: hacs/action@main
with:
category: appdaemon
docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install poetry
uses: snok/[email protected]
with:
version: 1.4.0
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: "{project-dir}/.venv"
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: docs-venv-${{ hashFiles('poetry.lock') }}
- name: Install dependencies
run: poetry install --only main,docs
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
- name: Build docs
run: cd docs && poetry run mkdocs build
- uses: actions/upload-artifact@master
with:
name: built-docs
path: docs/site
publish_preview_docs:
name: Publish preview documentation
runs-on: ubuntu-latest
needs: [test, pre-commit, hacs, docs]
if: github.ref_type != 'tag'
steps:
- uses: actions/download-artifact@master
with:
name: built-docs
path: docs/site
- name: Move docs to controllerx/ folder
run: mkdir docs/controllerx-site && mv docs/site docs/controllerx-site/controllerx
- name: Create redirect for /controllerx
run: echo "/ /controllerx" > ./docs/controllerx-site/_redirects
- name: Deploy to Netlify
id: netlify
uses: nwtgck/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
publish-dir: "./docs/controllerx-site"
deploy-message: "${{ github.event.pull_request.number }} - ${{ github.event.pull_request.title }}"
production-deploy: ${{ github.ref_type == 'branch' && github.ref_name == 'main' }}
enable-pull-request-comment: true
enable-commit-comment: false
overwrites-pull-request-comment: true
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
deploy:
name: Deployment
runs-on: ubuntu-latest
needs: [test, pre-commit, hacs, docs]
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
- name: Archive Release
uses: thedoctor0/zip-release@master
with:
type: zip
filename: ../../controllerx.zip
directory: apps/controllerx
- run: sed -i 's/VERSION_TAG/${{ github.ref_name }}/g' RELEASE_NOTES.md
- run: "sed -i 's/BASE_URL/controllerx.netlify.app/g' RELEASE_NOTES.md"
if: contains(github.ref_name, 'b')
- run: sed -i 's/BASE_URL/xaviml.github.io/g' RELEASE_NOTES.md
if: "!contains(github.ref_name, 'b')"
- uses: ncipollo/release-action@v1
with:
artifacts: controllerx.zip
prerelease: ${{ contains(github.ref_name, 'b') }}
bodyFile: RELEASE_NOTES.md
generateReleaseNotes: false
post_deploy:
name: Post deployment
runs-on: ubuntu-latest
needs: [deploy]
if: startsWith(github.ref, 'refs/tags/v') && !contains(github.ref_name, 'b')
steps:
- uses: actions/checkout@v4
with:
ref: main
- run: mv RELEASE_NOTES.md RELEASE_NOTES.old.md
- run: cp .github/RELEASE_NOTES.template.md RELEASE_NOTES.md
- name: Commit report
if: hashFiles('RELEASE_NOTES.old.md') != hashFiles('RELEASE_NOTES.md')
run: |
git config --global user.name 'xaviml'
git config --global user.email '[email protected]'
git add RELEASE_NOTES.md
git commit -m "Upload RELEASE_NOTES.md"
git push origin HEAD
publish_doc:
name: Publish documentation
runs-on: ubuntu-latest
needs: [deploy]
if: startsWith(github.ref, 'refs/tags/v') && !contains(github.ref_name, 'b')
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install poetry
uses: snok/[email protected]
with:
version: 1.4.0
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: "{project-dir}/.venv"
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: docs-venv-${{ hashFiles('poetry.lock') }}
- name: Install dependencies
run: poetry install --only main,docs
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
- name: Publish docs
run: cd docs && poetry run mkdocs gh-deploy --force