Răsfoiți Sursa

ci(release): reuse previous agent binaries when agent/VERSION is unchanged (#1469)

When the agent version matches the previous tag, the five agent assets are downloaded from that release, verified against its checksums.txt and extracted into the embed, instead of cross-compiling five architectures. The compile step remains as the fallback and runs whenever the agent version changed (each critical step in the reuse path aborts explicitly, since set -e does not apply inside a function called in a condition context).

Closes #1469
Nacho 1 lună în urmă
părinte
comite
35125aa0bf
1 a modificat fișierele cu 56 adăugiri și 0 ștergeri
  1. 56 0
      .github/workflows/release.yml

+ 56 - 0
.github/workflows/release.yml

@@ -75,7 +75,63 @@ jobs:
       # resuelve "agents/netpulse-agent-" + normalizeArch(arch) y esta mapea
       # armv7/armv7l/armhf -> arm, asi que el fichero se llama
       # netpulse-agent-arm (con GOARM=7), NO netpulse-agent-armv7 (#458).
+      # #1469: cuando agent/VERSION no cambió respecto al tag anterior, los
+      # binarios del agente son los mismos que la release previa: se
+      # descargan sus assets y se extraen al embed en vez de recompilar 5
+      # arquitecturas. Garantiza además embed == assets bit a bit. Cualquier
+      # fallo de la descarga o la verificación deja reused=false y el paso
+      # de compilación (fallback) corre encima, sobreescribiendo lo extraído.
+      - name: Reutiliza agentes del release anterior (si agent/VERSION no cambió)
+        id: agent-reuse
+        env:
+          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        run: |
+          set -e
+          PREV_TAG=$(git describe --tags --abbrev=0 --match 'v[0-9]*' HEAD^ 2>/dev/null || true)
+          AGENT_VERSION=${{ steps.version.outputs.agent }}
+          if [ -z "$PREV_TAG" ]; then
+            echo "sin tag anterior: se compila"
+            echo "reused=false" >> "$GITHUB_OUTPUT"
+            exit 0
+          fi
+          PREV_AGENT=$(git show "$PREV_TAG:agent/VERSION" 2>/dev/null | tr -d '[:space:]' || true)
+          if [ "$PREV_AGENT" != "$AGENT_VERSION" ]; then
+            echo "agente cambió ($PREV_AGENT -> $AGENT_VERSION): se compila"
+            echo "reused=false" >> "$GITHUB_OUTPUT"
+            exit 0
+          fi
+          reuse() {
+            # set -e NO aplica dentro de una función llamada en condición:
+            # cada paso crítico aborta explícitamente con || return 1.
+            TMP=$(mktemp -d) || return 1
+            cd "$TMP" || return 1
+            for arch in amd64 arm64 armv7 mipsle mips; do
+              gh release download "$PREV_TAG" --pattern "netpulse-agent_*_linux_${arch}.tar.gz" --clobber || return 1
+            done
+            # Los tarballs deben casar con el checksums.txt del release
+            # anterior (filtrado a los assets del agente).
+            gh release download "$PREV_TAG" --pattern checksums.txt --clobber || return 1
+            grep 'netpulse-agent_.*_linux_.*\.tar\.gz' checksums.txt > agent-checksums.txt || return 1
+            sha256sum -c agent-checksums.txt || return 1
+            NAMES="amd64:amd64 arm64:arm64 armv7:arm mipsle:mipsle mips:mips"
+            for pair in $NAMES; do
+              arch="${pair%%:*}"; name="${pair##*:}"
+              tarball=$(ls netpulse-agent_*_linux_${arch}.tar.gz) || return 1
+              tar xzf "$tarball" netpulse-agent || return 1
+              mv netpulse-agent "$GITHUB_WORKSPACE/server-go/internal/agentbin/agents/netpulse-agent-${name}" || return 1
+              chmod +x "$GITHUB_WORKSPACE/server-go/internal/agentbin/agents/netpulse-agent-${name}" || return 1
+            done
+          }
+          if reuse; then
+            echo "agente $AGENT_VERSION reutilizado de $PREV_TAG"
+            echo "reused=true" >> "$GITHUB_OUTPUT"
+          else
+            echo "::warning::reutilización del agente falló; se compila"
+            echo "reused=false" >> "$GITHUB_OUTPUT"
+          fi
+
       - name: Build agent binaries para embed (todas las arquitecturas)
+        if: steps.agent-reuse.outputs.reused != 'true'
         env:
           CGO_ENABLED: 0
           GOOS: linux