fcidr 0.10.2

Fragmented Classless Inter-Domain Routing (FCIDR)
Documentation
name: Rust

on:
  push:
    branches:
      - 'main'
    paths:
      - '**.rs'
      - 'Cargo.toml'
      - 'Cargo.lock'
      - '.github/workflows/rust.yml'
  pull_request:
    paths:
      - '**.rs'
      - 'Cargo.toml'
      - 'Cargo.lock'
      - '.github/workflows/rust.yml'
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

env:
  CARGO_TERM_COLOR: always

jobs:
  validate:
    strategy:
      matrix:
        platform: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.platform }}
    steps:
      - name: Checkout
        uses: actions/checkout@v6
      - name: Check
        run: cargo check --all-features --verbose
      - name: Format
        run: cargo fmt --check --verbose
      - name: Lint
        run: rustup component add clippy && cargo clippy --verbose
      - name: Test
        run: cargo test --all-features --verbose

  tag:
    if: github.event_name == 'push' || (github.base_ref == 'main' && github.event.pull_request.merged == true)
    runs-on: ubuntu-latest
    needs: [validate]
    outputs:
      version: ${{ steps.stamp.outputs.version }}
    steps:
      - name: Checkout
        uses: actions/checkout@v6
      - name: Check semver bump
        id: check-semver
        run: |
          if [[ "${{ github.event.head_commit.message }}" =~ ^Merge\ pull\ request\ #[0-9]+\ from\ [^/]+/patch/.+$ ]]
          then
            echo "semver=patch" >> $GITHUB_OUTPUT
          elif [[ "${{ github.event.head_commit.message }}" =~ ^Merge\ pull\ request\ #[0-9]+\ from\ [^/]+/major/.+$ ]]
          then
            echo "semver=major" >> $GITHUB_OUTPUT
          else
            echo "semver=minor" >> $GITHUB_OUTPUT
          fi
      - name: Bump major version and push tag
        id: bump-major
        if: ${{ steps.check-semver.outputs.semver == 'major' }}
        uses: anothrNick/github-tag-action@1.75.0
        env:
          DEFAULT_BUMP: major
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Bump minor version and push tag
        id: bump-minor
        if: ${{ steps.check-semver.outputs.semver == 'minor' }}
        uses: anothrNick/github-tag-action@1.75.0
        env:
          DEFAULT_BUMP: minor
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Bump patch version and push tag
        id: bump-patch
        if: ${{ steps.check-semver.outputs.semver == 'patch' }}
        uses: anothrNick/github-tag-action@1.75.0
        env:
          DEFAULT_BUMP: patch
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Stamp version
        id: stamp
        run: |
          if [[ "${{ steps.check-semver.outputs.semver }}" == patch ]]
          then
            VERSION=${{ steps.bump-patch.outputs.new_tag }}
          elif [[ "${{ steps.check-semver.outputs.semver }}" == major ]]
          then
            VERSION=${{ steps.bump-major.outputs.new_tag }}
          else
            VERSION=${{ steps.bump-minor.outputs.new_tag }}
          fi
          echo "version=${VERSION}" >> $GITHUB_OUTPUT
          sed -i "s/version = \"0.0.0\"/version = \"${VERSION}\"/" Cargo.toml
      - name: Upload Build Artifact
        uses: actions/upload-artifact@v6
        with:
          name: 'Cargo.toml'
          path: 'Cargo.toml'

  build:
    if: github.event_name == 'push' || (github.base_ref == 'main' && github.event.pull_request.merged == true)
    strategy:
      matrix:
        platform: [macos-latest, windows-latest]
    runs-on: ${{ matrix.platform }}
    needs: [tag]
    steps:
      - name: Checkout
        uses: actions/checkout@v6
      - name: Download Build Artifacts
        uses: actions/download-artifact@v7
        with:
          name: 'Cargo.toml'
      - name: Build
        shell: bash
        run: |
          RAW_BINARY_NAME=fcidr
          BINARY_NAME=${RAW_BINARY_NAME}
          if [[ ${{ startsWith(matrix.platform, 'windows') }} == true ]]
          then
            BINARY_NAME=${BINARY_NAME}.exe
          fi
          cargo build --features=std --release --verbose
          cp target/release/${BINARY_NAME} ./
          tar czf ${RAW_BINARY_NAME}-${{ runner.os }}-${{ runner.arch }}.tar.gz ${BINARY_NAME}
      - name: Upload Build Artifact
        uses: actions/upload-artifact@v6
        with:
          name: 'artifact-${{ runner.os }}-${{ runner.arch }}'
          path: '*.tar.gz'

  publish:
    if: github.event_name == 'push' || (github.base_ref == 'main' && github.event.pull_request.merged == true)
    runs-on: ubuntu-latest
    needs: [tag]
    steps:
      - name: Checkout
        uses: actions/checkout@v6
      - name: Download Build Artifacts
        uses: actions/download-artifact@v7
        with:
          name: 'Cargo.toml'
      - name: Publish to crates.io
        run: |
          cargo login ${{ secrets.CRATES_IO_API_TOKEN }}
          cargo publish --allow-dirty --verbose

  release:
    if: github.event_name == 'push' || (github.base_ref == 'main' && github.event.pull_request.merged == true)
    runs-on: ubuntu-latest
    needs: [tag, build]
    steps:
      - name: Download Build Artifacts
        uses: actions/download-artifact@v7
      - name: Release
        uses: softprops/action-gh-release@v2.5.0
        with:
          files: 'artifact*/*.tar.gz'
          tag_name: ${{ needs.tag.outputs.version }}