-
Notifications
You must be signed in to change notification settings - Fork 0
150 lines (125 loc) · 6.26 KB
/
build-image.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
name: Build images
on:
workflow_dispatch:
inputs:
openwrt_tag:
type: string
description: "eg: v23.05.5"
jobs:
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
targets: ${{ steps.set_env.outputs.targets }}
targets_subtargets: ${{ steps.set_env.outputs.targets_subtargets }}
targets_devices: ${{ steps.set_env.outputs.targets_devices }}
archs: ${{ steps.set_env.outputs.archs }}
openwrt_dir: ${{ steps.set_env.outputs.openwrt_dir }}
openwrt_tag: ${{ steps.set_env.outputs.openwrt_tag }}
openwrt_tag_version: ${{ steps.set_env.outputs.openwrt_tag_version }}
openwrt_branch: ${{ steps.set_env.outputs.openwrt_branch }}
openwrt_branch_number: ${{ steps.set_env.outputs.openwrt_branch_number }}
openwrt_builder_volume: ${{ steps.set_env.outputs.openwrt_builder_volume }}
artifact_targets_rel: ${{ steps.set_env.outputs.artifact_targets_rel }}
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/}"
openwrt_branch_number=$(echo $openwrt_branch | sed 's|openwrt-||')
openwrt_tag=${{ inputs.openwrt_tag }}
artifact_targets_rel=
artifact_packages_rel=
if [ "${openwrt_branch}" == "main" ];then
openwrt_tag=$openwrt_branch
artifact_targets_rel=snapshots/targets
artifact_packages_rel=snapshots/packages
else
openwrt_tag=${openwrt_tag:-$(curl -sL 'https://git.openwrt.org/?p=openwrt/openwrt.git;a=summary' | sed -n "s|.*OpenWrt \(v${openwrt_branch_number}.*\) Release.*|\1|p" | head -n 1)}
openwrt_tag_version=$(echo $openwrt_tag | sed 's|^v||')
artifact_targets_rel=releases/$openwrt_tag_version/targets
artifact_packages_rel=releases/packages-${openwrt_branch_number}
fi
echo "openwrt_builder_volume=${{ vars.OPENWRT_BUILDER_VOLUME }}" >> "$GITHUB_OUTPUT"
echo "openwrt_dir=${openwrt_dir}" >> "$GITHUB_OUTPUT"
echo "openwrt_branch=${openwrt_branch}" >> "$GITHUB_OUTPUT"
echo "openwrt_branch_number=${openwrt_branch_number}" >> "$GITHUB_OUTPUT"
echo "openwrt_tag=${openwrt_tag}" >> "$GITHUB_OUTPUT"
echo "openwrt_tag_version=${openwrt_tag_version}" >> "$GITHUB_OUTPUT"
echo "artifact_targets_rel=${artifact_targets_rel}" >> "$GITHUB_OUTPUT"
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.target }}/${{ matrix.subtarget }}
needs: setup
runs-on: self-hosted
strategy:
fail-fast: false
matrix:
include: ${{fromJson(needs.setup.outputs.targets_subtargets)}}
container:
image: openwrt/imagebuilder:${{ matrix.target }}-${{ matrix.subtarget }}-${{ needs.setup.outputs.openwrt_tag }}
volumes:
- openwrt-ib-${{ matrix.target }}-${{ matrix.subtarget }}-${{ needs.setup.outputs.openwrt_tag }}:/builder
- ${{ needs.setup.outputs.openwrt_builder_volume }}/:/data/
options: --user root --privileged --pull always
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Initialize
working-directory: /builder
run: python3 -m pip install jinja2
- name: Mirror
working-directory: /builder
shell: su buildbot -c "bash {0}"
run: |
openwrt_targets=/data/download/${{ needs.setup.outputs.artifact_targets_rel }}
mkdir -p $openwrt_targets bin
ln -snf ${openwrt_targets} bin/targets
openwrt_tag=${{ needs.setup.outputs.openwrt_tag }}
openwrt_mirror=https://mirrors.pku.edu.cn/openwrt
[ ! -f setup.sh ] || UPSTREAM_URL=${openwrt_mirror} bash setup.sh
sed -i 's|^CONFIG_SIGNATURE_CHECK|# \0|' .config
if [ "$openwrt_tag" == "main" ];then
id;pwd;ls -al
openwrt_plugin=$(sed -n -e 's|\(.*\)base\(\.*\)|\1plugin\2|p' repositories | sed -e "s|https://downloads.openwrt.org|http://openwrt-download.czy21-internal.com|")
sed -i -e "1i ${openwrt_plugin}" -e "s|https://downloads.openwrt.org|${openwrt_mirror}|" repositories
cat repositories
else
id;pwd;ls -al
(cd ${openwrt_targets}/../;ln -snf ../$(basename ${{ needs.setup.outputs.artifact_packages_rel }}) packages)
openwrt_plugin=$(sed -n -e 's|openwrt_base\(.*\)base$|openwrt_plugin\1plugin|p' repositories.conf | sed -e "s|https://downloads.openwrt.org|http://openwrt-download.czy21-internal.com|")
sed -i -e "s|https://downloads.openwrt.org|${openwrt_mirror}|" -e 's|^option check_signature|# \0|' -e "\$a ${openwrt_plugin}" repositories.conf
cat repositories.conf
fi
- name: Generate image
shell: su buildbot -c "bash {0}"
run: python3 -B .github/workflows/scripts/gen_image.py --openwrt-dir /builder --config config --target ${{ matrix.target }}/${{ matrix.subtarget }}
- name: Generate version
shell: su buildbot -c "bash {0}"
if: always()
run: |
wget https://downloads.openwrt.org/index.html -O /data/download/index.html
for t in $(ls /data/download/releases/ | grep "^[0-9]");do
sed -i -e "s|//archive.openwrt.org/\(releases/${t}\)|\1|" /data/download/index.html
done
python3 -B .github/workflows/scripts/gen_version.py --artifact-dir /data/download
clean:
name: Clean ${{ matrix.target }}/${{ matrix.subtarget }}
runs-on: self-hosted
needs: [setup,build]
strategy:
fail-fast: false
matrix:
include: ${{fromJson(needs.setup.outputs.targets_subtargets)}}
if: always()
steps:
- run: |
volume_names=$(docker volume ls -q | grep 'openwrt-ib-${{ matrix.target }}-${{ matrix.subtarget }}-${{ needs.setup.outputs.openwrt_tag }}$' || true | xargs )
if [ -n "${volume_names}" ];then
docker volume rm $volume_names
fi