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:
robojerk 2025-08-19 11:38:07 -07:00
parent cc4d989b82
commit bf2b5104f1
2 changed files with 223 additions and 7 deletions

View file

@ -123,14 +123,57 @@ jobs:
echo "Building Debian package..."
# Get build information for versioning
# Forgejo/Gitea Actions uses GITEA_RUN_NUMBER, fallback to timestamp
BUILD_NUMBER="${GITEA_RUN_NUMBER:-$(date +%s)}"
# Gitea/Forgejo Actions uses GITEA_RUN_NUMBER, fallback to timestamp for now
BUILD_NUMBER="${GITEA_RUN_NUMBER:-$(date +%Y%m%d%H%M%S)}"
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 "Project Version: $PROJECT_VERSION"
echo "Build Number: $BUILD_NUMBER"
echo "Commit Hash: $COMMIT_HASH"
echo "Commit Hash: $SHORT_COMMIT"
# Check if we have the necessary files
if [ -f "Cargo.toml" ] && [ -d "debian" ]; then
@ -470,8 +513,8 @@ jobs:
fi
# Get build info for registry
# Forgejo/Gitea Actions uses GITEA_RUN_NUMBER, fallback to timestamp
BUILD_NUMBER="${GITEA_RUN_NUMBER:-$(date +%s)}"
# Gitea/Forgejo Actions uses GITEA_RUN_NUMBER, fallback to timestamp for now
BUILD_NUMBER="${GITEA_RUN_NUMBER:-$(date +%Y%m%d%H%M%S)}"
COMMIT_HASH=$(git rev-parse HEAD 2>/dev/null || echo "unknown")
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 "Status report created: STATUS_REPORT.md"
echo "✅ All CI jobs completed successfully!"
echo "✅ All CI jobs completed successfully!"