openwrt-package.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. name: openwrt-package
  2. # Builds the OpenWrt packages for the released agent and attaches them to the
  3. # published release:
  4. # - netpulse-agent as .ipk (24.10 SDK, mediatek/filogic) and .apk (25.12
  5. # SDK, armsr/armv8 -> aarch64_generic, instalable en aarch64 genérico y
  6. # en cortex-a53, cubriendo routers fuera de cortex-a53). Also built for
  7. # x86/64 (amd64 binary) since #672.
  8. # - luci-app-netpulse (arch all) as .ipk and .apk (#236).
  9. # - netpulse on-box server as .ipk and .apk (#364), also for x86/64 (#672).
  10. #
  11. # Triggered on v* tag pushes, the SAME event that runs release.yml. It does
  12. # not rely on the `release` event for goreleaser-published releases: goreleaser
  13. # creates releases with the workflow GITHUB_TOKEN, and events triggered by the
  14. # GITHUB_TOKEN do not start new workflow runs
  15. # (https://docs.github.com/en/actions/concepts/security/github_token). Publishing
  16. # a draft release creates its tag, so that flow also lands here through the push
  17. # event, and there is no `release: published` trigger on purpose: it fired a
  18. # second run of this same job for the same tag, and the two raced on the asset
  19. # name (#2197).
  20. on:
  21. push:
  22. tags: ['v*']
  23. workflow_dispatch:
  24. inputs:
  25. version:
  26. description: 'Release tag (ej: v2.6.0)'
  27. required: true
  28. permissions:
  29. contents: write
  30. jobs:
  31. package-agent:
  32. runs-on: ubuntu-latest
  33. strategy:
  34. fail-fast: false
  35. matrix:
  36. include:
  37. - sdk-version: 24.10.5
  38. sdk-target: mediatek/filogic
  39. format: ipk
  40. goarch: arm64
  41. - sdk-version: 25.12.5
  42. sdk-target: armsr/armv8
  43. format: apk
  44. goarch: arm64
  45. - sdk-version: 24.10.5
  46. sdk-target: x86/64
  47. format: ipk
  48. goarch: amd64
  49. - sdk-version: 25.12.5
  50. sdk-target: x86/64
  51. format: apk
  52. goarch: amd64
  53. steps:
  54. - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
  55. - name: Resolve release tag
  56. id: tag
  57. run: |
  58. if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
  59. echo "tag=${{ inputs.version }}" >> "$GITHUB_OUTPUT"
  60. elif [ "${{ github.event_name }}" = "push" ]; then
  61. echo "tag=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
  62. else
  63. echo "tag=${{ github.event.release.tag_name }}" >> "$GITHUB_OUTPUT"
  64. fi
  65. - name: Wait for agent tarballs on the release
  66. env:
  67. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  68. TAG: ${{ steps.tag.outputs.tag }}
  69. run: |
  70. for i in $(seq 1 80); do
  71. assets="$(gh release view "$TAG" --json assets --jq '.assets[].name' 2>/dev/null || true)"
  72. if printf '%s\n' "$assets" | grep -q "netpulse-agent_.*_linux_${{ matrix.goarch }}.tar.gz" \
  73. && printf '%s\n' "$assets" | grep -qx 'checksums.txt'; then
  74. echo "Agent tarballs and checksums present after $i attempts"
  75. exit 0
  76. fi
  77. echo "Waiting for agent tarballs and checksums ($i/80)..."
  78. sleep 15
  79. done
  80. echo "ERROR: agent tarballs or checksums not found on $TAG after 20 min" >&2
  81. exit 1
  82. - name: Download netpulse-agent ${{ matrix.goarch }} binary
  83. env:
  84. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  85. TAG: ${{ steps.tag.outputs.tag }}
  86. run: |
  87. gh release download "$TAG" -p "netpulse-agent_*_linux_${{ matrix.goarch }}.tar.gz" -p checksums.txt --dir /tmp/agent
  88. cd /tmp/agent
  89. asset="$(ls netpulse-agent_*_linux_${{ matrix.goarch }}.tar.gz)"
  90. awk -v n="$asset" '{candidate=$NF; sub(/^\*/, "", candidate); if (candidate == n) print}' checksums.txt > agent-checksums.txt
  91. test -s agent-checksums.txt
  92. sha256sum -c agent-checksums.txt
  93. tar xzf "$asset"
  94. ls -la netpulse-agent
  95. file netpulse-agent
  96. - name: Package ${{ matrix.format }} (SDK ${{ matrix.sdk-version }})
  97. env:
  98. TAG: ${{ steps.tag.outputs.tag }}
  99. run: |
  100. chmod +x deploy/openwrt/package.sh
  101. export PKG_VERSION="${TAG#v}"
  102. export PKG_RELEASE="1"
  103. deploy/openwrt/package.sh \
  104. "${{ matrix.sdk-version }}" \
  105. "${{ matrix.sdk-target }}" \
  106. "" \
  107. "${{ matrix.format }}" \
  108. /tmp/agent/netpulse-agent
  109. - name: Upload to release
  110. env:
  111. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  112. TAG: ${{ steps.tag.outputs.tag }}
  113. run: |
  114. echo "Packages generated:"
  115. ls -la dist/packages/
  116. existing="$(gh release view "$TAG" --json assets --jq '.assets[].name' || true)"
  117. missing=()
  118. for f in dist/packages/*.${{ matrix.format }}; do
  119. if grep -qxF "$(basename "$f")" <<<"$existing"; then
  120. echo "already attached, skipping: $(basename "$f")"
  121. else
  122. missing+=("$f")
  123. fi
  124. done
  125. if [ ${#missing[@]} -gt 0 ]; then
  126. gh release upload "$TAG" "${missing[@]}" --clobber
  127. else
  128. echo "all package assets already attached"
  129. fi
  130. package-luci:
  131. runs-on: ubuntu-latest
  132. strategy:
  133. fail-fast: false
  134. matrix:
  135. include:
  136. - sdk-version: 24.10.5
  137. sdk-target: mediatek/filogic
  138. format: ipk
  139. - sdk-version: 25.12.5
  140. sdk-target: qualcommax/ipq807x
  141. format: apk
  142. steps:
  143. - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
  144. - name: Resolve release tag
  145. id: tag
  146. run: |
  147. if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
  148. echo "tag=${{ inputs.version }}" >> "$GITHUB_OUTPUT"
  149. elif [ "${{ github.event_name }}" = "push" ]; then
  150. echo "tag=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
  151. else
  152. echo "tag=${{ github.event.release.tag_name }}" >> "$GITHUB_OUTPUT"
  153. fi
  154. - name: Wait for agent tarballs on the release
  155. env:
  156. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  157. TAG: ${{ steps.tag.outputs.tag }}
  158. run: |
  159. for i in $(seq 1 80); do
  160. if gh release view "$TAG" --json assets --jq '.assets[].name' 2>/dev/null | grep -q 'netpulse-agent_.*_linux_arm64.tar.gz'; then
  161. echo "Release ready after $i attempts"
  162. exit 0
  163. fi
  164. echo "Waiting for release assets ($i/80)..."
  165. sleep 15
  166. done
  167. echo "ERROR: agent tarballs not found on $TAG after 20 min" >&2
  168. exit 1
  169. - name: Package luci-app-netpulse ${{ matrix.format }} (SDK ${{ matrix.sdk-version }})
  170. env:
  171. TAG: ${{ steps.tag.outputs.tag }}
  172. run: |
  173. chmod +x deploy/openwrt/package-luci.sh
  174. export PKG_VERSION="${TAG#v}"
  175. export PKG_RELEASE="1"
  176. deploy/openwrt/package-luci.sh \
  177. "${{ matrix.sdk-version }}" \
  178. "${{ matrix.sdk-target }}" \
  179. "" \
  180. "${{ matrix.format }}"
  181. - name: Upload to release
  182. env:
  183. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  184. TAG: ${{ steps.tag.outputs.tag }}
  185. run: |
  186. echo "LuCI packages generated:"
  187. ls -la dist/packages/
  188. existing="$(gh release view "$TAG" --json assets --jq '.assets[].name' || true)"
  189. missing=()
  190. for f in dist/packages/*.${{ matrix.format }}; do
  191. if grep -qxF "$(basename "$f")" <<<"$existing"; then
  192. echo "already attached, skipping: $(basename "$f")"
  193. else
  194. missing+=("$f")
  195. fi
  196. done
  197. if [ ${#missing[@]} -gt 0 ]; then
  198. gh release upload "$TAG" "${missing[@]}" --clobber
  199. else
  200. echo "all LuCI assets already attached"
  201. fi
  202. package-server:
  203. runs-on: ubuntu-latest
  204. strategy:
  205. fail-fast: false
  206. matrix:
  207. include:
  208. - sdk-version: 24.10.5
  209. sdk-target: mediatek/filogic
  210. format: ipk
  211. goarch: arm64
  212. - sdk-version: 25.12.5
  213. sdk-target: armsr/armv8
  214. format: apk
  215. goarch: arm64
  216. - sdk-version: 24.10.5
  217. sdk-target: x86/64
  218. format: ipk
  219. goarch: amd64
  220. - sdk-version: 25.12.5
  221. sdk-target: x86/64
  222. format: apk
  223. goarch: amd64
  224. steps:
  225. - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
  226. - name: Resolve release tag
  227. id: tag
  228. run: |
  229. if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
  230. echo "tag=${{ inputs.version }}" >> "$GITHUB_OUTPUT"
  231. elif [ "${{ github.event_name }}" = "push" ]; then
  232. echo "tag=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
  233. else
  234. echo "tag=${{ github.event.release.tag_name }}" >> "$GITHUB_OUTPUT"
  235. fi
  236. - name: Wait for server tarball on the release
  237. env:
  238. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  239. TAG: ${{ steps.tag.outputs.tag }}
  240. run: |
  241. for i in $(seq 1 80); do
  242. assets="$(gh release view "$TAG" --json assets --jq '.assets[].name' 2>/dev/null || true)"
  243. if printf '%s\n' "$assets" | grep -q "netpulse_.*_linux_${{ matrix.goarch }}.tar.gz" \
  244. && printf '%s\n' "$assets" | grep -qx 'checksums.txt'; then
  245. echo "Server tarball and checksums present after $i attempts"
  246. exit 0
  247. fi
  248. echo "Waiting for server tarball and checksums ($i/80)..."
  249. sleep 15
  250. done
  251. echo "ERROR: server tarball or checksums not found on $TAG after 20 min" >&2
  252. exit 1
  253. - name: Download netpulse server ${{ matrix.goarch }} binary
  254. env:
  255. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  256. TAG: ${{ steps.tag.outputs.tag }}
  257. run: |
  258. gh release download "$TAG" -p "netpulse_*_linux_${{ matrix.goarch }}.tar.gz" -p checksums.txt --dir /tmp/server
  259. cd /tmp/server
  260. asset="$(ls netpulse_*_linux_${{ matrix.goarch }}.tar.gz)"
  261. awk -v n="$asset" '{candidate=$NF; sub(/^\*/, "", candidate); if (candidate == n) print}' checksums.txt > server-checksums.txt
  262. test -s server-checksums.txt
  263. sha256sum -c server-checksums.txt
  264. tar xzf "$asset"
  265. ls -la netpulse
  266. file netpulse
  267. - name: Package ${{ matrix.format }} (SDK ${{ matrix.sdk-version }})
  268. env:
  269. TAG: ${{ steps.tag.outputs.tag }}
  270. run: |
  271. chmod +x deploy/openwrt/package-server.sh
  272. export PKG_VERSION="${TAG#v}"
  273. export PKG_RELEASE="1"
  274. deploy/openwrt/package-server.sh \
  275. "${{ matrix.sdk-version }}" \
  276. "${{ matrix.sdk-target }}" \
  277. "" \
  278. "${{ matrix.format }}" \
  279. /tmp/server/netpulse
  280. - name: Upload to release
  281. env:
  282. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  283. TAG: ${{ steps.tag.outputs.tag }}
  284. run: |
  285. echo "Server packages generated:"
  286. ls -la dist/packages/
  287. # netpulse_<v>_*.ipk (no colisiona con el tarball netpulse_<v>_linux_*)
  288. files=$(ls dist/packages/netpulse[-_]*.${{ matrix.format }} 2>/dev/null || true)
  289. if [ -z "$files" ]; then
  290. echo "ERROR: no server package produced" >&2
  291. exit 1
  292. fi
  293. existing="$(gh release view "$TAG" --json assets --jq '.assets[].name' || true)"
  294. missing=()
  295. for f in $files; do
  296. if grep -qxF "$(basename "$f")" <<<"$existing"; then
  297. echo "already attached, skipping: $(basename "$f")"
  298. else
  299. missing+=("$f")
  300. fi
  301. done
  302. if [ ${#missing[@]} -gt 0 ]; then
  303. gh release upload "$TAG" "${missing[@]}" --clobber
  304. else
  305. echo "all server package assets already attached"
  306. fi