forked from yury-sannikov/awg-openwrt
-
Notifications
You must be signed in to change notification settings - Fork 39
184 lines (147 loc) · 7.62 KB
/
build-to-all-latest-snapshots.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
name: Build AmneziaWG for snapshot OpenWRT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
on:
push:
tags:
- "SNAPSHOT"
schedule:
- cron: '0 */4 * * *'
jobs:
generate-config:
runs-on: ubuntu-latest
outputs:
job-config: ${{ steps.generate-config.outputs.job-config }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20.16.0'
- name: Install dependencies
run: npm install
- name: Generate Job Config
id: generate-config
run: node index.js SNAPSHOT
build:
name: "${{ matrix.build_env.tag }} - ${{ matrix.build_env.pkgarch}} :: ${{ matrix.build_env.target}}/${{ matrix.build_env.subtarget}} build"
runs-on: ubuntu-latest
needs: generate-config
strategy:
matrix:
build_env: ${{ fromJson(needs.generate-config.outputs.job-config) }}
fail-fast: false
steps:
- name: Check if release file exists
id: check_release
run: |
postfix="${{ matrix.build_env.tag }}_${{ matrix.build_env.vermagic }}_${{ matrix.build_env.pkgarch}}_${{ matrix.build_env.target}}_${{ matrix.build_env.subtarget}}"
RELEASE_FILE="kmod-amneziawg_${postfix}.ipk"
echo "Checking for release file: $RELEASE_FILE"
# Используем GitHub CLI для проверки наличия файла в релизе
if gh release view $matrix.build_env.tag --repo Slava-Shchipunov/awg-openwrt --json assets --jq ".assets | .[].name" | grep -q "$RELEASE_FILE"; then
echo "Release file $RELEASE_FILE already exists. Skipping job."
echo "FILE_EXISTS=true" >> $GITHUB_ENV
else
echo "FILE_EXISTS=false" >> $GITHUB_ENV
fi
# Прерываем job'у, если файл уже существует
- name: Skip job if release file exists
if: env.FILE_EXISTS == 'true'
run: |
echo "Skipping job as release file already exists."
exit 0
- name: Get snapshot commit SHA and device ARCH
if: env.FILE_EXISTS == 'false'
run: |
PROFILE_URL="https://downloads.openwrt.org/snapshots/targets/${{ matrix.build_env.target}}/${{ matrix.build_env.subtarget}}/profiles.json"
SNAPSHOT_COMMIT_SHA=$(wget -q $PROFILE_URL -O- | tr ',' '\n' | grep "version_code"| awk -F: '{print $2}' | tr -d '"' | awk -F- '{print $2}')
echo "Snapshot commit sha: $SNAPSHOT_COMMIT_SHA"
echo "SNAPSHOT_COMMIT_SHA=$SNAPSHOT_COMMIT_SHA" >> $GITHUB_ENV
DEVICE_ARCH=$(wget -q $PROFILE_URL -O- | tr ',' '\n' | grep "arch_packages"| awk -F: '{print $2}' | tr -d '"')
echo "Device ARCH: $DEVICE_ARCH"
echo "DEVICE_ARCH=$DEVICE_ARCH" >> $GITHUB_ENV
- uses: actions/checkout@v4
if: env.FILE_EXISTS == 'false'
with:
repository: openwrt/openwrt
fetch-depth: 0
- name: Checkout snapshot commit in openwrt repo
if: env.FILE_EXISTS == 'false'
run: git checkout ${{ env.SNAPSHOT_COMMIT_SHA}}
- name: Building kernel and tools
if: env.FILE_EXISTS == 'false'
run: |
echo "pkgarch: ${{ matrix.build_env.pkgarch}}, target:${{ matrix.build_env.target}}, subtarget: ${{ matrix.build_env.subtarget}}"
# Setup & install feeds
wget https://downloads.openwrt.org/snapshots/targets/${{ matrix.build_env.target}}/${{ matrix.build_env.subtarget}}/feeds.buildinfo -O feeds.conf
echo "src-git awgopenwrt https://github.com/Slava-Shchipunov/awg-openwrt.git" >> ./feeds.conf
./scripts/feeds update && ./scripts/feeds install -a
# Setup config with AWG and dependencies
wget https://downloads.openwrt.org/snapshots/targets/${{ matrix.build_env.target}}/${{ matrix.build_env.subtarget}}/config.buildinfo -O .config
echo "CONFIG_PACKAGE_kmod-amneziawg=m" >> .config
echo "CONFIG_PACKAGE_amneziawg-tools=y" >> .config
echo "CONFIG_PACKAGE_luci-app-amneziawg=y" >> .config
echo "CONFIG_PACKAGE_kmod-crypto-lib-chacha20=m" >> .config
echo "CONFIG_PACKAGE_kmod-crypto-lib-chacha20poly1305=m" >> .config
echo "CONFIG_PACKAGE_kmod-crypto-chacha20poly1305=m" >> .config
make defconfig
echo " > make tools/install"
make tools/install -i -j `nproc`
cat ./build_dir/target-*/linux-*/linux-*/.vermagic || true
echo " > make toolchain/install"
make toolchain/install -i -j `nproc`
cat ./build_dir/target-*/linux-*/linux-*/.vermagic || true
# compile kernel module
echo " > make target/linux/compile"
make target/linux/compile -i -j `nproc` V=s
VERMAGIC=`cat ./build_dir/target-*/linux-*/linux-*/.vermagic`
VERMAGIC_EXPECTED=${{ matrix.build_env.vermagic }}
if [ "$VERMAGIC" != "$VERMAGIC_EXPECTED" ]; then
echo Vermagic mismatch: $VERMAGIC, expected $VERMAGIC_EXPECTED
exit 1
fi
- name: Build AmneziaWG
if: env.FILE_EXISTS == 'false'
run: |
VERMAGIC=`cat ./build_dir/target-*/linux-*/linux-*/.vermagic`
echo "Vermagic: $VERMAGIC"
VERMAGIC_EXPECTED=${{ matrix.build_env.vermagic }}
if [ "$VERMAGIC" != "$VERMAGIC_EXPECTED" ]; then
echo Vermagic mismatch: $VERMAGIC, expected $VERMAGIC_EXPECTED
exit 1
fi
# Ignore kmod build for some targets, replace with the awg-go
make package/kmod-amneziawg/{clean,download,prepare} V=s || true
make package/kmod-amneziawg/compile V=s || true
make package/luci-app-amneziawg/{clean,download,prepare}
make package/luci-app-amneziawg/compile V=s
make V=s package/amneziawg-tools/{clean,download,prepare}
make V=s package/amneziawg-tools/compile
- name: Prepare artifacts
if: env.FILE_EXISTS == 'false'
run: |
tag_name=${{ github.ref_name }}
mkdir -p awgrelease
postfix="${{ matrix.build_env.tag }}_${{ matrix.build_env.vermagic }}_${{ matrix.build_env.pkgarch}}_${{ matrix.build_env.target}}_${{ matrix.build_env.subtarget}}"
cp bin/packages/${{ matrix.build_env.pkgarch }}/awgopenwrt/amneziawg-tools_*.ipk awgrelease/amneziawg-tools_${postfix}.ipk
cp bin/packages/${{ matrix.build_env.pkgarch }}/awgopenwrt/luci-app-amneziawg_*.ipk awgrelease/luci-app-amneziawg_${postfix}.ipk
cp bin/targets/${{ matrix.build_env.target}}/${{ matrix.build_env.subtarget}}/packages/kmod-amneziawg_*.ipk awgrelease/kmod-amneziawg_${postfix}.ipk
- name: Delete old release assets
if: env.FILE_EXISTS == 'false'
run: |
postfix="${{ matrix.build_env.pkgarch}}_${{ matrix.build_env.target}}_${{ matrix.build_env.subtarget}}"
echo "Looking for old release files ending with: ${postfix}"
# Получаем список всех артефактов релиза
assets=$(gh release view "${{ matrix.build_env.tag }}" --repo Slava-Shchipunov/awg-openwrt --json assets --jq ".assets | .[] | select(.name | endswith(\"$postfix.ipk\")) | .id")
# Удаляем найденные артефакты
for asset_id in $assets; do
echo "Deleting asset with ID: $asset_id"
gh release delete-asset "${{ matrix.build_env.tag }}" "$asset_id" --repo Slava-Shchipunov/awg-openwrt
done
- name: Release
if: env.FILE_EXISTS == 'false'
uses: softprops/action-gh-release@v1
with:
files: awgrelease/*.ipk