diff --git a/.github/workflows/run-obs.yml b/.github/workflows/run-obs.yml index ecefc2bc..c6eba63e 100644 --- a/.github/workflows/run-obs.yml +++ b/.github/workflows/run-obs.yml @@ -367,6 +367,16 @@ jobs: EOF chmod 600 ~/.config/osc/oscrc + # Cache OBS bundled Go toolchains + - name: Cache OBS bundled Go toolchains (dms-git) + if: contains(steps.packages.outputs.packages, 'dms-git') + uses: actions/cache@v4 + with: + path: /home/runner/.cache/dms-obs-go-toolchain + key: dms-obs-go-toolchain-${{ runner.os }}-${{ hashFiles('core/go.mod') }} + restore-keys: | + dms-obs-go-toolchain-${{ runner.os }}- + - name: Upload to OBS id: upload env: diff --git a/distro/debian/dms-git/debian/control b/distro/debian/dms-git/debian/control index 2e30550c..2b1ee7a8 100644 --- a/distro/debian/dms-git/debian/control +++ b/distro/debian/dms-git/debian/control @@ -3,7 +3,6 @@ Section: x11 Priority: optional Maintainer: Avenge Media Build-Depends: debhelper-compat (= 13), - golang-go | golang (>= 2:1.22~) | golang-any Standards-Version: 4.6.2 Homepage: https://github.com/AvengeMedia/DankMaterialShell Vcs-Browser: https://github.com/AvengeMedia/DankMaterialShell diff --git a/distro/debian/dms-git/debian/rules b/distro/debian/dms-git/debian/rules index ecfa6fde..7163ee0e 100755 --- a/distro/debian/dms-git/debian/rules +++ b/distro/debian/dms-git/debian/rules @@ -27,20 +27,30 @@ override_dh_auto_build: # Verify core directory exists (native package format has source at root) test -d core || (echo "ERROR: core directory not found!" && exit 1) - # Pin go.mod and vendor/modules.txt to the installed Go toolchain version - GO_INSTALLED=$$(go version | grep -oP 'go\K[0-9]+\.[0-9]+'); \ - sed -i "s/^go [0-9]\+\.[0-9]\+\(\.[0-9]*\)\?$$/go $${GO_INSTALLED}/" core/go.mod; \ - sed -i "s/^\(## explicit; go \)[0-9]\+\.[0-9]\+\(\.[0-9]*\)\?$$/\1$${GO_INSTALLED}/" core/vendor/modules.txt - - # Build dms-cli (single shell to preserve variables; arch: Debian amd64/arm64 -> Makefile amd64/arm64) + # Bundled Go at repo root (go$$VER.linux-{amd64,arm64}.tar.gz); packaged via obs-upload.sh + GO_TOOLCHAIN_VERSION=$$(grep -m1 '^go ' core/go.mod | awk '{print $$2}'); \ + case "$(DEB_HOST_ARCH)" in \ + amd64) GO_LINUX_ARCH=amd64 ;; \ + arm64) GO_LINUX_ARCH=arm64 ;; \ + *) echo "ERROR: Unsupported architecture: $(DEB_HOST_ARCH)" && exit 1 ;; \ + esac; \ + GO_TARBALL="$(CURDIR)/go$$GO_TOOLCHAIN_VERSION.linux-$$GO_LINUX_ARCH.tar.gz"; \ + test -f "$$GO_TARBALL" || (echo "ERROR: Missing bundled Go toolchain $$GO_TARBALL" && exit 1); \ + rm -rf "$(CURDIR)/go-bootstrap" "$(CURDIR)/.go-toolchain"; \ + mkdir -p "$(CURDIR)/go-bootstrap"; \ + tar -xzf "$$GO_TARBALL" -C "$(CURDIR)/go-bootstrap"; \ + mv "$(CURDIR)/go-bootstrap/go" "$(CURDIR)/.go-toolchain"; \ + export PATH="$(CURDIR)/.go-toolchain/bin:$$PATH"; \ + export GOROOT="$(CURDIR)/.go-toolchain"; \ + go version; \ + sed -i "s/^go [0-9]\+\.[0-9]\+\(\.[0-9]*\)\?$$/go $$GO_TOOLCHAIN_VERSION/" core/go.mod; \ + sed -i "s/^\(## explicit; go \)[0-9]\+\.[0-9]\+\(\.[0-9]*\)\?$$/\1$$GO_TOOLCHAIN_VERSION/" core/vendor/modules.txt; \ VERSION="$(UPSTREAM_VERSION)"; \ COMMIT=$$(echo "$(UPSTREAM_VERSION)" | grep -oP '(?<=git)[0-9]+\.[a-f0-9]+' | cut -d. -f2 | head -c8 || echo "unknown"); \ if [ "$(DEB_HOST_ARCH)" = "amd64" ]; then \ MAKE_ARCH=amd64; \ - BINARY_NAME=dms-linux-amd64; \ elif [ "$(DEB_HOST_ARCH)" = "arm64" ]; then \ MAKE_ARCH=arm64; \ - BINARY_NAME=dms-linux-arm64; \ else \ echo "ERROR: Unsupported architecture: $(DEB_HOST_ARCH)" && exit 1; \ fi; \ @@ -80,4 +90,5 @@ override_dh_auto_clean: rm -f dms rm -rf core/bin rm -rf debian/tmp-home + rm -rf go-bootstrap .go-toolchain dh_auto_clean diff --git a/distro/opensuse/dms-git.spec b/distro/opensuse/dms-git.spec index b74e0b25..53340cb9 100644 --- a/distro/opensuse/dms-git.spec +++ b/distro/opensuse/dms-git.spec @@ -1,7 +1,8 @@ %global debug_package %{nil} +%global go_toolchain_version 1.26.1 Name: dms-git -Version: 1.0.2+git2528.d336866f +Version: 1.4.0+git2528.d336866f Release: 1%{?dist} Epoch: 2 Summary: DankMaterialShell - Material 3 inspired shell (git nightly) @@ -9,9 +10,9 @@ Summary: DankMaterialShell - Material 3 inspired shell (git nightly) License: MIT URL: https://github.com/AvengeMedia/DankMaterialShell Source0: dms-git-source.tar.gz +Source1: go%{go_toolchain_version}.linux-amd64.tar.gz +Source2: go%{go_toolchain_version}.linux-arm64.tar.gz -BuildRequires: golang >= 1.22 -BuildRequires: golang-packaging BuildRequires: git-core BuildRequires: systemd-rpm-macros @@ -47,6 +48,28 @@ and fixes. Includes pre-built dms CLI binary and QML shell files. test -d core/vendor || (echo "ERROR: Go vendor directory missing!" && exit 1) %build +# Bundled Go toolchain +case "%{_arch}" in + x86_64) + GO_TARBALL="%{_sourcedir}/go%{go_toolchain_version}.linux-amd64.tar.gz" + ;; + aarch64) + GO_TARBALL="%{_sourcedir}/go%{go_toolchain_version}.linux-arm64.tar.gz" + ;; + *) + echo "Unsupported architecture for bundled Go: %{_arch}" + exit 1 + ;; +esac + +rm -rf "%{_builddir}/go-bootstrap" "%{_builddir}/.go-toolchain" +mkdir -p "%{_builddir}/go-bootstrap" +tar -xzf "$GO_TARBALL" -C "%{_builddir}/go-bootstrap" +mv "%{_builddir}/go-bootstrap/go" "%{_builddir}/.go-toolchain" + +export GOROOT="%{_builddir}/.go-toolchain" +export PATH="$GOROOT/bin:$PATH" + # Create Go cache directories (OBS build env may have restricted HOME) export HOME=%{_builddir}/go-home export GOCACHE=%{_builddir}/go-cache @@ -56,10 +79,11 @@ mkdir -p $HOME $GOCACHE $GOMODCACHE # OBS has no network access, so use local toolchain only export GOTOOLCHAIN=local -# Pin go.mod and vendor/modules.txt to the installed Go toolchain version -GO_INSTALLED=$(go version | grep -oP 'go\K[0-9]+\.[0-9]+') -sed -i "s/^go [0-9]\+\.[0-9]\+\(\.[0-9]*\)\?$/go ${GO_INSTALLED}/" core/go.mod -sed -i "s/^\(## explicit; go \)[0-9]\+\.[0-9]\+\(\.[0-9]*\)\?$/\1${GO_INSTALLED}/" core/vendor/modules.txt +go version + +# Pin go.mod and vendor/modules.txt to the bundled Go toolchain version +sed -i "s/^go [0-9]\+\.[0-9]\+\(\.[0-9]*\)\?$/go %{go_toolchain_version}/" core/go.mod +sed -i "s/^\(## explicit; go \)[0-9]\+\.[0-9]\+\(\.[0-9]*\)\?$/\1%{go_toolchain_version}/" core/vendor/modules.txt # Extract version info for embedding in binary VERSION="%{version}" diff --git a/distro/scripts/obs-upload.sh b/distro/scripts/obs-upload.sh index 288e8528..c2ff90f1 100755 --- a/distro/scripts/obs-upload.sh +++ b/distro/scripts/obs-upload.sh @@ -115,6 +115,40 @@ osc_retry() { done } +# Bundled Go for dms-git OBS builds (offline VM); filenames must match distro/opensuse/dms-git.spec Source1/2. +GO_TOOLCHAIN_CACHE="${GO_TOOLCHAIN_CACHE:-$HOME/.cache/dms-obs-go-toolchain}" + +dms_git_go_toolchain_version() { + grep -m1 '^go ' "$REPO_ROOT/core/go.mod" 2>/dev/null | awk '{print $2}' +} + +ensure_dms_git_go_tarballs() { + local dest="$1" + local ver arch url cached + ver="$(dms_git_go_toolchain_version)" + if [[ -z "$ver" ]]; then + echo "ERROR: Could not read Go version from core/go.mod" + exit 1 + fi + mkdir -p "$GO_TOOLCHAIN_CACHE/$ver" + for arch in amd64 arm64; do + url="https://go.dev/dl/go${ver}.linux-${arch}.tar.gz" + cached="$GO_TOOLCHAIN_CACHE/$ver/go${ver}.linux-${arch}.tar.gz" + if [[ ! -f "$cached" ]]; then + echo " Downloading Go ${ver} (${arch})…" + if wget -q -O "${cached}.tmp" "$url" 2>/dev/null || curl -L -f -s -o "${cached}.tmp" "$url"; then + mv "${cached}.tmp" "$cached" + else + rm -f "${cached}.tmp" + echo "ERROR: Failed to download $url" + exit 1 + fi + fi + cp -f "$cached" "$dest/go${ver}.linux-${arch}.tar.gz" + echo " ✓ Go toolchain ready: $dest/go${ver}.linux-${arch}.tar.gz" + done +} + # Parameters: # $1 = PROJECT # $2 = PACKAGE @@ -205,9 +239,15 @@ update_debian_dms_greeter_service() { update_opensuse_git_spec() { local spec_path="$1" + local go_ver if [[ -z "$spec_path" || ! -f "$spec_path" ]]; then return 0 fi + go_ver="$(dms_git_go_toolchain_version)" + if [[ -n "$go_ver" ]] && grep -q '^%global go_toolchain_version' "$spec_path"; then + sed -i "s/^%global go_toolchain_version .*/%global go_toolchain_version ${go_ver}/" "$spec_path" + echo " Synced %global go_toolchain_version to ${go_ver} (core/go.mod)" + fi if [[ -n "$CHANGELOG_VERSION" ]]; then echo " Updating OpenSUSE spec to version $CHANGELOG_VERSION" sed -i "s/^Version:.*/Version: $CHANGELOG_VERSION/" "$spec_path" @@ -438,7 +478,7 @@ if [[ "$UPLOAD_OPENSUSE" == true ]] && [[ -f "distro/opensuse/$PACKAGE.spec" ]]; echo " - Copying $PACKAGE.spec for OpenSUSE" cp "distro/opensuse/$PACKAGE.spec" "$WORK_DIR/" - if [[ "$PACKAGE" == *"-git" ]] && [[ -n "$CHANGELOG_VERSION" ]]; then + if [[ "$PACKAGE" == *"-git" ]]; then update_opensuse_git_spec "$WORK_DIR/$PACKAGE.spec" elif [[ "$PACKAGE" == "dms-greeter" ]] && [[ -n "$CHANGELOG_VERSION" ]]; then DMS_GREETER_BASE_VERSION=$(echo "$CHANGELOG_VERSION" | sed -E 's/^([0-9]+(\.[0-9]+)*).*/\1/') @@ -570,6 +610,11 @@ if [[ "$UPLOAD_OPENSUSE" == true ]] && [[ "$UPLOAD_DEBIAN" == false ]] && [[ -f cd "$REPO_ROOT" rm -rf "$OBS_TARBALL_DIR" + + if [[ "$PACKAGE" == "dms-git" ]]; then + echo " - Staging bundled Go toolchains for RPM (Source1/Source2)" + ensure_dms_git_go_tarballs "$WORK_DIR" + fi fi else echo " - Warning: Could not obtain source for OpenSUSE tarball" @@ -830,12 +875,18 @@ if [[ "$UPLOAD_DEBIAN" == true ]] && [[ -d "distro/debian/$PACKAGE/debian" ]]; t esac cd "$REPO_ROOT" rm -rf "$OBS_TARBALL_DIR" + + if [[ "$PACKAGE" == "dms-git" ]]; then + echo " - Staging bundled Go toolchains for RPM (Source1/Source2)" + ensure_dms_git_go_tarballs "$WORK_DIR" + fi + echo " - OpenSUSE source tarballs created" fi # Copy and update OpenSUSE spec file with the correct version cp "distro/opensuse/$PACKAGE.spec" "$WORK_DIR/" - if [[ "$PACKAGE" == *"-git" ]] && [[ -n "$CHANGELOG_VERSION" ]]; then + if [[ "$PACKAGE" == *"-git" ]]; then update_opensuse_git_spec "$WORK_DIR/$PACKAGE.spec" elif [[ "$PACKAGE" == "dms-greeter" ]] && [[ -n "$CHANGELOG_VERSION" ]]; then DMS_GREETER_BASE_VERSION=$(echo "$CHANGELOG_VERSION" | sed -E 's/^([0-9]+(\.[0-9]+)*).*/\1/') @@ -891,6 +942,11 @@ if [[ "$UPLOAD_DEBIAN" == true ]] && [[ -d "distro/debian/$PACKAGE/debian" ]]; t fi fi + if [[ "$PACKAGE" == "dms-git" ]]; then + echo " Bundling Go toolchains into Debian source tree (offline build)" + ensure_dms_git_go_tarballs "$SOURCE_DIR" + fi + rm -f "$WORK_DIR/$COMBINED_TARBALL" echo " Creating combined tarball: $COMBINED_TARBALL" @@ -1055,6 +1111,12 @@ if [[ -n "$OBS_FILES" ]]; then continue fi + # Keep pinned Go toolchain archives (bundled for dms-git offline builds) + if [[ "$old_file" =~ ^go[0-9].+\.linux-(amd64|arm64)\.tar\.gz$ ]]; then + echo " - Keeping Go toolchain tarball: $old_file" + continue + fi + # Keep current orig tarball for dms-greeter (Debian 3.0 quilt needs it) UPSTREAM_VER_CLEAN=$(echo "$CHANGELOG_VERSION" | sed 's/-[^-]*$//' 2>/dev/null) if [[ "$PACKAGE" == "dms-greeter" ]] && [[ "$old_file" == "${PACKAGE}_${UPSTREAM_VER_CLEAN}.orig.tar.gz" ]]; then @@ -1130,11 +1192,11 @@ ls -la 2>&1 | head -20 echo "==> Staging changes" echo "Files to upload:" if [[ "$UPLOAD_DEBIAN" == true ]] && [[ "$UPLOAD_OPENSUSE" == true ]]; then - ls -lh ./*.tar.gz ./*.tar.xz ./*.tar ./*.spec ./*.dsc _service 2>/dev/null | awk '{print " " $9 " (" $5 ")"}' + ls -lh ./*.tar.gz ./*.tar.xz ./*.tar ./*.spec ./*.dsc _service ./go*.linux-*.tar.gz 2>/dev/null | awk '{print " " $9 " (" $5 ")"}' elif [[ "$UPLOAD_DEBIAN" == true ]]; then - ls -lh ./*.tar.gz ./*.dsc _service 2>/dev/null | awk '{print " " $9 " (" $5 ")"}' + ls -lh ./*.tar.gz ./*.dsc _service ./go*.linux-*.tar.gz 2>/dev/null | awk '{print " " $9 " (" $5 ")"}' elif [[ "$UPLOAD_OPENSUSE" == true ]]; then - ls -lh ./*.tar.gz ./*.tar.xz ./*.tar ./*.spec _service 2>/dev/null | awk '{print " " $9 " (" $5 ")"}' + ls -lh ./*.tar.gz ./*.tar.xz ./*.tar ./*.spec _service ./go*.linux-*.tar.gz 2>/dev/null | awk '{print " " $9 " (" $5 ")"}' fi echo ""