224 lines
No EOL
8.5 KiB
YAML
224 lines
No EOL
8.5 KiB
YAML
name: Build and Publish Debian Package
|
|
|
|
on:
|
|
push:
|
|
branches: [ main, develop ]
|
|
tags: [ 'v*' ]
|
|
pull_request:
|
|
branches: [ main ]
|
|
|
|
jobs:
|
|
build-deb:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
run: |
|
|
git clone https://git.raines.xyz/robojerk/deb-mock.git /tmp/deb-mock
|
|
cp -r /tmp/deb-mock/* .
|
|
cp -r /tmp/deb-mock/.* . 2>/dev/null || true
|
|
|
|
- name: Set up Python
|
|
run: |
|
|
sudo apt update
|
|
sudo apt install -y python3.12 python3.12-venv python3-pip
|
|
|
|
- name: Install build dependencies
|
|
run: |
|
|
# Configure APT to use your cache server
|
|
echo 'Acquire::http::Proxy "http://192.168.1.79:3142";' | sudo tee /etc/apt/apt.conf.d/99proxy
|
|
echo 'Acquire::https::Proxy "http://192.168.1.79:3142";' | sudo tee -a /etc/apt/apt.conf.d/99proxy
|
|
|
|
sudo apt update
|
|
sudo apt install -y build-essential devscripts debhelper dh-python python3-all python3-setuptools
|
|
sudo apt install -y sbuild schroot debootstrap
|
|
|
|
- name: Create deb-mock directories
|
|
run: |
|
|
sudo mkdir -p /var/lib/deb-mock/chroots /var/cache/deb-mock
|
|
sudo chown -R $USER:$USER /var/lib/deb-mock /var/cache/deb-mock
|
|
|
|
- name: Set up virtual environment
|
|
run: |
|
|
python3 -m venv venv
|
|
source venv/bin/activate
|
|
pip install --upgrade pip
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
source venv/bin/activate
|
|
pip install -r requirements.txt
|
|
pip install -r requirements-dev.txt
|
|
|
|
- name: Install deb-mock in development mode
|
|
run: |
|
|
source venv/bin/activate
|
|
pip install -e .
|
|
|
|
- name: Run tests
|
|
run: |
|
|
source venv/bin/activate
|
|
python -m pytest tests/ -v --cov=deb_mock --cov-report=xml
|
|
|
|
- name: Build Debian package
|
|
run: |
|
|
# Get version from setup.py instead of importing module
|
|
VERSION=$(python3 -c "import re; print(re.search(r'version=[\"\']([^\"\']+)[\"\']', open('setup.py').read()).group(1))")
|
|
echo "Building version: $VERSION"
|
|
|
|
# Update changelog with current version
|
|
dch --newversion "$VERSION-1" --distribution unstable "Build from CI/CD"
|
|
|
|
# Build the package
|
|
dpkg-buildpackage -us -uc -b
|
|
|
|
# List built packages (handle missing .dsc file)
|
|
echo "Built packages:"
|
|
ls -la ../*.deb ../*.changes 2>/dev/null || true
|
|
ls -la ../*.dsc 2>/dev/null || echo "No .dsc file (binary-only package)"
|
|
|
|
- name: Upload build artifacts
|
|
run: |
|
|
echo "Debian package artifacts:"
|
|
ls -la ../*.deb ../*.changes 2>/dev/null || true
|
|
ls -la ../*.dsc 2>/dev/null || echo "No .dsc file (binary-only package)"
|
|
echo "Package contents:"
|
|
dpkg -c ../deb-mock_*.deb || true
|
|
|
|
- name: Create release assets
|
|
run: |
|
|
mkdir -p release-assets
|
|
cp ../deb-mock_*.deb release-assets/ 2>/dev/null || echo "No .deb files found"
|
|
cp ../deb-mock_*.changes release-assets/ 2>/dev/null || echo "No .changes files found"
|
|
|
|
# Create a summary file
|
|
echo "Deb-Mock Package Build Summary" > release-assets/BUILD_SUMMARY.txt
|
|
echo "===============================" >> release-assets/BUILD_SUMMARY.txt
|
|
echo "Build Date: $(date)" >> release-assets/BUILD_SUMMARY.txt
|
|
echo "Package: deb-mock" >> release-assets/BUILD_SUMMARY.txt
|
|
echo "Version: $VERSION" >> release-assets/BUILD_SUMMARY.txt
|
|
echo "" >> release-assets/BUILD_SUMMARY.txt
|
|
echo "Built Packages:" >> release-assets/BUILD_SUMMARY.txt
|
|
ls -la release-assets/*.deb 2>/dev/null || echo "No packages found" >> release-assets/BUILD_SUMMARY.txt
|
|
echo "" >> release-assets/BUILD_SUMMARY.txt
|
|
echo "Changes Files:" >> release-assets/BUILD_SUMMARY.txt
|
|
ls -la release-assets/*.changes 2>/dev/null || echo "No changes files found" >> release-assets/BUILD_SUMMARY.txt
|
|
|
|
echo "Release assets created:"
|
|
ls -la release-assets/
|
|
|
|
- name: Upload to Forgejo Debian Package Registry
|
|
if: startsWith(github.ref, 'refs/tags/')
|
|
run: |
|
|
echo "=== Uploading to Forgejo Debian Package Registry ==="
|
|
|
|
# Check if ACCESS_TOKEN is available
|
|
if [ -z "${{ secrets.ACCESS_TOKEN }}" ]; then
|
|
echo "❌ ACCESS_TOKEN is not set - skipping upload"
|
|
echo "To enable uploads, add ACCESS_TOKEN secret to repository settings"
|
|
exit 0
|
|
fi
|
|
|
|
echo "✅ ACCESS_TOKEN is set"
|
|
|
|
# List packages for upload
|
|
echo "Built packages:"
|
|
ls -la ../*.deb 2>/dev/null || echo "No .deb files found"
|
|
|
|
for deb_file in ../deb-mock_*.deb; do
|
|
if [ -f "$deb_file" ]; then
|
|
echo "Uploading $deb_file to Forgejo Debian Package Registry..."
|
|
filename=$(basename "$deb_file")
|
|
echo "File: $filename"
|
|
|
|
# Upload using Forgejo's API
|
|
http_code=$(curl -s -o /dev/null -w "%{http_code}" \
|
|
--user "robojerk:${{ secrets.ACCESS_TOKEN }}" \
|
|
--upload-file "$deb_file" \
|
|
"https://git.raines.xyz/api/packages/robojerk/debian/pool/unstable/main/upload")
|
|
|
|
echo "HTTP Response Code: $http_code"
|
|
|
|
if [ "$http_code" = "201" ]; then
|
|
echo "✅ Debian Package Registry upload SUCCESS for $deb_file"
|
|
elif [ "$http_code" = "409" ]; then
|
|
echo "➡️ INFO: Package $deb_file already exists (HTTP 409 Conflict)"
|
|
else
|
|
echo "❌ Debian Package Registry upload FAILED for $deb_file (HTTP $http_code)"
|
|
# Show verbose output for debugging failures
|
|
curl -v -i --user "robojerk:${{ secrets.ACCESS_TOKEN }}" \
|
|
--upload-file "$deb_file" \
|
|
"https://git.raines.xyz/api/packages/robojerk/debian/pool/unstable/main/upload" 2>&1
|
|
exit 1
|
|
fi
|
|
fi
|
|
done
|
|
|
|
- name: Success Summary
|
|
if: startsWith(github.ref, 'refs/tags/')
|
|
run: |
|
|
echo "=== Upload Summary ==="
|
|
echo "✅ Deb-Mock package uploaded successfully to Forgejo Debian Package Registry"
|
|
echo "✅ Package automatically assigned to repository by Forgejo"
|
|
echo ""
|
|
echo "📦 Package should now be available at:"
|
|
echo " https://git.raines.xyz/robojerk/deb-mock/packages"
|
|
echo ""
|
|
echo "🎯 Next steps:"
|
|
echo " - Verify package appears in repository packages page"
|
|
echo " - Test package installation on Debian/Ubuntu systems"
|
|
echo " - Users can install with: sudo apt install deb-mock"
|
|
|
|
- name: Setup Debian repository
|
|
if: startsWith(github.ref, 'refs/tags/')
|
|
run: |
|
|
# Install reprepro for repository management
|
|
sudo apt install -y reprepro gnupg
|
|
|
|
# Create repository structure
|
|
mkdir -p debian-repo/conf
|
|
mkdir -p debian-repo/dists
|
|
mkdir -p debian-repo/pool
|
|
|
|
# Create repository configuration
|
|
cat > debian-repo/conf/distributions << EOF
|
|
Origin: Deb-Mock Repository
|
|
Label: Deb-Mock
|
|
Codename: unstable
|
|
Architectures: amd64 arm64 i386 all source
|
|
Components: main
|
|
Description: Deb-Mock Debian Package Repository
|
|
SignWith: default
|
|
EOF
|
|
|
|
# Create options file
|
|
cat > debian-repo/conf/options << EOF
|
|
verbose
|
|
basedir .
|
|
EOF
|
|
|
|
- name: Add package to repository
|
|
if: startsWith(github.ref, 'refs/tags/')
|
|
run: |
|
|
# Add the package to the repository
|
|
reprepro -b debian-repo includedeb unstable ../deb-mock_*.deb
|
|
|
|
# List repository contents
|
|
reprepro -b debian-repo list unstable
|
|
|
|
- name: Create repository archive
|
|
if: startsWith(github.ref, 'refs/tags/')
|
|
run: |
|
|
# Create a tarball of the repository
|
|
tar -czf deb-mock-repo.tar.gz debian-repo/
|
|
|
|
echo "Repository archive created:"
|
|
ls -la deb-mock-repo.tar.gz
|
|
|
|
- name: Upload repository artifacts
|
|
if: startsWith(github.ref, 'refs/tags/')
|
|
run: |
|
|
echo "Repository artifacts:"
|
|
ls -la deb-mock-repo.tar.gz
|
|
echo "Repository structure:"
|
|
find debian-repo/ -type f | head -20 |