generated from P3TERX/Actions-OpenWrt
-
Notifications
You must be signed in to change notification settings - Fork 4
168 lines (146 loc) · 5.45 KB
/
build-openwrt.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
name: Build OpenWrt
on:
repository_dispatch:
workflow_dispatch:
inputs:
ssh:
description: 'SSH connection to Actions'
required: true
default: 'false'
type: choice
options:
- true
- false
version:
description: 'OpenWrt version'
required: true
default: 'snapshot'
type: string
env:
REPO_URL: https://git.openwrt.org/openwrt/openwrt.git
REPO_BRANCH: master
BUILDROOT: ${{ github.workspace }}/openwrt
DEPENDENCIES: ${{ github.workspace }}/dependencies-ubuntu.txt
CUSTOM_FEEDS_SH: ${{ github.workspace }}/custom-feeds.sh
CUSTOM_PACKAGES_SH: ${{ github.workspace }}/custom-packages.sh
CUSTOM_CONFIG_SH: ${{ github.workspace }}/custom-config.sh
TZ: Asia/Shanghai
jobs:
build:
runs-on: ubuntu-24.04
steps:
- name: Initialization environment
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo apt-get -qq update && sudo apt-get -qq upgrade
sudo apt-get -qq install $(cat $DEPENDENCIES)
sudo apt-get -qq autoremove --purge
sudo apt-get -qq clean
sudo timedatectl set-timezone "$TZ"
- name: Maximize build disk space
uses: easimon/maximize-build-space@master
with:
remove-dotnet: true
remove-android: true
remove-haskell: true
remove-codeql: true
remove-docker-images: true
- name: Checkout
uses: actions/checkout@main
- name: Download the sources
run: git clone --branch $REPO_BRANCH $REPO_URL
- name: Auto select a specific code revision
id: autoselect
if: github.event.client_payload.version == 'stable'
run: |
cd $BUILDROOT && git checkout $(git tag --sort=-creatordate | head -n1)
echo "status=success" >> $GITHUB_OUTPUT
- name: Manual select a specific code revision
id: manualselect
if: github.event.inputs.version != 'snapshot'
run: |
cd $BUILDROOT && git checkout ${{ github.event.inputs.version }}
echo "status=success" >> $GITHUB_OUTPUT
- name: Load custom
run: |
chmod +x custom-*.sh
$CUSTOM_FEEDS_SH
$BUILDROOT/scripts/feeds update -a && $BUILDROOT/scripts/feeds install -a
$CUSTOM_PACKAGES_SH
$CUSTOM_CONFIG_SH
- name: Start SSH via tmate
uses: rdp-studio/ssh2actions@main
if: github.event.inputs.ssh == 'true'
- name: Build the firmware image
id: compile
run: |
cd $BUILDROOT && echo "$(($(nproc)+1)) thread compile"
IGNORE_ERRORS=m make -j$(($(nproc)+1)) defconfig download clean world || IGNORE_ERRORS=m make -j1 defconfig download clean world V=s
echo "status=success" >> $GITHUB_OUTPUT
grep '^CONFIG_TARGET.*DEVICE.*=y' .config | sed -r 's/.*DEVICE_(.*)=y/\1/' > DEVICE_NAME
[ -s DEVICE_NAME ] && echo "DEVICE_NAME=$(cat DEVICE_NAME)" >> $GITHUB_ENV
echo "FILE_DATE=$(date +"%Y%m%d%H%M")" >> $GITHUB_ENV
- name: Check space usage
run: df -hT
- name: Upload bin directory
uses: actions/upload-artifact@main
if: steps.compile.outputs.status == 'success'
with:
name: OpenWrt_bin_${{ env.DEVICE_NAME }}_${{ env.FILE_DATE }}
path: ${{ env.BUILDROOT }}/bin
- name: Organize files
id: organize
run: |
cd $BUILDROOT/bin/targets/*/* && rm -rf packages
{ echo '### SHA256SUMS'; echo '```txt'; cat sha256sums; echo '```'; } > $BUILDROOT/SHA256SUMS
echo "FIRMWARE=$PWD" >> $GITHUB_ENV
echo "status=success" >> $GITHUB_OUTPUT
- name: Upload firmware directory
uses: actions/upload-artifact@main
if: steps.organize.outputs.status == 'success'
with:
name: OpenWrt_firmware_${{ env.DEVICE_NAME }}_${{ env.FILE_DATE }}
path: ${{ env.FIRMWARE }}
- name: Generate stable Release Tag
id: stabletag
if: steps.autoselect.outputs.status == 'success' || steps.manualselect.outputs.status == 'success'
run: |
echo "release_tag=$(cd $BUILDROOT && git describe --tags --abbrev=0 --exact-match)_$(date +"%Y.%m.%d-%H%M")" >> $GITHUB_OUTPUT
echo "status=success" >> $GITHUB_OUTPUT
- name: Generate snapshot Release Tag
id: snapshottag
if: github.event.inputs.version == 'snapshot'
run: |
echo "release_tag=SNAPSHOT_$(date +"%Y.%m.%d-%H%M")" >> $GITHUB_OUTPUT
echo "status=success" >> $GITHUB_OUTPUT
- name: Upload stable firmware to Release
uses: softprops/action-gh-release@master
if: steps.stabletag.outputs.status == 'success'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.stabletag.outputs.release_tag }}
files: ${{ env.FIRMWARE }}/*
body_path: ${{ env.BUILDROOT }}/SHA256SUMS
- name: Upload snapshot firmware to Release
uses: softprops/action-gh-release@master
if: steps.snapshottag.outputs.status == 'success'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.snapshottag.outputs.release_tag }}
files: ${{ env.FIRMWARE }}/*
body_path: ${{ env.BUILDROOT }}/SHA256SUMS
- name: Delete workflow runs
uses: Mattraks/delete-workflow-runs@main
with:
retain_days: 1
keep_minimum_runs: 3
- name: Remove old Releases
uses: dev-drprasad/delete-older-releases@master
with:
keep_latest: 3
delete_tags: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}