-
Notifications
You must be signed in to change notification settings - Fork 0
186 lines (159 loc) · 6.21 KB
/
sync.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
name: Sync
on:
schedule:
- cron: '0 1 * * *'
push:
paths:
- '.github/workflows/scripts/**'
- '.github/workflows/build-*'
- main.sh
workflow_dispatch:
jobs:
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
branchs: ${{ steps.set_env.outputs.branchs }}
openwrt_builder_volume: ${{ steps.set_env.outputs.openwrt_builder_volume }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set env
id: set_env
run: |
branchs=main
branchs+=$(echo;git ls-remote origin | sed -n 's|.*\(openwrt-*\)|\1|p' | xargs)
JSON='['
FIRST=1
for BRANCH in $branchs; do
TUPLE='"'"$(echo $BRANCH | cut -d "/" -f 1)"'"'
[[ $FIRST -ne 1 ]] && JSON="$JSON"','
JSON="$JSON""$TUPLE"
FIRST=0
done
JSON="$JSON"']'
echo -e "\n---- branchs ----\n"
echo "$JSON"
echo -e "\n---- branchs ----\n"
echo "branchs=$JSON" >> $GITHUB_OUTPUT
echo "openwrt_builder_volume=${{ vars.OPENWRT_BUILDER_VOLUME }}" >> "$GITHUB_OUTPUT"
plugin:
name: Plugin
needs: [setup]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
branch: ${{fromJson(needs.setup.outputs.branchs)}}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ matrix.branch }}
token: ${{ secrets.PAT }}
- name: Sync main
if: ${{ matrix.branch != 'main' }}
run: |
git clone ${{ github.server_url }}/${{ github.repository }} feeds/main
mkdir -p .github/workflows/
cp -rfv feeds/main/.github/workflows/scripts/ feeds/main/.github/workflows/build-* .github/workflows/
cp -rfv feeds/main/main.sh .
- name: Determine update
run: bash main.sh update
- name: Determine changes
run: |
git config user.name github-actions
git config user.email [email protected]
if [ -n "$(git status -s)" ];then
git pull && git add . && git commit -m "CI: sync code" && git push
fi
mirror:
name: Mirror
runs-on: self-hosted
needs: [setup]
strategy:
fail-fast: false
matrix:
branch: ${{fromJson(needs.setup.outputs.branchs)}}
container:
image: openwrt/sdk:x86-64-${{ matrix.branch }}
volumes:
- openwrt-sdk-x86-64-${{ matrix.branch }}:/builder
- ${{ needs.setup.outputs.openwrt_builder_volume }}/:/data/
options: --user root --privileged --pull always
steps:
- name: Set env
id: set_env
shell: bash
run: |
openwrt_branch_number=$(echo ${{ matrix.branch }} | sed 's|openwrt-||')
artifact_packages_rel=
if [ "${{ matrix.branch }}" == "main" ];then
artifact_packages_rel=snapshots/packages
else
artifact_packages_rel=releases/packages-${openwrt_branch_number}
fi
artifact_packages_bin=/builder/bin/download
artifact_packages_dir=${artifact_packages_bin}/$artifact_packages_rel
download_packages_bin=/data/download
download_packages_dir=${download_packages_bin}/$artifact_packages_rel
echo "openwrt_branch_number=${openwrt_branch_number}" >> "$GITHUB_OUTPUT"
echo "artifact_packages_rel=${artifact_packages_rel}" >> "$GITHUB_OUTPUT"
echo "artifact_packages_bin=${artifact_packages_bin}" >> "$GITHUB_OUTPUT"
echo "artifact_packages_dir=${artifact_packages_dir}" >> "$GITHUB_OUTPUT"
echo "download_packages_bin=${download_packages_bin}" >> "$GITHUB_OUTPUT"
echo "download_packages_dir=${download_packages_dir}" >> "$GITHUB_OUTPUT"
- 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 ${{ steps.set_env.outputs.artifact_packages_bin }}
mkdir -p ${{ steps.set_env.outputs.download_packages_dir }}
- name: Sync
working-directory: /builder
shell: su buildbot -c "bash {0}"
run: |
echo 'immortalwrt-org' > rsync-immortalwrt-password
chmod 600 rsync-immortalwrt-password
echo "
*vlmcsd*
luci-app-openclash*
" > include-packages
rsync --password-file=rsync-immortalwrt-password -avmR --include-from=include-packages --include=*/ --exclude=* \
rsync://[email protected]/firmware-public/${{ steps.set_env.outputs.artifact_packages_rel }} ${{ steps.set_env.outputs.artifact_packages_bin }}
(
cd ${{ steps.set_env.outputs.artifact_packages_dir }}
for t in `find -maxdepth 1 -type d -not -path . -exec basename {} \;`;do
plugin_rel=$t/plugin
mkdir -p $plugin_rel
find $t \( -name "*.ipk" -o -name "*.apk" \) -and \( -not -path '*plugin/*' \) -exec cp -rv {} ${plugin_rel} \;
rsync -avmR --include-from=/builder/include-packages --include=*/ --exclude=* --delete $plugin_rel ${{ steps.set_env.outputs.download_packages_dir }}
done
)
- 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 ${{ steps.set_env.outputs.download_packages_dir }} -type d -name 'plugin');do
echo "Generating index for package ${t}"
make -j4 package/index V=s CONFIG_SIGNED_PACKAGES= PACKAGE_SUBDIRS=$t
done
clean:
name: Clean
runs-on: self-hosted
needs: [setup,mirror]
strategy:
fail-fast: false
matrix:
branch: ${{fromJson(needs.setup.outputs.branchs)}}
if: always()
steps:
- run: |
volume_names=$(docker volume ls -q | grep 'openwrt-sdk-x86-64-${{ matrix.branch }}$' || true | xargs )
if [ -n "${volume_names}" ];then
docker volume rm $volume_names
fi