-
Notifications
You must be signed in to change notification settings - Fork 31
199 lines (179 loc) · 9.69 KB
/
HassOS-AutoBuild.yml
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
name: HassOS-AutoBuild
on:
# push:
# branches:
# - main
workflow_dispatch:
inputs:
ssh:
description: 'SSH connection to Actions'
required: false
default: 'false'
schedule:
- cron: '0 18 * * *'
watch:
types: [started]
env:
RUN_VALIDATION: true
jobs:
build:
#runs-on: self-hosted
runs-on: ubuntu-20.04
if: github.event.repository.owner.id == github.event.sender.id
name: Build ${{matrix.target}}
strategy:
fail-fast: false
matrix:
target: [rpi3_64,rpi4_64,rpi5_64,ova,generic_x86_64,generic_aarch64,green,yellow]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get HassOS version
id: get_hassos_version
run: |
ver=$(curl -s https://version.home-assistant.io/stable.json | jq -r '.hassos."ova"')
old=$(curl -s https://sumju.net/stable.json | jq -r '.hassos."ova"')
echo "HASSOS_VERSION=${ver}" >> $GITHUB_ENV
echo "HA_VER=${old}" >> $GITHUB_ENV
- name: Compare HassOS versions
run: |
if [ -z "${{ env.HA_VER }}" ]; then
echo "No previous HassOS version found. Storing current version '${{ env.HASSOS_VERSION }}' as old version."
export HA_Ver="${{ env.HASSOS_VERSION }}"
elif [ "${{ env.HASSOS_VERSION }}" != "${{ env.HA_VER }}" ]; then
echo "HassOS version has changed from '${{ env.HA_VER }}' to '${{ env.HASSOS_VERSION }}' . Proceeding with next steps."
else
echo "HassOS offical version is '${{ env.HASSOS_VERSION }}' already builed . Stopping subsequent steps."
exit 1
fi
- name: Initialization environment
run: |
#sudo echo "nameserver 1.1.1.1" >> /etc/hosts
sudo rm -rf /etc/apt/sources.list.d/* /usr/share/dotnet /usr/local/lib/android /opt/ghc
sudo -E apt-get -qq update
sudo -E apt-get -qq autoremove --purge
sudo -E apt-get -qq clean
sudo timedatectl set-timezone "Asia/Shanghai"
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo rm -rf /usr/share/
- name: Clone source code
run: |
df -hT $PWD
#dpkg-query -W --showformat='${Installed-Size} ${Package} ${Status}\n'|grep -v deinstall|sort -n|awk '{print $1" "$2}'
git clone https://github.com/home-assistant/operating-system.git -b main HassOS
#git clone -b main https://github.com/5high/operating-system.git -b dev HassOS
- name: Change Settings.
run: |
cp -r rootfs-overlay HassOS/buildroot-external
cd HassOS
git submodule update --init
wget ${{ secrets.KEY_URL }}/key.pem --no-check-certificate
wget ${{ secrets.KEY_URL }}/cert.pem --no-check-certificate
sed -i 's/-e\ BUILDER_UID/-e TZ=Asia\/Shanghai\ -e BUILDER_UID/g' buildroot-external/package/hassio/hassio.mk
sed -i 's/-e\ BUILDER_UID/-e TZ=Asia\/Shanghai\ -e BUILDER_UID/g' scripts/enter.sh
sed -i 's/-e\ SUPERVISOR_NAME=hassio_supervisor/-e TZ=Asia\/Shanghai\ -e SUPERVISOR_NAME=hassio_supervisor/g' buildroot-external/rootfs-overlay/usr/sbin/hassos-supervisor
sed -i '/vhdx/d' buildroot-external/scripts/hdd-image.sh
sed -i '/vdi/d' buildroot-external/scripts/hdd-image.sh
if [ "${{matrix.target}}" == "generic_x86_64" ]; then
sed -i 's/SYSTEM_SIZE=256M/SYSTEM_SIZE=512M/' buildroot-external/scripts/hdd-image.sh
fi
#sed -i 's/homeassistant/itcommander/g' buildroot-external/configs/${{matrix.target}}_defconfig
sed -i 's/Welcome to Home Assistant/Welcome to Home Assistant ( YouTuBe @itcommander )/g' buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_TARGET_GENERIC_ROOT_PASSWD=\"\"" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_ROOTFS_SKELETON_DEFAULT=y" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_TARGET_ENABLE_ROOT_LOGIN=y" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_HOST_LZO=n" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_PACKAGE_VIM=y" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_PACKAGE_NANO_TINY=y" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_PACKAGE_NTP=y" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_PACKAGE_NTP_SNTP=y" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_PACKAGE_NTPDATE=y" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_PACKAGE_NTPTIME=y" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_PACKAGE_TZDATA=y" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_PACKAGE_HTOP=y" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_PACKAGE_NGINX=y" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_PACKAGE_NGINX_HTTP_GZIP_MODULE=y" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_PACKAGE_NGINX_HTTP_PROXY_MODULE=y" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_PACKAGE_NGINX_HTTP_REWRITE_MODULE=y" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_PACKAGE_NGINX_HTTP_SSL_MODULE=y" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_PACKAGE_NGINX_HTTP_UPSTREAM_IP_HASH_MODULE=y" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_PACKAGE_NGINX_HTTP_UPSTREAM_KEEPALIVE_MODULE=y" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_PACKAGE_NGINX_HTTP_UPSTREAM_RANDOM_MODULE=y" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_PACKAGE_NGINX_HTTP_UPSTREAM_ZONE_MODULE=y" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_PACKAGE_NGINX_HTTP_UPSTREAM_LEAST_CONN_MODULE=y" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_PACKAGE_NGINX_HTTP_SUB_MODULE=y" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_PACKAGE_WGET=y" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_TARGET_INFO=y" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_PACKAGE_ZIP=y" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_PACKAGE_UNZIP=y" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_TARGET_ZONELIST=\"default\"" >> buildroot-external/configs/${{matrix.target}}_defconfig
echo "BR2_TARGET_LOCALTIME=\"Asia/Shanghai\"" >> buildroot-external/configs/${{matrix.target}}_defconfig
sed -i '/\[Service\]/a RestartSec=10' buildroot/package/nginx/nginx.service
sed -i '/\[Service\]/a Restart=always' buildroot/package/nginx/nginx.service
sed -i '/After=syslog.target network.target/ s/$/ hassos-supervisor.service/' buildroot/package/nginx/nginx.service
sed -i '/cd \$(TARGET_DIR) ;\\/i \ \ \ \ wget -O \$(TARGET_DIR)\/usr\/share\/ca-certificates\/itcommander.crt https:\/\/github.com\/5high\/HassOS-Actions\/raw\/main\/rootfs-overlay\/etc\/ssl\/certs\/rootCA.cer' buildroot/package/ca-certificates/ca-certificates.mk
- name: SSH connection to Actions
uses: P3TERX/[email protected]
if: (github.event.inputs.ssh == 'true' && github.event.inputs.ssh != 'false') || contains(github.event.action, 'ssh')
env:
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
- name: Build
shell: 'script -q -e -c "bash {0}"'
id: build
run: |
sleep $((RANDOM % 60))
cd HassOS
./scripts/enter.sh make -j$(($(nproc) + 1)) ${{matrix.target}}
#sudo ./scripts/entry.sh make ${{matrix.target}}
- name: Get current date
id: current_date
run: |
current_date=$(date +'%Y-%m-%d')
echo "CURRENT_DATE=${current_date}" >> $GITHUB_ENV
- name: Use current date
run: echo "Current date is $CURRENT_DATE"
# - name: Upload Firmware
# uses: actions/upload-artifact@main
# with:
# name: ${{matrix.target}}_Firmware
# path: HassOS/output/images
- name: Upload images to release
id: upload-release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: HassOS/output/images/haos_*
asset_name: ${{ matrix.asset_name }}
tag: ${{ env.HASSOS_VERSION }}
overwrite: true
file_glob: true
body: "针对大陆地区网络专门优化的HassOS版本 欢迎关注Youtube频道https://youtube.com/@itcommander 博客地址https://sumju.net 官方硬件优惠卷领取https://sumju.net/?p=7943"
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Delete workflow runs
uses: 5high/delete-workflow-runs@main
with:
retain_days: 1
keep_minimum_runs: 1
- name: Remove old Releases
uses: dev-drprasad/[email protected]
with:
keep_latest: 8
delete_tags: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Notify on Telegram
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_CHAT_ID }}
token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
message: "New release! Download it [here](${{ steps.upload-release.outputs.browser_download_url }})."
- name: Trigger download
run: |
curl -k -d "command=download_file" -X POST -H "Content-Type: application/x-www-form-urlencoded" $URL
env:
URL: ${{ secrets.URL }}