Update release.yml #15
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| push: | |
| tags: | |
| - '[0-9]*' | |
| permissions: | |
| contents: write | |
| packages: write | |
| jobs: | |
| create-release: | |
| runs-on: ubuntu-22.04 | |
| outputs: | |
| upload_url: ${{ steps.release.outputs.upload_url }} | |
| release_id: ${{ steps.release.outputs.id }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Create Release | |
| id: release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: ${{ github.ref_name }} | |
| name: Release ${{ github.ref_name }} | |
| draft: false | |
| prerelease: ${{ contains(github.ref_name, 'alpha') || contains(github.ref_name, 'beta') || contains(github.ref_name, 'rc') || contains(github.ref_name, 'unstable') }} | |
| generate_release_notes: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| build-release: | |
| needs: create-release | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| include: | |
| - os: ubuntu-22.04 | |
| target: x86_64-linux-gnu | |
| name: netmgr-linux-x86_64 | |
| cmake_args: "" | |
| - os: ubuntu-22.04 | |
| target: aarch64-linux-gnu | |
| name: netmgr-linux-aarch64 | |
| cmake_args: "-DCMAKE_TOOLCHAIN_FILE=cmake/aarch64-toolchain.cmake" | |
| - os: macos-latest | |
| target: x86_64-apple-darwin | |
| name: netmgr-macos-x86_64 | |
| cmake_args: "-DCMAKE_OSX_ARCHITECTURES=x86_64" | |
| - os: macos-latest | |
| target: aarch64-apple-darwin | |
| name: netmgr-macos-aarch64 | |
| cmake_args: "-DCMAKE_OSX_ARCHITECTURES=arm64" | |
| - os: windows-latest | |
| target: x86_64-pc-windows-msvc | |
| name: netmgr-windows-x86_64.exe | |
| cmake_args: "-A x64" | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install dependencies (Ubuntu) | |
| if: runner.os == 'Linux' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y build-essential cmake ninja-build | |
| sudo apt-get install -y libjsoncpp-dev | |
| # Install cross-compilation tools for ARM64 | |
| if [[ "${{ matrix.target }}" == "aarch64-linux-gnu" ]]; then | |
| sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu | |
| fi | |
| - name: Install dependencies (macOS) | |
| if: runner.os == 'macOS' | |
| run: | | |
| brew install cmake ninja jsoncpp | |
| - name: Install dependencies (Windows) | |
| if: runner.os == 'Windows' | |
| run: | | |
| choco install cmake ninja | |
| vcpkg install jsoncpp:x64-windows | |
| - name: Create ARM64 toolchain file | |
| if: matrix.target == 'aarch64-linux-gnu' | |
| run: | | |
| mkdir -p cmake | |
| cat > cmake/aarch64-toolchain.cmake << 'EOF' | |
| set(CMAKE_SYSTEM_NAME Linux) | |
| set(CMAKE_SYSTEM_PROCESSOR aarch64) | |
| set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) | |
| set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) | |
| set(CMAKE_FIND_ROOT_PATH /usr/aarch64-linux-gnu) | |
| set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) | |
| set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) | |
| set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) | |
| EOF | |
| - name: Configure CMake | |
| run: | | |
| cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release ${{ matrix.cmake_args }} | |
| - name: Build release binary | |
| run: cmake --build build --config Release | |
| - name: Strip binary (Unix) | |
| if: runner.os != 'Windows' | |
| run: | | |
| if [[ "${{ matrix.target }}" == "aarch64-linux-gnu" ]]; then | |
| aarch64-linux-gnu-strip build/netmgr | |
| else | |
| strip build/netmgr | |
| fi | |
| - name: Prepare binary (Unix) | |
| if: runner.os != 'Windows' | |
| run: | | |
| cp build/netmgr ${{ matrix.name }} | |
| chmod +x ${{ matrix.name }} | |
| - name: Prepare binary (Windows) | |
| if: runner.os == 'Windows' | |
| run: | | |
| cp build/Release/netmgr.exe ${{ matrix.name }} | |
| - name: Build Debian package (Linux x86_64 only) | |
| if: matrix.os == 'ubuntu-22.04' && matrix.target == 'x86_64-linux-gnu' | |
| run: | | |
| # Create package structure | |
| mkdir -p package/DEBIAN | |
| mkdir -p package/usr/bin | |
| mkdir -p package/usr/share/doc/netmgr | |
| mkdir -p package/usr/share/man/man1 | |
| # Copy files | |
| cp build/netmgr package/usr/bin/ | |
| cp README.md package/usr/share/doc/netmgr/ | |
| cp LICENSE package/usr/share/doc/netmgr/ | |
| # Clean version string for package | |
| VERSION=$(echo "${{ github.ref_name }}" | sed 's/^v//') | |
| # Create control file | |
| cat > package/DEBIAN/control << EOF | |
| Package: netmgr | |
| Version: ${VERSION} | |
| Section: net | |
| Priority: optional | |
| Architecture: amd64 | |
| Depends: libc6 (>= 2.17), libstdc++6 (>= 5.4.0), libjsoncpp25 (>= 1.7.4) | |
| Maintainer: Rimaki <rimaki@rimakiproject.online> | |
| Description: Cross-platform network management tool | |
| A comprehensive network management utility that provides | |
| unified interface management, routing, firewall configuration, | |
| and network diagnostics across different platforms. | |
| EOF | |
| # Copy postinst and postrm scripts if they exist | |
| if [ -f debian/postinst ]; then | |
| cp debian/postinst package/DEBIAN/ | |
| chmod 755 package/DEBIAN/postinst | |
| fi | |
| if [ -f debian/postrm ]; then | |
| cp debian/postrm package/DEBIAN/ | |
| chmod 755 package/DEBIAN/postrm | |
| fi | |
| # Build package | |
| dpkg-deb --build package netmgr_${VERSION}_amd64.deb | |
| - name: Build RPM package (Linux x86_64 only) | |
| if: matrix.os == 'ubuntu-22.04' && matrix.target == 'x86_64-linux-gnu' | |
| run: | | |
| # Install rpm tools | |
| sudo apt-get install -y rpm | |
| # Clean version string for RPM | |
| VERSION=$(echo "${{ github.ref_name }}" | sed 's/^v//') | |
| # Create RPM build structure | |
| mkdir -p rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS} | |
| # Create spec file | |
| cat > rpmbuild/SPECS/netmgr.spec << EOF | |
| Name: netmgr | |
| Version: ${VERSION} | |
| Release: 1 | |
| Summary: Cross-platform network management tool | |
| License: MIT | |
| URL: https://github.com/RimakiTaema/netmgr | |
| %description | |
| A comprehensive network management utility that provides | |
| unified interface management, routing, firewall configuration, | |
| and network diagnostics across different platforms. | |
| %prep | |
| %build | |
| %install | |
| mkdir -p %{buildroot}%{_bindir} | |
| cp %{_sourcedir}/netmgr %{buildroot}%{_bindir}/netmgr | |
| %files | |
| %{_bindir}/netmgr | |
| %changelog | |
| * $(date '+%a %b %d %Y') Rimaki <rimaki@rimakiproject.online> - ${VERSION}-1 | |
| - Release ${VERSION} | |
| EOF | |
| # Copy binary to SOURCES | |
| cp build/netmgr rpmbuild/SOURCES/ | |
| # Build RPM | |
| rpmbuild --define "_topdir $(pwd)/rpmbuild" -bb rpmbuild/SPECS/netmgr.spec | |
| # Copy RPM to current directory | |
| cp rpmbuild/RPMS/x86_64/netmgr-*.rpm ./ | |
| - name: Upload Release Assets | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: ${{ github.ref_name }} | |
| files: | | |
| ${{ matrix.name }} | |
| *.deb | |
| *.rpm | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| build-docker: | |
| needs: create-release | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract version | |
| id: version | |
| run: echo "version=$(echo ${{ github.ref_name }} | sed 's/^v//')" >> $GITHUB_OUTPUT | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| tags: | | |
| ghcr.io/rimakitaema/netmgr:latest | |
| ghcr.io/rimakitaema/netmgr:${{ steps.version.outputs.version }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| publish-packages: | |
| needs: [create-release, build-release] | |
| runs-on: ubuntu-22.04 | |
| if: startsWith(github.ref, 'refs/tags/') | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| - name: Setup GPG for package signing | |
| env: | |
| GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} | |
| if: env.GPG_PRIVATE_KEY != '' | |
| run: | | |
| echo "${{ secrets.GPG_PRIVATE_KEY }}" | gpg --import | |
| echo "GPG key imported successfully" | |
| - name: Create Homebrew formula | |
| run: | | |
| # Extract version | |
| VERSION=$(echo "${{ github.ref_name }}" | sed 's/^v//') | |
| # Calculate SHA256 for macOS binary (if it exists) | |
| if [ -f "netmgr-macos-x86_64" ]; then | |
| MACOS_SHA256=$(sha256sum netmgr-macos-x86_64 | cut -d' ' -f1) | |
| else | |
| MACOS_SHA256="PLACEHOLDER_SHA256" | |
| fi | |
| # Create Homebrew formula | |
| cat > netmgr.rb << EOF | |
| class Netmgr < Formula | |
| desc "Cross-platform network management tool" | |
| homepage "https://github.com/RimakiTaema/netmgr" | |
| url "https://github.com/RimakiTaema/netmgr/releases/download/${{ github.ref_name }}/netmgr-macos-x86_64" | |
| sha256 "$MACOS_SHA256" | |
| version "$VERSION" | |
| def install | |
| bin.install "netmgr-macos-x86_64" => "netmgr" | |
| end | |
| test do | |
| system "#{bin}/netmgr", "--version" | |
| end | |
| end | |
| EOF | |
| echo "Homebrew formula created: netmgr.rb" |