feat: improve CI/CD package naming and build script functionality
- Replace hardcoded version with dynamic extraction from debian/changelog - Use portable sed/awk commands instead of grep -oP for better compatibility - Implement robust fallback system for version extraction - Add install/remove arguments to build-debian-trixie.sh - Fix timestamp fallback to use readable format (YYYYMMDDHHMMSS) - Truncate commit hashes to 16 characters for better readability - Ensure YAML syntax validity for CI/CD workflow
This commit is contained in:
parent
cc4d989b82
commit
bf2b5104f1
2 changed files with 223 additions and 7 deletions
|
|
@ -123,14 +123,57 @@ jobs:
|
||||||
echo "Building Debian package..."
|
echo "Building Debian package..."
|
||||||
|
|
||||||
# Get build information for versioning
|
# Get build information for versioning
|
||||||
# Forgejo/Gitea Actions uses GITEA_RUN_NUMBER, fallback to timestamp
|
# Gitea/Forgejo Actions uses GITEA_RUN_NUMBER, fallback to timestamp for now
|
||||||
BUILD_NUMBER="${GITEA_RUN_NUMBER:-$(date +%s)}"
|
BUILD_NUMBER="${GITEA_RUN_NUMBER:-$(date +%Y%m%d%H%M%S)}"
|
||||||
COMMIT_HASH=$(git rev-parse HEAD 2>/dev/null || echo "unknown")
|
COMMIT_HASH=$(git rev-parse HEAD 2>/dev/null || echo "unknown")
|
||||||
BUILD_VERSION="0.1.0+build${BUILD_NUMBER}.${COMMIT_HASH}"
|
|
||||||
|
# Truncate commit hash to first 16 characters for better uniqueness
|
||||||
|
SHORT_COMMIT=$(echo "$COMMIT_HASH" | cut -c1-16)
|
||||||
|
|
||||||
|
# Dynamically get the project version with portable regex alternatives
|
||||||
|
extract_version() {
|
||||||
|
local version=""
|
||||||
|
|
||||||
|
# Try debian/changelog first (most authoritative)
|
||||||
|
if [ -f "debian/changelog" ]; then
|
||||||
|
# Portable alternative to grep -oP: use sed with capture groups
|
||||||
|
version=$(sed -nE 's/.*\(([^)]+)\).*/\1/p' debian/changelog | head -n1)
|
||||||
|
[ -n "$version" ] && echo "$version" && return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Try debian/control
|
||||||
|
if [ -f "debian/control" ]; then
|
||||||
|
# Portable alternative: use awk for field extraction
|
||||||
|
version=$(awk '/^Version:/ {print $2; exit}' debian/control 2>/dev/null)
|
||||||
|
[ -n "$version" ] && echo "$version" && return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Try Cargo.toml
|
||||||
|
if [ -f "Cargo.toml" ]; then
|
||||||
|
# Portable alternative: use sed with simple pattern matching
|
||||||
|
version=$(sed -nE 's/^version[[:space:]]*=[[:space:]]*"([^"]+)"/\1/p' Cargo.toml 2>/dev/null)
|
||||||
|
[ -n "$version" ] && echo "$version" && return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Ultimate fallback
|
||||||
|
echo "0.1.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
PROJECT_VERSION=$(extract_version)
|
||||||
|
|
||||||
|
# Validate version format (portable regex)
|
||||||
|
if ! echo "$PROJECT_VERSION" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9]+)?$' >/dev/null; then
|
||||||
|
echo "Warning: Invalid version format '$PROJECT_VERSION', using fallback"
|
||||||
|
PROJECT_VERSION="0.1.0"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Construct the full build version string
|
||||||
|
BUILD_VERSION="${PROJECT_VERSION}+build${BUILD_NUMBER}.${SHORT_COMMIT}"
|
||||||
|
|
||||||
echo "Build Version: $BUILD_VERSION"
|
echo "Build Version: $BUILD_VERSION"
|
||||||
|
echo "Project Version: $PROJECT_VERSION"
|
||||||
echo "Build Number: $BUILD_NUMBER"
|
echo "Build Number: $BUILD_NUMBER"
|
||||||
echo "Commit Hash: $COMMIT_HASH"
|
echo "Commit Hash: $SHORT_COMMIT"
|
||||||
|
|
||||||
# Check if we have the necessary files
|
# Check if we have the necessary files
|
||||||
if [ -f "Cargo.toml" ] && [ -d "debian" ]; then
|
if [ -f "Cargo.toml" ] && [ -d "debian" ]; then
|
||||||
|
|
@ -470,8 +513,8 @@ jobs:
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get build info for registry
|
# Get build info for registry
|
||||||
# Forgejo/Gitea Actions uses GITEA_RUN_NUMBER, fallback to timestamp
|
# Gitea/Forgejo Actions uses GITEA_RUN_NUMBER, fallback to timestamp for now
|
||||||
BUILD_NUMBER="${GITEA_RUN_NUMBER:-$(date +%s)}"
|
BUILD_NUMBER="${GITEA_RUN_NUMBER:-$(date +%Y%m%d%H%M%S)}"
|
||||||
COMMIT_HASH=$(git rev-parse HEAD 2>/dev/null || echo "unknown")
|
COMMIT_HASH=$(git rev-parse HEAD 2>/dev/null || echo "unknown")
|
||||||
|
|
||||||
echo "Publishing packages for build $BUILD_NUMBER (commit $COMMIT_HASH)"
|
echo "Publishing packages for build $BUILD_NUMBER (commit $COMMIT_HASH)"
|
||||||
|
|
@ -797,4 +840,4 @@ jobs:
|
||||||
echo "- **Build Scripts**: Automated package building and testing" >> STATUS_REPORT.md
|
echo "- **Build Scripts**: Automated package building and testing" >> STATUS_REPORT.md
|
||||||
|
|
||||||
echo "Status report created: STATUS_REPORT.md"
|
echo "Status report created: STATUS_REPORT.md"
|
||||||
echo "✅ All CI jobs completed successfully!"
|
echo "✅ All CI jobs completed successfully!"
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,31 @@
|
||||||
|
|
||||||
# Build apt-ostree for Debian Trixie/Forky
|
# Build apt-ostree for Debian Trixie/Forky
|
||||||
# This script ensures compatibility with libapt-pkg7.0
|
# This script ensures compatibility with libapt-pkg7.0
|
||||||
|
# Usage: ./build-debian-trixie.sh [install|remove]
|
||||||
|
# - No arguments: Build only
|
||||||
|
# - "install" argument: Build, remove existing installation, then install new
|
||||||
|
# - "remove" argument: Remove existing apt-ostree installation from system
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
# Parse command line arguments
|
||||||
|
INSTALL_AFTER_BUILD=false
|
||||||
|
REMOVE_ONLY=false
|
||||||
|
if [[ "$1" == "install" ]]; then
|
||||||
|
INSTALL_AFTER_BUILD=true
|
||||||
|
print_status "Install mode enabled - will remove existing installation, build, then install new"
|
||||||
|
elif [[ "$1" == "remove" ]]; then
|
||||||
|
REMOVE_ONLY=true
|
||||||
|
print_status "Remove mode enabled - will only remove existing apt-ostree installation"
|
||||||
|
elif [[ "$1" != "" ]]; then
|
||||||
|
print_error "Invalid argument: $1"
|
||||||
|
print_error "Usage: $0 [install|remove]"
|
||||||
|
print_error " - No arguments: Build only"
|
||||||
|
print_error " - 'install': Build, remove existing installation, then install new"
|
||||||
|
print_error " - 'remove': Remove existing apt-ostree installation from system"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Colors for output
|
# Colors for output
|
||||||
GREEN='\033[0;32m'
|
GREEN='\033[0;32m'
|
||||||
BLUE='\033[0;34m'
|
BLUE='\033[0;34m'
|
||||||
|
|
@ -24,6 +46,10 @@ print_error() {
|
||||||
echo -e "${RED}[ERROR]${NC} $1"
|
echo -e "${RED}[ERROR]${NC} $1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print_warning() {
|
||||||
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
print_header() {
|
print_header() {
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "${BLUE}================================${NC}"
|
echo -e "${BLUE}================================${NC}"
|
||||||
|
|
@ -33,12 +59,69 @@ print_header() {
|
||||||
|
|
||||||
print_header "Building apt-ostree for Debian Trixie/Forky"
|
print_header "Building apt-ostree for Debian Trixie/Forky"
|
||||||
|
|
||||||
|
# Show usage information
|
||||||
|
if [[ "$REMOVE_ONLY" == "true" ]]; then
|
||||||
|
print_status "Mode: REMOVE ONLY (will not build or install)"
|
||||||
|
elif [[ "$INSTALL_AFTER_BUILD" == "true" ]]; then
|
||||||
|
print_status "Mode: BUILD + REMOVE + INSTALL (will replace system installation)"
|
||||||
|
else
|
||||||
|
print_status "Mode: BUILD ONLY (package will not be installed)"
|
||||||
|
fi
|
||||||
|
|
||||||
# Check if we're in the right directory
|
# Check if we're in the right directory
|
||||||
if [ ! -f "Cargo.toml" ]; then
|
if [ ! -f "Cargo.toml" ]; then
|
||||||
print_error "Cargo.toml not found. Please run this script from the project root."
|
print_error "Cargo.toml not found. Please run this script from the project root."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Remove mode: Only remove existing installation
|
||||||
|
if [[ "$REMOVE_ONLY" == "true" ]]; then
|
||||||
|
print_header "Removing existing apt-ostree installation"
|
||||||
|
|
||||||
|
# Check if apt-ostree is currently installed
|
||||||
|
if command -v apt-ostree >/dev/null 2>&1; then
|
||||||
|
print_status "Found existing apt-ostree installation, removing..."
|
||||||
|
|
||||||
|
# Remove existing binaries
|
||||||
|
if [ -f "/usr/local/bin/apt-ostree" ]; then
|
||||||
|
sudo rm -f /usr/local/bin/apt-ostree
|
||||||
|
print_status "Removed /usr/local/bin/apt-ostree"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "/usr/local/bin/apt-ostreed" ]; then
|
||||||
|
sudo rm -f /usr/local/bin/apt-ostreed
|
||||||
|
print_status "Removed /usr/local/bin/apt-ostreed"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove existing configuration
|
||||||
|
if [ -d "/etc/apt-ostreed" ]; then
|
||||||
|
sudo rm -rf /etc/apt-ostreed
|
||||||
|
print_status "Removed /etc/apt-ostreed configuration"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove existing systemd service
|
||||||
|
if [ -f "/etc/systemd/system/apt-ostreed.service" ]; then
|
||||||
|
sudo systemctl stop apt-ostreed.service 2>/dev/null || true
|
||||||
|
sudo systemctl disable apt-ostreed.service 2>/dev/null || true
|
||||||
|
sudo rm -f /etc/systemd/system/apt-ostreed.service
|
||||||
|
print_status "Removed apt-ostreed systemd service"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove symlinks
|
||||||
|
if [ -L "/etc/systemd/system/multi-user.target.wants/apt-ostreed.service" ]; then
|
||||||
|
sudo rm -f /etc/systemd/system/multi-user.target.wants/apt-ostreed.service
|
||||||
|
print_status "Removed systemd symlink"
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_success "Existing apt-ostree installation removed successfully!"
|
||||||
|
else
|
||||||
|
print_status "No existing apt-ostree installation found"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Exit after removal
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
# Check if debian directory exists
|
# Check if debian directory exists
|
||||||
if [ ! -d "debian" ]; then
|
if [ ! -d "debian" ]; then
|
||||||
print_error "debian/ directory not found. Please ensure Debian packaging files are present."
|
print_error "debian/ directory not found. Please ensure Debian packaging files are present."
|
||||||
|
|
@ -167,3 +250,93 @@ fi
|
||||||
print_success "Build and test completed successfully!"
|
print_success "Build and test completed successfully!"
|
||||||
print_status "Package ready for Debian Trixie/Forky:"
|
print_status "Package ready for Debian Trixie/Forky:"
|
||||||
ls -la ../apt-ostree_*.deb
|
ls -la ../apt-ostree_*.deb
|
||||||
|
|
||||||
|
# Install mode: Replace system installation
|
||||||
|
if [[ "$INSTALL_AFTER_BUILD" == "true" ]]; then
|
||||||
|
print_header "Installing new build to system"
|
||||||
|
|
||||||
|
# First remove existing installation
|
||||||
|
print_status "Removing existing apt-ostree installation..."
|
||||||
|
|
||||||
|
# Remove existing binaries
|
||||||
|
if [ -f "/usr/local/bin/apt-ostree" ]; then
|
||||||
|
sudo rm -f /usr/local/bin/apt-ostree
|
||||||
|
print_status "Removed /usr/local/bin/apt-ostree"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "/usr/local/bin/apt-ostreed" ]; then
|
||||||
|
sudo rm -f /usr/local/bin/apt-ostreed
|
||||||
|
print_status "Removed /usr/local/bin/apt-ostreed"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove existing configuration
|
||||||
|
if [ -d "/etc/apt-ostreed" ]; then
|
||||||
|
sudo rm -rf /etc/apt-ostreed
|
||||||
|
print_status "Removed /etc/apt-ostreed configuration"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove existing systemd service
|
||||||
|
if [ -f "/etc/systemd/system/apt-ostreed.service" ]; then
|
||||||
|
sudo systemctl stop apt-ostreed.service 2>/dev/null || true
|
||||||
|
sudo systemctl disable apt-ostreed.service 2>/dev/null || true
|
||||||
|
sudo rm -f /etc/systemd/system/apt-ostreed.service
|
||||||
|
print_status "Removed apt-ostreed systemd service"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove symlinks
|
||||||
|
if [ -L "/etc/systemd/system/multi-user.target.wants/apt-ostreed.service" ]; then
|
||||||
|
sudo rm -f /etc/systemd/system/multi-user.target.wants/apt-ostreed.service
|
||||||
|
print_status "Removed systemd symlink"
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_status "Existing installation removed, proceeding with new installation..."
|
||||||
|
|
||||||
|
# Install the new package
|
||||||
|
print_status "Installing new package..."
|
||||||
|
if sudo dpkg -i ../apt-ostree_*.deb; then
|
||||||
|
print_success "Package installed successfully!"
|
||||||
|
|
||||||
|
# Verify installation
|
||||||
|
print_status "Verifying installation..."
|
||||||
|
if command -v apt-ostree >/dev/null 2>&1; then
|
||||||
|
print_success "apt-ostree command available"
|
||||||
|
apt-ostree --version
|
||||||
|
else
|
||||||
|
print_error "apt-ostree command not found after installation"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if daemon is available
|
||||||
|
if command -v apt-ostreed >/dev/null 2>&1; then
|
||||||
|
print_success "apt-ostreed daemon available"
|
||||||
|
else
|
||||||
|
print_warning "apt-ostreed daemon not found (may be normal for some builds)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Reload systemd and enable service if daemon exists
|
||||||
|
if command -v apt-ostreed >/dev/null 2>&1; then
|
||||||
|
print_status "Setting up systemd service..."
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
|
||||||
|
# Check if service file was created by the package
|
||||||
|
if [ -f "/etc/systemd/system/apt-ostreed.service" ]; then
|
||||||
|
sudo systemctl enable apt-ostreed.service
|
||||||
|
print_success "apt-ostreed service enabled"
|
||||||
|
else
|
||||||
|
print_warning "No systemd service file found - manual setup may be required"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_success "System installation completed successfully!"
|
||||||
|
print_status "New apt-ostree is now active on the system"
|
||||||
|
|
||||||
|
else
|
||||||
|
print_error "Package installation failed!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
print_status "Install mode not enabled - package built but not installed"
|
||||||
|
print_status "To install, run: $0 install"
|
||||||
|
print_status "To remove existing installation only, run: $0 remove"
|
||||||
|
print_status "To test existing .deb file: $0 remove && sudo dpkg -i ../apt-ostree_*.deb"
|
||||||
|
fi
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue