mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-15 01:49:08 +02:00
* [infrastructure] Restrict the FreeBSD port job to stable releases The port scripts picked the target version by scraping the GitHub tags page and only dropped tags containing "rc". A canary tag such as v0.81.0-canary.pr-8098.1 sorts above the latest stable release, so the job tried to package a prerelease, and the page only lists ten tags, so a run of prereleases could leave no candidate at all. Both scripts now share one helper that reads the tags API, keeps MAJOR.MINOR.PATCH versions only, and rejects an explicitly requested prerelease. Go proxy downloads fail instead of hashing an error page. The job moves out of the release workflow into its own, so it runs on pushes to main, on release tags, and on pull requests that touch the scripts or the workflow itself. Prerelease tags skip the job, and a stable tag is packaged directly rather than whatever happens to be the latest release at the time. * [infrastructure] Keep the FreeBSD port job in the release workflow A separate workflow would rename the check and detach the job from the release run, so the job stays in release.yml behind a small trigger job that decides when it runs: pushes to main, stable release tags, and pull requests that touch the port scripts or the workflow. Prerelease tags and other branches skip it. Tags are now listed with git ls-remote, which returns every tag in one call and needs neither a token nor pagination, and the Go module proxy downloads are limited to HTTPS like the other fetches. * [infrastructure] Address Sonar findings in the FreeBSD port helper Read the version into a local and return explicitly from is_stable_version. * [infrastructure] Address review findings in the FreeBSD port job Only a full vMAJOR.MINOR.PATCH tag starts the port job, so a tag like v1.2 skips it instead of failing in the resolver. The diff detection steps use a glob array rather than parsing ls, and quote GITHUB_OUTPUT. A failed tag listing now stops the issue body script instead of writing an incomplete changelog, and a bare "v" argument is rejected rather than treated as a request for the latest release.
182 lines
5.8 KiB
Bash
Executable File
182 lines
5.8 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# FreeBSD Port Diff Generator for NetBird
|
|
#
|
|
# This script generates the diff file required for submitting a FreeBSD port update.
|
|
# It works on macOS, Linux, and FreeBSD by fetching files from the FreeBSD ports
|
|
# GitHub mirror and computing checksums from the Go module proxy.
|
|
#
|
|
# Usage: ./freebsd-port-diff.sh [new_version]
|
|
# Example: ./freebsd-port-diff.sh 0.60.7
|
|
#
|
|
# If no version is provided, it uses the latest stable release from GitHub.
|
|
# Prerelease versions (canary, rc, ...) are rejected: the port only tracks
|
|
# stable releases.
|
|
|
|
set -e
|
|
|
|
# shellcheck source=release_files/freebsd-port-lib.sh
|
|
source "$(dirname "${BASH_SOURCE[0]}")/freebsd-port-lib.sh"
|
|
|
|
GO_PROXY="https://proxy.golang.org/github.com/netbirdio/netbird/@v"
|
|
OUTPUT_DIR="${OUTPUT_DIR:-.}"
|
|
AWK_FIRST_FIELD='{print $1}'
|
|
|
|
compute_checksums() {
|
|
local version="$1"
|
|
local tmpdir
|
|
tmpdir=$(mktemp -d)
|
|
# shellcheck disable=SC2064
|
|
trap "rm -rf '$tmpdir'" EXIT
|
|
|
|
echo "Downloading files from Go module proxy for v${version}..." >&2
|
|
|
|
local mod_file="${tmpdir}/v${version}.mod"
|
|
local zip_file="${tmpdir}/v${version}.zip"
|
|
|
|
local -a curl_opts=(-fsL --proto '=https' --proto-redir '=https' --retry 3)
|
|
if ! curl "${curl_opts[@]}" "${GO_PROXY}/v${version}.mod" -o "$mod_file" 2>/dev/null || \
|
|
! curl "${curl_opts[@]}" "${GO_PROXY}/v${version}.zip" -o "$zip_file" 2>/dev/null; then
|
|
echo "Error: Could not download v${version} from the Go module proxy" >&2
|
|
return 1
|
|
fi
|
|
|
|
if [[ ! -s "$mod_file" ]] || [[ ! -s "$zip_file" ]]; then
|
|
echo "Error: Go module proxy returned empty files for v${version}" >&2
|
|
return 1
|
|
fi
|
|
|
|
local mod_sha256 mod_size zip_sha256 zip_size
|
|
|
|
if command -v sha256sum &>/dev/null; then
|
|
mod_sha256=$(sha256sum "$mod_file" | awk "$AWK_FIRST_FIELD")
|
|
zip_sha256=$(sha256sum "$zip_file" | awk "$AWK_FIRST_FIELD")
|
|
elif command -v shasum &>/dev/null; then
|
|
mod_sha256=$(shasum -a 256 "$mod_file" | awk "$AWK_FIRST_FIELD")
|
|
zip_sha256=$(shasum -a 256 "$zip_file" | awk "$AWK_FIRST_FIELD")
|
|
else
|
|
echo "Error: No sha256 command found" >&2
|
|
return 1
|
|
fi
|
|
|
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
mod_size=$(stat -f%z "$mod_file")
|
|
zip_size=$(stat -f%z "$zip_file")
|
|
else
|
|
mod_size=$(stat -c%s "$mod_file")
|
|
zip_size=$(stat -c%s "$zip_file")
|
|
fi
|
|
|
|
echo "TIMESTAMP = $(date +%s)"
|
|
echo "SHA256 (go/security_netbird/netbird-v${version}/v${version}.mod) = ${mod_sha256}"
|
|
echo "SIZE (go/security_netbird/netbird-v${version}/v${version}.mod) = ${mod_size}"
|
|
echo "SHA256 (go/security_netbird/netbird-v${version}/v${version}.zip) = ${zip_sha256}"
|
|
echo "SIZE (go/security_netbird/netbird-v${version}/v${version}.zip) = ${zip_size}"
|
|
return 0
|
|
}
|
|
|
|
generate_new_makefile() {
|
|
local new_version="$1"
|
|
local old_makefile="$2"
|
|
|
|
# Check if old version had PORTREVISION
|
|
if echo "$old_makefile" | grep -q "^PORTREVISION="; then
|
|
# Remove PORTREVISION line and update DISTVERSION
|
|
echo "$old_makefile" | \
|
|
sed "s/^DISTVERSION=.*/DISTVERSION= ${new_version}/" | \
|
|
grep -v "^PORTREVISION="
|
|
else
|
|
# Just update DISTVERSION
|
|
echo "$old_makefile" | \
|
|
sed "s/^DISTVERSION=.*/DISTVERSION= ${new_version}/"
|
|
fi
|
|
return 0
|
|
}
|
|
|
|
# Parse arguments
|
|
NEW_VERSION=$(resolve_target_version "${1:-}")
|
|
echo "Target version: ${NEW_VERSION}" >&2
|
|
|
|
OLD_VERSION=$(fetch_current_ports_version)
|
|
echo "Current FreeBSD ports version: ${OLD_VERSION}" >&2
|
|
|
|
if [[ "$OLD_VERSION" = "$NEW_VERSION" ]]; then
|
|
echo "Port is already at version ${NEW_VERSION}. Nothing to do." >&2
|
|
exit 0
|
|
fi
|
|
|
|
echo "" >&2
|
|
|
|
# Fetch current files
|
|
echo "Fetching current Makefile from FreeBSD ports..." >&2
|
|
OLD_MAKEFILE=$(fetch_ports_file "Makefile")
|
|
if [[ -z "$OLD_MAKEFILE" ]]; then
|
|
echo "Error: Could not fetch Makefile" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "Fetching current distinfo from FreeBSD ports..." >&2
|
|
OLD_DISTINFO=$(fetch_ports_file "distinfo")
|
|
if [[ -z "$OLD_DISTINFO" ]]; then
|
|
echo "Error: Could not fetch distinfo" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Generate new files
|
|
echo "Generating new Makefile..." >&2
|
|
NEW_MAKEFILE=$(generate_new_makefile "$NEW_VERSION" "$OLD_MAKEFILE")
|
|
|
|
echo "Computing checksums for new version..." >&2
|
|
NEW_DISTINFO=$(compute_checksums "$NEW_VERSION")
|
|
if [[ -z "$NEW_DISTINFO" ]]; then
|
|
echo "Error: Could not compute checksums" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Create temp files for diff
|
|
TMPDIR=$(mktemp -d)
|
|
# shellcheck disable=SC2064
|
|
trap "rm -rf '$TMPDIR'" EXIT
|
|
|
|
mkdir -p "${TMPDIR}/a/security/netbird" "${TMPDIR}/b/security/netbird"
|
|
|
|
echo "$OLD_MAKEFILE" > "${TMPDIR}/a/security/netbird/Makefile"
|
|
echo "$OLD_DISTINFO" > "${TMPDIR}/a/security/netbird/distinfo"
|
|
echo "$NEW_MAKEFILE" > "${TMPDIR}/b/security/netbird/Makefile"
|
|
echo "$NEW_DISTINFO" > "${TMPDIR}/b/security/netbird/distinfo"
|
|
|
|
# Generate diff
|
|
OUTPUT_FILE="${OUTPUT_DIR}/netbird-${NEW_VERSION}.diff"
|
|
|
|
echo "" >&2
|
|
echo "Generating diff..." >&2
|
|
|
|
# Generate diff and clean up temp paths to show standard a/b paths
|
|
(cd "${TMPDIR}" && diff -ruN "a/security/netbird" "b/security/netbird") > "$OUTPUT_FILE" || true
|
|
|
|
if [[ ! -s "$OUTPUT_FILE" ]]; then
|
|
echo "Error: Generated diff is empty" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "" >&2
|
|
echo "========================================="
|
|
echo "Diff saved to: ${OUTPUT_FILE}"
|
|
echo "========================================="
|
|
echo ""
|
|
cat "$OUTPUT_FILE"
|
|
echo ""
|
|
echo "========================================="
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo "1. Review the diff above"
|
|
echo "2. Submit to https://bugs.freebsd.org/bugzilla/"
|
|
echo "3. Use ./freebsd-port-issue-body.sh to generate the issue content"
|
|
echo ""
|
|
echo "For FreeBSD testing (optional but recommended):"
|
|
echo " cd /usr/ports/security/netbird"
|
|
echo " patch < ${OUTPUT_FILE}"
|
|
echo " make stage && make stage-qa && make package && make install"
|
|
echo " netbird status"
|
|
echo " make deinstall"
|