name: Release
on:
push:
tags:
- 'v*'
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
build-binaries:
name: Build ${{ matrix.platform.target }}
runs-on: ${{ matrix.platform.os }}
strategy:
matrix:
platform:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
name: netflow_generator-linux-x86_64
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
name: netflow_generator-linux-aarch64
- os: macos-latest
target: x86_64-apple-darwin
name: netflow_generator-macos-x86_64
- os: macos-latest
target: aarch64-apple-darwin
name: netflow_generator-macos-aarch64
- os: windows-latest
target: x86_64-pc-windows-msvc
name: netflow_generator-windows-x86_64.exe
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.platform.target }}
- name: Install cross-compilation tools (Linux ARM)
if: matrix.platform.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-${{ matrix.platform.target }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.platform.target }}-cargo-registry-
- name: Cache cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-${{ matrix.platform.target }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.platform.target }}-cargo-git-
- name: Cache cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-${{ matrix.platform.target }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.platform.target }}-cargo-build-target-
- name: Build release binary
run: cargo build --release --target ${{ matrix.platform.target }}
env:
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
- name: Prepare binary (Unix)
if: matrix.platform.os != 'windows-latest'
run: |
cp target/${{ matrix.platform.target }}/release/netflow_generator ${{ matrix.platform.name }}
chmod +x ${{ matrix.platform.name }}
tar -czf ${{ matrix.platform.name }}.tar.gz ${{ matrix.platform.name }}
- name: Prepare binary (Windows)
if: matrix.platform.os == 'windows-latest'
shell: pwsh
run: |
Copy-Item "target/${{ matrix.platform.target }}/release/netflow_generator.exe" "${{ matrix.platform.name }}"
Compress-Archive -Path "${{ matrix.platform.name }}" -DestinationPath "${{ matrix.platform.name }}.zip"
- name: Upload Unix artifacts
if: matrix.platform.os != 'windows-latest'
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform.name }}
path: ${{ matrix.platform.name }}.tar.gz
- name: Upload Windows artifacts
if: matrix.platform.os == 'windows-latest'
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform.name }}
path: ${{ matrix.platform.name }}.zip
build-docker:
name: Build and Push Docker Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
create-release:
name: Create GitHub Release
needs: [build-binaries, build-docker]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Display structure of downloaded files
run: ls -R artifacts
- name: Create Release
uses: softprops/action-gh-release@v1
with:
draft: false
prerelease: false
generate_release_notes: true
files: |
artifacts/netflow_generator-linux-x86_64/*.tar.gz
artifacts/netflow_generator-linux-aarch64/*.tar.gz
artifacts/netflow_generator-macos-x86_64/*.tar.gz
artifacts/netflow_generator-macos-aarch64/*.tar.gz
artifacts/netflow_generator-windows-x86_64.exe/*.zip