-
Notifications
You must be signed in to change notification settings - Fork 1
185 lines (157 loc) Β· 7.17 KB
/
build.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
name: Build and Publish OpenWrt Image
on:
workflow_dispatch:
inputs:
model:
description: 'Device Model:'
required: true
target:
description: 'Target Architecture:'
visible: false
version:
description: 'OpenWrt Version:'
required: true
packages:
description: 'Extra Packages:'
required: false
disabled_services:
description: 'Disabled Services:'
required: false
scripts:
description: 'UCI Defaults Scripts:'
required: false
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Load config
run: |
# Check if a script is specified and set it in the environment
if [ -n "${{ github.event.inputs.scripts }}" ]; then
echo "SCRIPT=${{ github.event.inputs.scripts }}" >> $GITHUB_ENV
if [ ! -f "files/etc/uci-defaults/${{ github.event.inputs.scripts }}" ]; then
echo "Error: Specified script file does not exist."
exit 1
fi
find files/etc/uci-defaults -type f ! -name "${{ github.event.inputs.scripts }}" -delete
fi
# Create input configuration file
files="files"
cat <<EOF > input_config
openwrt_version=${{ github.event.inputs.version }}
packages=${{ github.event.inputs.packages }}
files=$files
profile=${{ github.event.inputs.model }}
target=${{ github.event.inputs.target }}
EOF
# Add disabled services to the configuration if specified
if [ -n "${{ github.event.inputs.disabled_services }}" ]; then
echo "disabled_services=${{ github.event.inputs.disabled_services }}" >> input_config
fi
# Append input configuration to environment variables
cat input_config >> $GITHUB_ENV
- name: Load secrets
if: ${{ github.event.inputs.scripts }}
run: |
# Inject secrets into the specified script
sed -i -e 's/^# ssid=".*"/ssid="${{ secrets.WLAN_NAME }}"/' \
-e 's/^# ssid_key=".*"/ssid_key="${{ secrets.WLAN_PASS }}"/' \
-e 's/^# root_password=".*"/root_password="${{ secrets.ROOT_PASS }}"/' \
-e 's/^# pppoe_name=".*"/pppoe_name="${{ secrets.PPPOE_NAME }}"/' \
-e 's/^# pppoe_key=".*"/pppoe_key="${{ secrets.PPPOE_PASS }}"/' \
files/etc/uci-defaults/${{ env.SCRIPT }}
- name: Cache apt packages
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: build-essential libncurses-dev zlib1g-dev gawk wget git gettext libssl-dev xsltproc rsync unzip python3 python3-setuptools zstd
version: 1.0
- name: Install dependencies
run: |
# Update package list and install required dependencies
sudo apt update
sudo apt install -y \
build-essential libncurses-dev zlib1g-dev gawk wget git gettext \
libssl-dev xsltproc rsync unzip python3 python3-setuptools zstd
- name: Fetch version.buildinfo
id: fetch_version_buildinfo
run: |
# Determine the OpenWrt version and download the appropriate image builder
version="${{ env.openwrt_version }}"
target="${{ env.target }}"
# Fetch the latest version.buildinfo file
if [[ $version == "SNAPSHOT" ]]; then
url="https://downloads.openwrt.org/${version,,}s/targets/${target}/version.buildinfo"
else
url="https://downloads.openwrt.org/releases/${version}/targets/${target}/version.buildinfo"
fi
wget $url
# Get the latest version code
echo "version_buildinfo=$(cat version.buildinfo)" >> $GITHUB_ENV
- name: Cache OpenWrt Image Builder
id: cache-openwrt
uses: actions/cache@v4
with:
path: openwrt-imagebuilder-*.tar.*
key: openwrt-imagebuilder-${{ env.openwrt_version }}-${{ env.target }}-${{ env.version_buildinfo }}
- name: Download OpenWrt Image Builder
if: steps.cache-openwrt.outputs.cache-hit != 'true'
run: |
# Determine the OpenWrt version and download the appropriate image builder
version="${{ env.openwrt_version }}"
target="${{ env.target }}"
if [[ $version == "SNAPSHOT" ]]; then
url="https://downloads.openwrt.org/${version,,}s/targets/${target}/openwrt-imagebuilder-$(echo $target | tr '/' '-').Linux-x86_64.tar.zst"
elif [[ $version < "24.10" ]]; then
url="https://downloads.openwrt.org/releases/${version}/targets/${target}/openwrt-imagebuilder-${version}-$(echo $target | tr '/' '-').Linux-x86_64.tar.xz"
else
url="https://downloads.openwrt.org/releases/${version}/targets/${target}/openwrt-imagebuilder-${version}-$(echo $target | tr '/' '-').Linux-x86_64.tar.zst"
fi
wget "$url"
- name: Build OpenWrt Image
run: |
tar -xf openwrt-imagebuilder-*.tar.*
# Move necessary files and run the build process
mv files openwrt-imagebuilder-*/
cd openwrt-imagebuilder-*/
make -j $(nproc) image \
PROFILE="${{ env.profile }}" \
PACKAGES="${{ env.packages }}" \
FILES="${{ env.files }}" \
DISABLED_SERVICES="${{ env.disabled_services }}"
- name: Write Build Info
run: |
# Determine if scripts are used
scripts="${{ env.SCRIPT != '' && env.SCRIPT || 'false' }}"
disabled_services="${{ env.disabled_services != '' && env.disabled_services || 'false' }}"
packages="${{ env.packages != '' && env.packages || 'default' }}"
# Get the target directory and write build info
target_dir=$(find openwrt-imagebuilder-*/bin/targets/*/*/ -type d -print -quit)
echo "image_path=$target_dir" >> $GITHUB_ENV
# Get version code from profiles.json
version_code=$(grep -o '"version_code":"[^"]*"' $target_dir/profiles.json | awk -F: '{print $2}' | tr -d '"')
# Create build info markdown file
cat <<EOF > build_info.md
## π‘ Custom OpenWrt Build Information
- **OpenWrt Version**: \`${{ env.openwrt_version }}\`
- **Target**: \`${{ env.target }}\`
- **Profile**: \`${{ env.profile }}\`
- **Package Selections**: \`${{ env.packages }}\`
- **Disabled Services**: \`$disabled_services\`
- **Version Code**: \`$version_code\`
- **UCI Defaults Scripts**: \`$scripts\`
-----
### π sha256sum
$(awk '$2 ~ /(sysupgrade|factory|recovery)\.bin$/ {printf "`%s`\n**%s**\n\n", $1, $2}' $target_dir/sha256sums)
EOF
- name: Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.event.inputs.model }}-${{ env.openwrt_version }}-${{ env.version_buildinfo }}
body_path: build_info.md
files: ${{ env.image_path }}/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}