|
| 1 | +name: Build External PCap Service |
| 2 | + |
| 3 | +on: |
| 4 | + # Trigger on version tags (e.g., v1.0.1, v1.2.0) |
| 5 | + push: |
| 6 | + tags: |
| 7 | + - "v*" |
| 8 | + |
| 9 | + # Manual trigger for testing or emergency releases |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + version: |
| 13 | + description: "Version to build (e.g., 1.0.1)" |
| 14 | + required: true |
| 15 | + type: string |
| 16 | + create_release: |
| 17 | + description: "Create GitHub release" |
| 18 | + required: true |
| 19 | + default: true |
| 20 | + type: boolean |
| 21 | + |
| 22 | +jobs: |
| 23 | + build-linux: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout repository |
| 28 | + uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + submodules: true |
| 31 | + |
| 32 | + - name: Install dependencies |
| 33 | + run: | |
| 34 | + sudo apt-get update -q |
| 35 | + sudo apt-get install -y -q \ |
| 36 | + libpcap-dev \ |
| 37 | + build-essential \ |
| 38 | + dpkg-dev \ |
| 39 | + rpm \ |
| 40 | + devscripts \ |
| 41 | + debhelper \ |
| 42 | + libsystemd-dev \ |
| 43 | + libcap-dev \ |
| 44 | + fakeroot \ |
| 45 | + binutils |
| 46 | +
|
| 47 | + - name: Extract version from tag or input |
| 48 | + id: version |
| 49 | + run: | |
| 50 | + if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == refs/tags/v* ]]; then |
| 51 | + # Extract version from tag (v1.0.1 -> 1.0.1) |
| 52 | + VERSION=${GITHUB_REF#refs/tags/v} |
| 53 | + echo "Extracted version from tag: $VERSION" |
| 54 | + elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then |
| 55 | + # Use manually provided version |
| 56 | + VERSION="${{ github.event.inputs.version }}" |
| 57 | + echo "Using manually provided version: $VERSION" |
| 58 | + else |
| 59 | + echo "Unable to determine version" |
| 60 | + exit 1 |
| 61 | + fi |
| 62 | +
|
| 63 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 64 | + echo "PCAP_SERVICE_VERSION=$VERSION" >> $GITHUB_ENV |
| 65 | +
|
| 66 | + - name: Verify version matches source code |
| 67 | + run: | |
| 68 | + SOURCE_VERSION=$(grep '#define PCAP_SERVICE_VERSION ' pcapservice.h | awk -F '"' '{print $2}') |
| 69 | +
|
| 70 | + echo "Source code version: $SOURCE_VERSION" |
| 71 | + echo "Build version: ${{ steps.version.outputs.version }}" |
| 72 | +
|
| 73 | + if [ "$SOURCE_VERSION" != "${{ steps.version.outputs.version }}" ]; then |
| 74 | + echo "⚠️ Version mismatch detected!" |
| 75 | + echo "Source code defines version: $SOURCE_VERSION" |
| 76 | + echo "Tag/input specifies version: ${{ steps.version.outputs.version }}" |
| 77 | + echo "" |
| 78 | + echo "Please update the PCAP_SERVICE_VERSION in pcapservice.h to match the tag version," |
| 79 | + echo "or use the correct tag that matches the source code version." |
| 80 | + exit 1 |
| 81 | + fi |
| 82 | +
|
| 83 | + echo "✓ Version verification passed" |
| 84 | +
|
| 85 | + - name: Build external PCap service |
| 86 | + run: | |
| 87 | + echo "Building External PCap Service v${{ steps.version.outputs.version }}..." |
| 88 | +
|
| 89 | + # Clean and build |
| 90 | + make clean |
| 91 | + make shared |
| 92 | + make dist-source |
| 93 | +
|
| 94 | + # Verify binary was created |
| 95 | + if [ ! -f "whatpulse-pcap-service" ]; then |
| 96 | + echo "Error: Binary not found after build" |
| 97 | + exit 1 |
| 98 | + fi |
| 99 | +
|
| 100 | + echo "✓ Build completed successfully" |
| 101 | +
|
| 102 | + - name: Build Debian package |
| 103 | + run: | |
| 104 | + chmod +x scripts/build-deb.sh |
| 105 | + ./scripts/build-deb.sh ${{ steps.version.outputs.version }} |
| 106 | +
|
| 107 | + echo "Debian package build completed" |
| 108 | +
|
| 109 | + - name: Build RPM package |
| 110 | + run: | |
| 111 | + chmod +x scripts/build-rpm.sh |
| 112 | + ./scripts/build-rpm.sh ${{ steps.version.outputs.version }} |
| 113 | +
|
| 114 | + echo "RPM package build completed" |
| 115 | +
|
| 116 | + - name: Build Arch package |
| 117 | + run: | |
| 118 | + chmod +x scripts/build-arch.sh |
| 119 | + ./scripts/build-arch.sh ${{ steps.version.outputs.version }} |
| 120 | +
|
| 121 | + echo "Arch package build completed" |
| 122 | +
|
| 123 | + - name: Create standalone binary |
| 124 | + run: | |
| 125 | + # Create versioned binary |
| 126 | + cp whatpulse-pcap-service whatpulse-pcap-service-${{ steps.version.outputs.version }}-linux-amd64 |
| 127 | + strip whatpulse-pcap-service-${{ steps.version.outputs.version }}-linux-amd64 |
| 128 | + chmod +x whatpulse-pcap-service-${{ steps.version.outputs.version }}-linux-amd64 |
| 129 | +
|
| 130 | + echo "✓ Standalone binary created" |
| 131 | +
|
| 132 | + - name: Collect artifacts |
| 133 | + run: | |
| 134 | + mkdir -p dist/packages |
| 135 | +
|
| 136 | + # Copy packages from script build directories |
| 137 | + find scripts -name "*.deb" -exec cp {} dist/packages/ \; 2>/dev/null || echo "No .deb files found" |
| 138 | + find scripts -name "*.rpm" -exec cp {} dist/packages/ \; 2>/dev/null || echo "No .rpm files found" |
| 139 | + find scripts -name "*.pkg.tar.*" -exec cp {} dist/packages/ \; 2>/dev/null || echo "No .pkg.tar.* files found" |
| 140 | +
|
| 141 | + # Copy source distribution and standalone binary |
| 142 | + cp -v dist/*.tar.gz dist/packages/ 2>/dev/null || echo "No .tar.gz files found" |
| 143 | + cp -v whatpulse-pcap-service-${{ steps.version.outputs.version }}-linux-amd64 dist/packages/ |
| 144 | +
|
| 145 | + echo "📦 Final artifacts:" |
| 146 | + ls -la ../dist/packages/ |
| 147 | +
|
| 148 | + - name: Generate checksums |
| 149 | + run: | |
| 150 | + cd dist/packages |
| 151 | + sha256sum * > SHA256SUMS |
| 152 | + echo "✓ Checksums generated" |
| 153 | +
|
| 154 | + - name: Upload build artifacts |
| 155 | + uses: actions/upload-artifact@v4 |
| 156 | + with: |
| 157 | + name: pcap-service-packages-${{ steps.version.outputs.version }} |
| 158 | + path: dist/packages/ |
| 159 | + retention-days: 30 |
| 160 | + |
| 161 | + - name: Create GitHub Release |
| 162 | + if: | |
| 163 | + (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) || |
| 164 | + (github.event_name == 'workflow_dispatch' && github.event.inputs.create_release == 'true') |
| 165 | + uses: softprops/action-gh-release@v1 |
| 166 | + with: |
| 167 | + tag_name: ${{ github.event_name == 'workflow_dispatch' && format('v{0}', steps.version.outputs.version) || github.ref_name }} |
| 168 | + name: "WhatPulse PCap Service v${{ steps.version.outputs.version }}" |
| 169 | + body: | |
| 170 | + # WhatPulse External PCap Service v${{ steps.version.outputs.version }} |
| 171 | +
|
| 172 | + This release contains the external PCap service that provides network packet capture capabilities for WhatPulse when running in containerized environments (AppImage, Flatpak) where direct PCap access is not available. |
| 173 | +
|
| 174 | + --- |
| 175 | +
|
| 176 | + **Built from commit:** ${{ github.sha }} |
| 177 | + **Build date:** $(date -u +"%Y-%m-%d %H:%M:%S UTC") |
| 178 | + files: | |
| 179 | + dist/packages/* |
| 180 | + draft: false |
| 181 | + prerelease: false |
| 182 | + generate_release_notes: true |
| 183 | + env: |
| 184 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 185 | + |
| 186 | + - name: Summary |
| 187 | + run: | |
| 188 | + echo "## 🎉 Build Summary" >> $GITHUB_STEP_SUMMARY |
| 189 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 190 | + echo "**Version:** ${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY |
| 191 | + echo "**Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY |
| 192 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 193 | + echo "### 📦 Generated Packages" >> $GITHUB_STEP_SUMMARY |
| 194 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 195 | +
|
| 196 | + cd dist/packages |
| 197 | + for file in *; do |
| 198 | + if [[ -f "$file" && "$file" != "SHA256SUMS" ]]; then |
| 199 | + size=$(du -h "$file" | cut -f1) |
| 200 | + echo "- **$file** ($size)" >> $GITHUB_STEP_SUMMARY |
| 201 | + fi |
| 202 | + done |
| 203 | +
|
| 204 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 205 | + echo "### ✅ Next Steps" >> $GITHUB_STEP_SUMMARY |
| 206 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 207 | +
|
| 208 | + if [[ "${{ github.event_name }}" == "push" ]]; then |
| 209 | + echo "- 🚀 GitHub release created automatically" >> $GITHUB_STEP_SUMMARY |
| 210 | + elif [[ "${{ github.event.inputs.create_release }}" == "true" ]]; then |
| 211 | + echo "- 🚀 GitHub release created manually" >> $GITHUB_STEP_SUMMARY |
| 212 | + else |
| 213 | + echo "- 📋 Artifacts uploaded to workflow (no release created)" >> $GITHUB_STEP_SUMMARY |
| 214 | + fi |
| 215 | +
|
| 216 | + echo "- 📥 Download packages from the release or workflow artifacts" >> $GITHUB_STEP_SUMMARY |
| 217 | + echo "- 🔧 Test installation on target systems" >> $GITHUB_STEP_SUMMARY |
| 218 | + echo "- 📖 Update documentation if needed" >> $GITHUB_STEP_SUMMARY |
0 commit comments