-
-
Notifications
You must be signed in to change notification settings - Fork 21
189 lines (173 loc) · 6.17 KB
/
build-firmware.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
# Build the ESPHome firmwares for the Onju Voice Satellite project.
name: Build & Deploy firmware
on:
push:
branches:
- main
# release:
# types:
# - published
workflow_dispatch:
pull_request:
# branches-ignore:
# - renovate/docusaurus**
# Every Monday at 4:00 UTC
# schedule:
# - cron: "0 4 * * 1"
concurrency:
# yamllint disable-line rule:line-length
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
FIRMWARES: esphome
REPOSITORY: onju-voice-satellite
jobs:
prepare:
name: Prepare matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.prepare-matrix.outputs.matrix }}
steps:
- name: ⤵️ Check out code from GitHub
uses: actions/[email protected]
# - name: ⤵️ Get changed files
# uses: masesgroup/retrieve-changed-files@v3
# if: github.event_name == 'pull_request'
# id: changes
- name: 🚧 Prepare matrix
id: prepare-matrix
run: |-
# Set variables
matrix=""
# fullRun=$(! [[ "${{ github.event_name }}" != "pull_request" || "${{ steps.changes.outputs.modified }}" == *".github/workflows/build-firmware.yaml"* ]]; echo $?)
# Iterate through firmwares and devices
for firmware in $FIRMWARES; do
for device in $firmware/*.yaml; do
# If pull_request event type and changed files do not contain the device, skip it
# if [[ $fullRun -eq 0 && "${{ steps.changes.outputs.added_modified }}" != *"${device}"* ]]; then
# continue
# fi
# Extract device name from file path
device=${device##*/}
device=${device%.yaml}
# Set default version
version="latest"
# Build matrix entry
matrix="$matrix{\"firmware\":\"$firmware\",\"device\":\"$device\", \"version\":\"$version\"},"
done
done
# Remove trailing comma and format matrix
matrix=${matrix%?}
matrix="{\"include\":[$matrix]}"
# Output matrix to a file
echo matrix=$matrix >> $GITHUB_OUTPUT
build:
name: ${{ matrix.device }}
runs-on: ubuntu-latest
needs: prepare
strategy:
fail-fast: false
matrix: ${{fromJson(needs.prepare.outputs.matrix)}}
steps:
- name: ⤵️ Check out code from GitHub
uses: actions/[email protected]
- name: 🔨 Build firmware
uses: esphome/[email protected]
id: esphome-build
with:
yaml_file: ${{ matrix.firmware }}/${{ matrix.device }}.yaml
version: ${{ matrix.version || 'latest' }}
- name: 🚚 Move generated files to output
run: |
mkdir -p output/${{ matrix.device }}
mv ${{ steps.esphome-build.outputs.name }}/* output/${{ matrix.device }}/
echo ${{ steps.esphome-build.outputs.version }} > output/${{ matrix.device }}/version
- name: 🔨 Alter path in manifest.json
run: |
sed -i 's/${{ steps.esphome-build.outputs.name }}\//\/${{ matrix.device }}\//g' output/${{ matrix.device }}/manifest.json
- name: ⬆️ Upload firmware / device artifact
uses: actions/[email protected]
with:
name: ${{ matrix.device }}
path: output
full-manifests:
name: Create ${{ matrix.project }} manifest
runs-on: ubuntu-latest
needs: build
strategy:
fail-fast: false
matrix:
include:
- project: onju-voice
name: Onju Voice Satellite
steps:
- name: ⤵️ Download specific artifacts
uses: actions/[email protected]
with:
name: ${{ matrix.project }}
path: project-build
- name: 🔨 Generate device manifest.json
run: |
version=$(cat project-build/*/version | sort -V | tail -n 1)
jq --arg version "$version" '{"name": "${{ matrix.name }}", "version": $version, "home_assistant_domain": "esphome", "builds":[.]}' project-build/*/manifest.json > temp.json && mv temp.json project-build/*/manifest.json
- name: 🧪 Display structure of job
run: |
cat project-build/*/manifest.json
ls -R
- name: ⬆️ Upload project artifact
uses: actions/[email protected]
with:
name: ${{ matrix.project }}
path: project-build
overwrite: true
build-docs:
name: Build documentation website
# if: (github.event_name == 'workflow_dispatch' || github.event_name == 'push') && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: full-manifests
steps:
- name: ⤵️ Check out code from GitHub
uses: actions/[email protected]
- name: ⬇️ Download all artifacts
uses: actions/[email protected]
with:
path: repository
- name: 🧪 Display structure of job
run: ls -R
- name: 🗂️ Move firmware folders to static
run: |
for firmware in repository/*/; do
mv "$firmware"* docs/static
done
rm -R ./repository
- name: 🏗️ Set up Node.js
uses: actions/[email protected]
with:
node-version: 20.x
- name: 🏗️ Install Docusaurus dependencies
run: npm install --frozen-lockfile --non-interactive
working-directory: docs
- name: 🚀 Build Docusaurus
run: npm run build
working-directory: docs
- name: ⬆️ Upload pages artifacts
uses: actions/upload-pages-artifact@v3
with:
path: docs/build
deploy:
name: Deploy to GitHub Pages
# if: (github.event_name == 'workflow_dispatch' || github.event_name == 'push') && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: build-docs
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: 🏗️ Setup Github Pages
uses: actions/configure-pages@v4
- name: 🚀 Deploy to Github Pages
uses: actions/[email protected]
id: deployment