-
-
Notifications
You must be signed in to change notification settings - Fork 223
233 lines (215 loc) · 7.6 KB
/
onpush_builder.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# yamllint disable rule:line-length
# inspired from https://github.com/Poeschl/Hassio-Addons
---
name: Builder
env:
BUILD_ARGS: ""
on:
workflow_call:
push:
branches:
- master
paths:
- "**/config.*"
jobs:
correct_path_filters:
if: github.repository_owner == 'alexbelgium'
runs-on: ubuntu-latest
steps:
- name: ↩️ Checkout
uses: actions/checkout@v4
- name: Update path_filters
run: |
# Init
echo "Starting"
# Go through all folders, add to filters if not existing
for f in $( find -- * -maxdepth 0 -type d | sort -r ); do
if [ -f "$f"/config.json ]; then
# Add to file
if ! grep "$f:" ".github/paths-filter.yml"; then
echo "$f: $f/config.*" >> ".github/paths-filter.yml"
fi
# Identify addons with true images
if [ "$(jq '.image' "$f/config.json")" != null ]; then
sed -i "/$f/ s/ # Image : yes//g" ".github/paths-filter.yml"
sed -i "/$f/ s/$/ # Image : yes/" ".github/paths-filter.yml"
fi
fi
done
# Sort yaml
sort -t= ".github/paths-filter.yml" -o ".github/paths-filter.yml"
- name: Commit if needed
uses: EndBug/add-and-commit@v9
with:
commit: -u
message: "GitHub bot : scripts executable"
default_author: github_actions
check-addon-changes:
runs-on: ubuntu-latest
needs: [correct_path_filters]
outputs:
changedAddons: ${{ steps.filter.outputs.changes }}
steps:
- name: ↩️ Checkout
uses: actions/checkout@v4
- name: 📂 Detect changed files
uses: dorny/paths-filter@v3
id: filter
with:
filters: .github/paths-filter.yml
correct-CRLF:
if: ${{ needs.check-addon-changes.outputs.changedAddons != '[]' }}
needs: check-addon-changes
uses: ./.github/workflows/weekly_crlftolf.yaml
make-executable:
if: ${{ needs.check-addon-changes.outputs.changedAddons != '[]' }}
needs: [check-addon-changes, correct-CRLF]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
addon: ${{ fromJSON(needs.check-addon-changes.outputs.changedAddons) }}
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Make scripts executable
run: |
echo "Starting"
git pull origin master
git config core.filemode true
# shellcheck disable=SC2086,SC2046
#git update-index --chmod=+x $(find "$path" -type f -iname "*.sh")
chmod u+x $(find "$path" -type f -iname "*.sh") || true
#git commit -am "fixing the script permissions..."
env:
path: "./${{ matrix.addon }}"
- name: Commit if needed
uses: EndBug/add-and-commit@v9
with:
commit: -u
message: "GitHub bot : scripts executable"
default_author: github_actions
lint_config:
if: ${{ needs.check-addon-changes.outputs.changedAddons != '[]' }}
needs: check-addon-changes
runs-on: ubuntu-latest
strategy:
matrix:
addon: ${{ fromJSON(needs.check-addon-changes.outputs.changedAddons) }}
steps:
- name: ↩️ Checkout
uses: actions/checkout@v4
- name: 🔎 Run Home Assistant Add-on Lint
uses: frenck/action-addon-linter@v2
with:
path: "./${{ matrix.addon }}"
build:
if: ${{ needs.check-addon-changes.outputs.changedAddons != '[]' }}
needs: [check-addon-changes, make-executable, correct-CRLF]
runs-on: ubuntu-latest
environment: CR_PAT
name: Build ${{ matrix.arch }} ${{ matrix.addon }} add-on
strategy:
matrix:
addon: ${{ fromJSON(needs.check-addon-changes.outputs.changedAddons) }}
arch: ["aarch64", "amd64", "armv7"]
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Get information
id: info
uses: home-assistant/actions/helpers/info@master
with:
path: "./${{ matrix.addon }}"
- name: Check if add-on should be built
id: check
env:
HEAD: "${{ github.head_ref }}"
run: |
# shellcheck disable=SC2157,SC2086
if [[ "${{ steps.info.outputs.architectures }}" =~ ${{ matrix.arch }} ]]; then
# shellcheck disable=SC2129
echo "build_arch=true" >> $GITHUB_OUTPUT;
# shellcheck disable=SC2129
echo "image=$(echo ${{ steps.info.outputs.image }} | cut -d'/' -f3)" >> $GITHUB_OUTPUT;
if [[ -z "$HEAD" ]] && [[ "${{ github.event_name }}" == "push" ]]; then
# shellcheck disable=SC2129
echo "BUILD_ARGS=" >> $GITHUB_ENV;
fi
else
echo "${{ matrix.arch }} is not a valid arch for ${{ matrix.addon }}, skipping build";
# shellcheck disable=SC2129
echo "build_arch=false" >> $GITHUB_OUTPUT;
fi
- name: Use action to check for mixed line endings (CRLF and LF)
uses: ymwymw/check-mixed-line-endings@v2
- name: Login to GitHub Container Registry
if: env.BUILD_ARGS != '--test'
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build ${{ matrix.addon }} add-on
id: builderstep
if: steps.check.outputs.build_arch == 'true'
uses: home-assistant/[email protected]
env:
CAS_API_KEY: ${{ secrets.CAS_API_KEY }}
with:
args: |
${{ env.BUILD_ARGS }} \
--${{ matrix.arch }} \
--target /data/${{ matrix.addon }} \
--image "${{ steps.check.outputs.image }}" \
--docker-hub "ghcr.io/${{ github.repository_owner }}" \
--addon
make-changelog:
if: ${{ needs.check-addon-changes.outputs.changedAddons != '[]' }}
needs: [check-addon-changes, build]
runs-on: ubuntu-latest
strategy:
matrix:
addon: ${{ fromJSON(needs.check-addon-changes.outputs.changedAddons) }}
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Update changelog for minor versions
run: |
echo "Starting"
# Git pull
git pull || true
cd "$path"
# Get version
if [ -f config.yaml ]; then
version="$(sed -e '/version/!d' -e 's/.*version: //' config.yaml)"
elif [ -f config.json ]; then
version="$(sed -e '/version/!d' -e 's/.*[^"]*"\([^"]*\)"/\1/' config.json)"
version="${version//,}"
else
exit 1
fi
# Exit if test
if [[ "$version" == *"test"* ]]; then exit 0; fi
# Create changelog
touch CHANGELOG.md
# If the version does not exist
if ! grep -q "$version" CHANGELOG.md; then
first_line="$(sed -n '/./p' CHANGELOG.md | head -n 1)"
# If the first line does not start with -
if [[ "$first_line" != "-"* ]]; then
sed -i "1i\- Minor bugs fixed" CHANGELOG.md
fi
sed -i "1i\## $version ($(date '+%d-%m-%Y'))" CHANGELOG.md
#fi
fi
env:
path: "./${{ matrix.addon }}"
- name: Commit if needed
uses: EndBug/add-and-commit@v9
with:
commit: -u
message: "GitHub bot : changelog"
default_author: github_actions
fetch: --force
push: --force