motorx 0.0.18

A reverse-proxy in pure rust.
Documentation
on:
  push:
    tags:
      - 'v*'

concurrency:
  group: build-bins
  cancel-in-progress: true

permissions:
  contents: write

jobs:
  create-body:
    runs-on: ubuntu-20.04
    outputs:
      body: ${{ steps.git-cliff.outputs.content }}
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: orhun/git-cliff-action@v2
        id: git-cliff
        with:
          args: --verbose --latest --strip header
      - name: Create initial release
        uses: softprops/action-gh-release@v1
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          body: ${{ steps.git-cliff.outputs.content }}
          tag_name: ${{ github.ref }}
          name: ${{ github.ref_name }}

  upload-bin:
    needs: create-body
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-20.04
            extension: ''
            cross: true
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-20.04
            extension: ''
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            extension: '.exe'
          - target: aarch64-apple-darwin
            os: macos-latest
            extension: ''
          - target: x86_64-apple-darwin
            os: macos-latest
            extension: ''
    name: ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v3
      - name: Install cross-compilation tools
        uses: taiki-e/setup-cross-toolchain-action@v1
        if: ${{ matrix.cross == true }}
        with:
          target: ${{ matrix.target }}
      - name: Add target
        if: ${{ !matrix.cross }}
        run: rustup target add ${{ matrix.target }}
      - uses: Swatinem/rust-cache@c5ed9ba6b7e1bb8aff90d43acd2f0af4990fa57c
      - name: Build Binary
        run: cargo build --target ${{ matrix.target }} --release --locked -p motorx
      - name: Move Binary To Root
        run: cp target/${{ matrix.target }}/release/motorx${{ matrix.extension }} motorx${{ matrix.extension }}
      - name: Archive Binary
        shell: bash
        run: |
          if [ "${{ matrix.os }}" = "windows-latest" ]; then
            7z a -tzip "motorx-${{ matrix.target }}.zip" \
              motorx${{ matrix.extension }} \
              README.md \
              LICENSE-APACHE \
              LICENSE-MIT
          else
            tar -czvf motorx-${{ matrix.target }}.tar.gz \
              motorx${{ matrix.extension }} \
              README.md \
              LICENSE-APACHE \
              LICENSE-MIT
          fi
      - name: Add Artifact To Release
        uses: svenstaro/upload-release-action@v2
        with:
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          body: ${{ needs.create-body.outputs.body }}
          file: motorx-${{ matrix.target }}*
          file_glob: true
          overwrite: true
          tag: ${{ github.ref }}
          release_name: ${{ github.ref_name }}

  build-push-images:
    name: Build and Push Images
    needs: create-body
    strategy:
      fail-fast: false
      matrix:
        base: [bullseye-slim, bullseye, bookworm, bookworm-slim]
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2
      - name: Login to Docker Hub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKER_HUB_USERNAME }}
          password: ${{ secrets.DOCKER_HUB_TOKEN }}
      - name: Version without v
        run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
      - name: Build and push
        uses: docker/build-push-action@v3
        if: ${{ matrix.base == 'bookworm-slim' }}
        with:
          context: .
          file: dockerfiles/${{ matrix.base }}.dockerfile
          build-args: |
            RUST_IMAGE=rust:1.84-slim
          push: true
          tags: |
            igamble/motorx:${{ env.VERSION }}-${{ matrix.base }}
            igamble/motorx:latest-${{ matrix.base }}
            igamble/motorx:latest
      # for images which are'nt gonna be the latest tag
      - name: Build and push
        uses: docker/build-push-action@v3
        if: ${{ matrix.base != 'bookworm-slim' }}
        with:
          context: .
          file: dockerfiles/${{ matrix.base }}.dockerfile
          build-args: |
            RUST_IMAGE=rust:1.84-slim
          push: true
          tags: |
            igamble/motorx:${{ env.VERSION }}-${{ matrix.base }}
            igamble/motorx:latest-${{ matrix.base }}