-
Notifications
You must be signed in to change notification settings - Fork 0
190 lines (165 loc) · 6.42 KB
/
build-package.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
name: Build packages
on:
push:
paths:
- luci/**
- package/**
workflow_dispatch:
inputs:
packages:
type: string
description: "empty only build changed or input special package names or input all will build all"
debug:
type: boolean
default: false
jobs:
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
archs: ${{ steps.set_env.outputs.archs }}
openwrt_dir: ${{ steps.set_env.outputs.openwrt_dir }}
openwrt_branch: ${{ steps.set_env.outputs.openwrt_branch }}
openwrt_builder_volume: ${{ steps.set_env.outputs.openwrt_builder_volume }}
artifact_packages_rel: ${{ steps.set_env.outputs.artifact_packages_rel }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set env
id: set_env
run: |
openwrt_dir=/data/openwrt
openwrt_branch="${GITHUB_REF#refs/heads/}"
echo "openwrt_dir=${openwrt_dir}" >> "$GITHUB_OUTPUT"
echo "openwrt_branch=${openwrt_branch}" >> "$GITHUB_OUTPUT"
openwrt_builder_volume=${{ vars.OPENWRT_BUILDER_VOLUME }}
echo "openwrt_builder_volume=${openwrt_builder_volume}" >> "$GITHUB_OUTPUT"
artifact_packages_rel=releases/packages-$(echo $openwrt_branch | sed 's|openwrt-||')
if [ "${openwrt_branch}" == "main" ];then
artifact_packages_rel=snapshots/packages
fi
echo "artifact_packages_rel=${artifact_packages_rel}" >> "$GITHUB_OUTPUT"
python3 -B ./.github/workflows/scripts/get_targets.py | while read v;do echo "$v" >> "$GITHUB_OUTPUT"; done
build:
name: Build ${{ matrix.arch }}
runs-on: ubuntu-latest
needs: setup
strategy:
fail-fast: false
matrix:
arch: ${{fromJson(needs.setup.outputs.archs)}}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine packages
run: |
EXTRA_FEEDS="src-git|openclash|https://github.com/vernesong/OpenClash.git;master"
echo "EXTRA_FEEDS=$EXTRA_FEEDS" >> $GITHUB_ENV
PACKAGES=
INPUT_PACKAGES="${{ inputs.packages }}"
if [[ "$INPUT_PACKAGES" =~ "luci" ]];then
PACKAGES+="luci-base "
fi
if [[ ! "$INPUT_PACKAGES" =~ "all" ]];then
# only detect packages with changes
PKG_ROOTS=$(find . -name Makefile | grep -v ".*/src/Makefile" | sed -e 's@./\(.*\)/Makefile@\1/@')
CHANGES=$(git diff --diff-filter=d --name-only ${{ github.event_name == 'push' && 'HEAD^' || '' }})
for ROOT in $PKG_ROOTS; do
for CHANGE in $CHANGES; do
if [[ "$CHANGE" == "$ROOT"* ]]; then
PACKAGES+=$(echo "$ROOT" | sed -e 's@.*/\(.*\)/@\1 @')
break
fi
done
done
for t in $INPUT_PACKAGES;do
flag=false
for s in $PACKAGES;do
if [[ "$t" == "$s" ]]; then
flag=true
break
fi
done
if [ $flag == "false" ];then
PACKAGES+="$t "
fi
done
PACKAGES="${PACKAGES:-luci-app-attendedsysupgrade}"
fi
echo "Building $PACKAGES"
echo "PACKAGES=$PACKAGES" >> $GITHUB_ENV
- name: Build
uses: openwrt/gh-action-sdk@v7
env:
ARCH: ${{ matrix.arch }}-${{ needs.setup.outputs.openwrt_branch }}
FEEDNAME: packages_ci
V: ${{ inputs.debug && 's' || '' }}
- name: Move created packages to project dir
run: |
ls -alR bin/packages
artifact_dir=bin/artifact/${{ matrix.arch }}/plugin
mkdir -p ${artifact_dir}
for t in $PACKAGES;do
find bin/packages/${{ matrix.arch }}/packages \( -name "$t*.ipk" -o -name "$t*.apk" \) -exec cp -rv {} ${artifact_dir} \; || true
done
for EXTRA_FEED in $EXTRA_FEEDS; do
EXTRA_FEED_NAME="$(echo "$EXTRA_FEED" | cut -d'|' -f2)"
find bin/packages/${{ matrix.arch }}/$EXTRA_FEED_NAME \( -name "*.ipk" -o -name "*.apk" \) -exec cp -rv {} ${artifact_dir} \; || true
done
find bin/packages/${{ matrix.arch }}/packages_ci \( -name "*.ipk" -o -name "*.apk" \) -exec cp -rv {} ${artifact_dir} \; || true
- name: Store packages
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.arch }}-packages
path: bin/artifact/
- name: Store logs
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.arch }}-logs
path: "logs/"
deploy:
name: Deploy
runs-on: self-hosted
needs: [setup,build]
if: always()
container:
image: openwrt/sdk:x86-64-${{ needs.setup.outputs.openwrt_branch }}
volumes:
- openwrt-sdk-x86-64-${{ needs.setup.outputs.openwrt_branch }}:/builder
- ${{ needs.setup.outputs.openwrt_builder_volume }}/:/data/
options: --user root --privileged --pull always
steps:
- name: Setup
working-directory: /builder
shell: su buildbot -c "bash {0}"
run: |
openwrt_mirror=https://mirrors.pku.edu.cn/openwrt
[ ! -f setup.sh ] || UPSTREAM_URL=${openwrt_mirror} bash setup.sh
make defconfig
mkdir -p /data/download/${{ needs.setup.outputs.artifact_packages_rel }}
- name: Download artifact
uses: actions/download-artifact@v4
with:
path: /data/download/${{ needs.setup.outputs.artifact_packages_rel }}
pattern: '*-packages'
merge-multiple: true
- name: Generate index
working-directory: /builder
shell: su buildbot -c "bash {0}"
run: |
sed -i -e 's|--sign $(BUILD_KEY_APK_SEC)|--allow-untrusted|' package/Makefile
for t in $(find /data/download/${{ needs.setup.outputs.artifact_packages_rel }} -type d -name 'plugin');do
make -j4 package/index V=s CONFIG_SIGNED_PACKAGES= PACKAGE_SUBDIRS=$t
done
clean:
name: Clean
runs-on: self-hosted
needs: [setup,build,deploy]
if: always()
steps:
- run: |
volume_names=$(docker volume ls -q | grep 'openwrt-sdk-x86-64-${{ needs.setup.outputs.openwrt_branch }}$' || true | xargs )
if [ -n "${volume_names}" ];then
docker volume rm $volume_names
fi