string_pipeline 0.13.4

A flexible, template-driven string transformation pipeline for Rust.
Documentation
name: CD # Continuous Deployment
permissions:
  contents: write

on:
  push:
    tags:
      - "[v]?[0-9]+.[0-9]+.[0-9]+"
  workflow_dispatch:
    inputs:
      tag:
        description: "Tag to deploy"
        required: true
        default: "0.0.0"

jobs:
  create-release:
    name: Create a release
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - name: Checkout the repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Generate a changelog
        uses: orhun/git-cliff-action@v4
        with:
          config: cliff.toml
          args: --latest --strip header
        env:
          OUTPUT: BODY.md

      - name: Publish on GitHub
        uses: ncipollo/release-action@v1
        with:
          prerelease: false
          bodyFile: BODY.md

  publish-release:
    name: Publishing for ${{ matrix.os }}
    runs-on: ${{ matrix.os }}

    strategy:
      fail-fast: false
      matrix:
        include:
          - os: macos-latest
            os-name: macos
            target: x86_64-apple-darwin
            architecture: x86_64
            binary-postfix: ""
            use-cross: false
          - os: macos-latest
            os-name: macos
            target: aarch64-apple-darwin
            architecture: arm64
            binary-postfix: ""
            use-cross: false
          - os: ubuntu-latest
            os-name: linux
            target: x86_64-unknown-linux-gnu
            architecture: x86_64
            binary-postfix: ""
            use-cross: false
          - os: ubuntu-latest
            os-name: linux
            target: x86_64-unknown-linux-musl
            architecture: x86_64
            binary-postfix: ""
            use-cross: false
          - os: windows-latest
            os-name: windows
            target: x86_64-pc-windows-msvc
            architecture: x86_64
            binary-postfix: ".exe"
            use-cross: false
          - os: ubuntu-latest
            os-name: linux
            target: aarch64-unknown-linux-gnu
            architecture: arm64
            binary-postfix: ""
            use-cross: true
          - os: ubuntu-latest
            os-name: linux
            target: i686-unknown-linux-gnu
            architecture: i686
            binary-postfix: ""
            use-cross: true

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}

      - name: Install musl for musl target
        if: matrix.target == 'x86_64-unknown-linux-musl'
        shell: bash
        run: |
          sudo apt update
          sudo apt-get install -y musl musl-tools

      - uses: Swatinem/rust-cache@v2
      - name: Cargo build
        shell: bash
        run: |
          if [[ "${{ matrix.use-cross }}" == "true" ]]; then
            cargo install cross
            cross build --release --target ${{ matrix.target }}
          else
            cargo build --release --target ${{ matrix.target }}
          fi

      - name: install strip command
        shell: bash
        run: |

          if [[ ${{ matrix.target }} == aarch64-unknown-linux-gnu ]]; then

              sudo apt update
              sudo apt-get install -y binutils-aarch64-linux-gnu
          fi
      - name: Packaging final binary
        shell: bash
        run: |

          ####### reduce binary size by removing debug symbols #######

          BIN=target/${{ matrix.target }}/release/string-pipeline${{ matrix.binary-postfix }}
          echo "BIN=$BIN" >> "$GITHUB_ENV"
          if [[ ${{ matrix.target }} == aarch64-unknown-linux-gnu ]]; then

            GCC_PREFIX="aarch64-linux-gnu-"
          else
            GCC_PREFIX=""
          fi
          "$GCC_PREFIX"strip $BIN

          ########## create tar.gz ##########

          RELEASE_NAME=string-pipeline-${GITHUB_REF/refs\/tags\//}-${{ matrix.target }}
          echo "RELEASE_NAME=$RELEASE_NAME" >> "$GITHUB_ENV"

          # create the directory for the archive
          mkdir -p "$RELEASE_NAME"/doc
          cp $BIN "$RELEASE_NAME"/
          cp {README.md,LICENSE,CHANGELOG.md} "$RELEASE_NAME"/

          tar czvf "$RELEASE_NAME".tar.gz "$RELEASE_NAME"

          ########## create sha256 ##########

          if [[ ${{ runner.os }} == 'Windows' ]]; then

            certutil -hashfile $RELEASE_NAME.tar.gz sha256 | grep -E [A-Fa-f0-9]{64} > $RELEASE_NAME.sha256
          else
            shasum -a 256 $RELEASE_NAME.tar.gz > $RELEASE_NAME.sha256
          fi
      - name: Packaging with zip format
        if: runner.os == 'Windows'
        run: |
          Compress-Archive -Path "$env:BIN" -Destination "$($env:RELEASE_NAME).zip"
          (Get-FileHash "$($env:RELEASE_NAME).zip" -Algorithm SHA256).Hash.ToLower() > "$($env:RELEASE_NAME).zip.sha256"

      - name: Releasing assets
        uses: softprops/action-gh-release@v2
        with:
          files: |

            string-pipeline*.tar.gz
            string-pipeline*.zip
            string-pipeline*.sha256

        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  publish-release-deb:
    name: publish-release-deb
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-unknown-linux-musl
            os: linux
            arch: x86_64
          - target: x86_64-unknown-linux-gnu
            os: linux
            arch: x86_64

    env:
      # Emit backtraces on panics.
      RUST_BACKTRACE: 1
      # Since we're distributing the dpkg, we don't know whether the user will
      # have PCRE2 installed, so just do a static build.
      PCRE2_SYS_STATIC: 1

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Install packages (Ubuntu)
        shell: bash
        run: |
          if ! command -V sudo; then
           apt-get update
           apt-get install -y --no-install-recommends sudo
          fi
          sudo apt-get update
          sudo apt-get install -y --no-install-recommends \
           zsh xz-utils liblz4-tool musl-tools brotli zstd

      - name: Install Rust
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: nightly
          target: ${{ matrix.target }}

      # for some reason, the above action doesn't seem to set the target correctly
      - name: Add rustup target
        shell: bash
        run: |
          rustup target add ${{ matrix.target }}

      - name: Install cargo-deb and cross
        shell: bash
        run: |
          cargo install cargo-deb cross

      - name: Create deployment directory
        shell: bash
        run: |
          dir=deployment/deb
          mkdir -p "$dir"
          echo "DEPLOY_DIR=$dir" >> $GITHUB_ENV

      - name: Build release binary
        shell: bash
        run: |
          version="${{ github.ref_name }}"
          DEB_NAME="string-pipeline-$version-${{ matrix.target }}.deb"
          DEB_DIR="target/${{ matrix.target }}/debian"

          # Build the actual binary
          # if aarch64, we need to install the cross compiler since we're running x86_64
          if [[ ${{ matrix.target }} == aarch64-unknown-linux-gnu ]]; then
            sudo apt-get install -y --no-install-recommends gcc-aarch64-linux-gnu

            cargo deb --profile deb --target ${{ matrix.target }} -o "$DEB_DIR/$DEB_NAME" \
              --cargo-build cross
              -- --no-default-features --features zero-copy,simd,fancy
          else
            cargo deb --profile deb --target ${{ matrix.target }} -o "$DEB_DIR/$DEB_NAME"
          fi

          echo "DEB_DIR=$DEB_DIR" >> $GITHUB_ENV
          echo "DEB_NAME=$DEB_NAME" >> $GITHUB_ENV

      - name: Create sha256 sum of deb file
        shell: bash
        run: |
          cd "$DEB_DIR"
          sum="$DEB_NAME.sha256"
          shasum -a 256 "$DEB_NAME" > "$sum"
          echo "SUM=$sum" >> $GITHUB_ENV

      - name: Upload release archive
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        shell: bash
        run: |
          cd "$DEB_DIR"
          version="${{ github.ref_name }}"
          gh release upload "$version" "$DEB_NAME" "$SUM"