name: Build Arch Packages (Enhanced) on: push: branches: [ main, master ] pull_request: branches: [ main, master ] jobs: detect-changes: runs-on: ubuntu-latest outputs: packages: ${{ steps.changes.outputs.packages }} matrix: ${{ steps.changes.outputs.matrix }} total: ${{ steps.changes.outputs.total }} steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Detect Changed Packages id: changes run: | # Alle verfügbaren Pakete finden all_packages=$(find . -name "PKGBUILD" -type f | xargs dirname | sed 's|^\./||' | sort) # Bei Push: nur geänderte Pakete if [ "${{ github.event_name }}" = "push" ] && [ "${{ github.event.before }}" != "0000000000000000000000000000000000000000" ]; then changed_files=$(git diff --name-only ${{ github.event.before }}..${{ github.sha }}) changed_packages="" for pkg in $all_packages; do if echo "$changed_files" | grep -q "^$pkg/"; then changed_packages="$changed_packages $pkg" fi done packages_to_build=$(echo $changed_packages | tr ' ' '\n' | sort | uniq) else # Bei PR oder initial commit: alle Pakete packages_to_build="$all_packages" fi # JSON Arrays erstellen if [ -n "$packages_to_build" ]; then packages_json=$(echo "$packages_to_build" | jq -R -s -c 'split("\n") | map(select(length > 0))') matrix_json=$(echo "$packages_to_build" | jq -R -s -c 'split("\n") | map(select(length > 0)) | map({package: ., name: (. | split("/") | last)})') total=$(echo "$packages_to_build" | wc -l) else packages_json="[]" matrix_json="[]" total="0" fi echo "packages=$packages_json" >> $GITHUB_OUTPUT echo "matrix=$matrix_json" >> $GITHUB_OUTPUT echo "total=$total" >> $GITHUB_OUTPUT echo "📦 Found $total package(s) to build:" echo "$packages_to_build" build-packages: needs: detect-changes if: needs.detect-changes.outputs.packages != '[]' strategy: matrix: include: ${{ fromJson(needs.detect-changes.outputs.matrix) }} fail-fast: false runs-on: ubuntu-latest container: image: archlinux:latest steps: - name: Setup Build Environment run: | echo "🔧 Setting up build environment..." pacman -Syu --noconfirm pacman -S --noconfirm base-devel git nodejs npm namcap pacman-contrib sudo curl # Builder user useradd -m -G wheel builder echo 'builder ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers echo 'builder:builder' | chpasswd - name: Checkout Repository uses: actions/checkout@v4 - name: Package Information run: | echo "📦 Building package: ${{ matrix.package }}" cd "${{ matrix.package }}" # PKGBUILD info extrahieren source PKGBUILD echo "Package name: $pkgname" echo "Version: $pkgver-$pkgrel" echo "Description: $pkgdesc" chown -R builder:builder /workspace/cseyfferth/repo - name: Validate PKGBUILD run: | cd "${{ matrix.package }}" echo "🔍 Validating PKGBUILD..." sudo -u builder namcap PKGBUILD # Dependency check sudo -u builder makepkg --printsrcinfo > .SRCINFO cat .SRCINFO - name: Build Package run: | cd "${{ matrix.package }}" echo "🔨 Building package..." # Build mit verbose output sudo -u builder makepkg -s --noconfirm --needed -L # Zeige gebaute Pakete echo "✅ Successfully built packages:" ls -la *.pkg.tar.zst - name: Test Package run: | cd "${{ matrix.package }}" echo "🧪 Testing built packages..." for pkg in *.pkg.tar.zst; do if [ -f "$pkg" ]; then echo "Testing $pkg..." sudo -u builder namcap "$pkg" || echo "⚠️ namcap warnings for $pkg" # Package info sudo -u builder pacman -Qip "$pkg" fi done - name: Upload Artifacts uses: actions/upload-artifact@v4 with: name: ${{ matrix.name }}-${{ github.sha }} path: | ${{ matrix.package }}/*.pkg.tar.zst ${{ matrix.package }}/.SRCINFO retention-days: 30