gw-bin 0.4.2

Watch git repositories, pull changes and run commands on the new files
Documentation
name: Release

on:
  push:
    tags:
      - "v*"

permissions:
  contents: write

env:
  isRcRelease: ${{ contains(github.ref, 'rc') }}
  isLiveRelease: ${{ ! contains(github.ref, 'rc') }}

jobs:
  release:
    name: Create GitHub release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout the tag
        uses: actions/checkout@v3
      - name: Add toolchain for Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
      - name: Restore cached dependencies
        uses: Swatinem/rust-cache@v2
      - name: Release for tags
        uses: taiki-e/create-gh-release-action@v1
        if: ${{ env.isLiveRelease == 'true' }}
        with:
          changelog: CHANGELOG.md
          token: ${{ secrets.GITHUB_TOKEN }}
      - name: Publish to Crates.io
        uses: katyo/publish-crates@v2
        if: ${{ env.isLiveRelease == 'true' }}
        with:
          registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
          ignore-unpublished-changes: true

  release_linux:
    name: Release for Linux
    runs-on: ubuntu-latest
    needs: release
    steps:
      - name: Checkout the tag
        uses: actions/checkout@v3
      - name: Add toolchain for Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
      - name: Restore cached dependencies
        uses: Swatinem/rust-cache@v2
      - name: Build for Linux
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: --release --target x86_64-unknown-linux-gnu
      - name: Convert binaries into compressed files
        run: |
          cd target/x86_64-unknown-linux-gnu/release && tar czf gw-bin_x86_64-unknown-linux-gnu.tar.gz gw && cd -
          cd target/x86_64-unknown-linux-gnu/release && zip gw-bin_x86_64-unknown-linux-gnu.zip gw && cd -
      - name: Upload zip to release
        uses: svenstaro/upload-release-action@v2
        if: ${{ env.isLiveRelease == 'true' }}
        with:
          file: target/x86_64-unknown-linux-gnu/release/gw-bin_x86_64-unknown-linux-gnu.zip
          asset_name: gw-bin_x86_64-unknown-linux-gnu.zip
      - name: Upload tar.gz to release
        uses: svenstaro/upload-release-action@v2
        if: ${{ env.isLiveRelease == 'true' }}
        with:
          file: target/x86_64-unknown-linux-gnu/release/gw-bin_x86_64-unknown-linux-gnu.tar.gz
          asset_name: gw-bin_x86_64-unknown-linux-gnu.tar.gz
      - name: Archive production artifacts
        uses: actions/upload-artifact@v4
        if: ${{ env.isRcRelease == 'true' }}
        with:
          name: gw-bin_x86_64-unknown-linux-gnu
          path: |
            target/x86_64-unknown-linux-gnu/release/gw
  
  release_musl:
    name: Release for Musl
    runs-on: ubuntu-latest
    needs: release
    steps:
      - name: Checkout the tag
        uses: actions/checkout@v3
      - name: Add toolchain for Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          target: x86_64-unknown-linux-musl
      - name: Restore cached dependencies
        uses: Swatinem/rust-cache@v2
      - name: Install MUSL dependencies
        run: sudo apt-get install musl-tools --no-install-recommends -y
      - name: Build for Musl
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: --release --target x86_64-unknown-linux-musl
      - name: Convert binaries into compressed files
        run: |
          cd target/x86_64-unknown-linux-musl/release && tar czf gw-bin_x86_64-unknown-linux-musl.tar.gz gw && cd -
          cd target/x86_64-unknown-linux-musl/release && zip gw-bin_x86_64-unknown-linux-musl.zip gw && cd -
      - name: Upload zip to release
        uses: svenstaro/upload-release-action@v2
        if: ${{ env.isLiveRelease == 'true' }}
        with:
          file: target/x86_64-unknown-linux-musl/release/gw-bin_x86_64-unknown-linux-musl.zip
          asset_name: gw-bin_x86_64-unknown-linux-musl.zip
      - name: Upload tar.gz to release
        uses: svenstaro/upload-release-action@v2
        if: ${{ env.isLiveRelease == 'true' }}
        with:
          file: target/x86_64-unknown-linux-musl/release/gw-bin_x86_64-unknown-linux-musl.tar.gz
          asset_name: gw-bin_x86_64-unknown-linux-musl.tar.gz
      - name: Archive production artifacts
        uses: actions/upload-artifact@v4
        if: ${{ env.isRcRelease == 'true' }}
        with:
          name: gw-bin_x86_64-unknown-linux-musl
          path: |
            target/x86_64-unknown-linux-musl/release/gw
  
  release_windows:
    name: Release for Windows
    runs-on: ubuntu-latest
    needs: release
    steps:
      - name: Checkout the tag
        uses: actions/checkout@v3
      - name: Add toolchain for Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
      - name: Restore cached dependencies
        uses: Swatinem/rust-cache@v2
      - name: Build for Windows
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: --release --target x86_64-pc-windows-gnu
          use-cross: true
      - name: Convert binaries into compressed files
        run: |
          cd target/x86_64-pc-windows-gnu/release && zip gw-bin_x86_64-pc-windows-gnu.zip gw.exe && cd -
      - name: Upload zip to release
        uses: svenstaro/upload-release-action@v2
        if: ${{ env.isLiveRelease == 'true' }}
        with:
          file: target/x86_64-pc-windows-gnu/release/gw-bin_x86_64-pc-windows-gnu.zip
          asset_name: gw-bin_x86_64-pc-windows-gnu.zip
      - name: Archive production artifacts
        uses: actions/upload-artifact@v4
        if: ${{ env.isRcRelease == 'true' }}
        with:
          name: gw-bin_x86_64-pc-windows-gnu
          path: |
            target/x86_64-pc-windows-gnu/release/gw.exe
  
  
  release_arm:
    name: Release for ARM
    runs-on: ubuntu-latest
    needs: release
    steps:
      - name: Checkout the tag
        uses: actions/checkout@v3
      - name: Add toolchain for Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          target: arm-unknown-linux-gnueabihf
      - name: Restore cached dependencies
        uses: Swatinem/rust-cache@v2
      - name: Add new apt sources that support armhf
        run: |
          sudo tee /etc/apt/sources.list.d/ubuntu.sources << EOF
          Types: deb
          URIs: http://archive.ubuntu.com/ubuntu/
          Suites: noble noble-updates noble-backports
          Components: main universe restricted multiverse
          Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
          Architectures: amd64

          Types: deb
          URIs: http://security.ubuntu.com/ubuntu/
          Suites: noble-security
          Components: main universe restricted multiverse
          Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
          Architectures: amd64

          Types: deb
          URIs: http://ports.ubuntu.com/
          Suites: noble noble-updates noble-backports
          Components: main universe restricted multiverse
          Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
          Architectures: armhf
          EOF
      - name: Enable ARM cross-build capabilities
        run: sudo dpkg --add-architecture armhf
      - name: Update apt repositories
        run: sudo apt-get update
      - name: Install cross-platform installation dependencies
        run: sudo apt-get install libc6-dev gcc-arm-linux-gnueabihf libc6-dev:armhf libssl-dev:armhf --no-install-recommends -y
      - name: Add setup for ARM cross-building
        run: |
          mkdir -p ~/.cargo
          cat > ~/.cargo/config.toml << EOF
          [target.arm-unknown-linux-gnueabihf]
          linker = "arm-linux-gnueabihf-gcc"
          rustflags = ["-L/usr/lib/arm-linux-gnueabihf", "-C", "target-feature=+crt-static"]
          EOF
      - name: Build for ARM
        run: |
          export OPENSSL_STATIC=1
          export OPENSSL_DIR=/usr/arm-linux-gnueabihf
          export OPENSSL_LIB_DIR=/usr/lib/arm-linux-gnueabihf
          export OPENSSL_INCLUDE_DIR=/usr/include/arm-linux-gnueabihf
          cargo build --release --target arm-unknown-linux-gnueabihf
      - name: Convert binaries into compressed files
        run: |
          cd target/arm-unknown-linux-gnueabihf/release && tar czf gw-bin_arm-unknown-linux-gnueabihf.tar.gz gw && cd -
          cd target/arm-unknown-linux-gnueabihf/release && zip gw-bin_arm-unknown-linux-gnueabihf.zip gw && cd -
      - name: Upload zip to release
        uses: svenstaro/upload-release-action@v2
        if: ${{ env.isLiveRelease == 'true' }}
        with:
          file: target/arm-unknown-linux-gnueabihf/release/gw-bin_arm-unknown-linux-gnueabihf.zip
          asset_name: gw-bin_arm-unknown-linux-gnueabihf.zip
      - name: Upload tar.gz to release
        uses: svenstaro/upload-release-action@v2
        if: ${{ env.isLiveRelease == 'true' }}
        with:
          file: target/arm-unknown-linux-gnueabihf/release/gw-bin_arm-unknown-linux-gnueabihf.tar.gz
          asset_name: gw-bin_arm-unknown-linux-gnueabihf.tar.gz
      - name: Archive production artifacts
        uses: actions/upload-artifact@v4
        with:
          name: gw-bin_arm-unknown-linux-gnueabihf
          path: |
            target/arm-unknown-linux-gnueabihf/release/gw
    
  release_mac:
    name: Release for MacOS
    needs: release
    runs-on: macos-latest
    steps:
      - name: Checkout the tag
        uses: actions/checkout@v3
      - name: Add toolchain for Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
      - name: Restore cached dependencies
        uses: Swatinem/rust-cache@v2
      - name: Build for MacOS
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: --release --target aarch64-apple-darwin
      - name: Convert binaries into compressed files
        run: |
          cd target/aarch64-apple-darwin/release && zip gw-bin_aarch64-apple-darwin.zip gw && cd -
      - name: Upload zip to live release
        uses: svenstaro/upload-release-action@v2
        if: ${{ env.isLiveRelease == 'true' }}
        with:
          file: target/aarch64-apple-darwin/release/gw-bin_aarch64-apple-darwin.zip
          asset_name: gw-bin_aarch64-apple-darwin.zip
      - name: Store artifacts for the release candidates
        uses: actions/upload-artifact@v4
        if: ${{ env.isRcRelease == 'true' }}
        with:
          name: gw-bin_aarch64-apple-darwin
          path: |
            target/aarch64-apple-darwin/release/gw

  docker:
    name: Docker build if we are on a tag
    needs: release_arm
    runs-on: ubuntu-latest
    steps:
      - name: Checkout the tag
        uses: actions/checkout@v3
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
      - name: Log in to Docker Hub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_PASSWORD }}
      - name: Download artifacts
        uses: actions/download-artifact@v4
        with:
          name: gw-bin_arm-unknown-linux-gnueabihf
          path: target/arm-unknown-linux-gnueabihf/release
      - name: Make artifact executable
        run: chmod +x target/arm-unknown-linux-gnueabihf/release/gw
      - name: Docker meta for Debian
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: |
            danielgrant/gw
          tags: |
            type=raw,value=latest
            type=semver,pattern={{version}}
            type=semver,pattern={{major}}.{{minor}}
      - name: Build and push Docker image for x86_64
        id: build_amd64
        uses: docker/build-push-action@v5
        with:
          context: .
          file: ./Dockerfile
          push: true
          tags: "danielgrant/gw:amd64"
          cache-from: type=registry,ref=danielgrant/gw:latest
          cache-to: type=inline
      - name: Build and push Docker image for ARMv7
        uses: docker/build-push-action@v5
        with:
          context: .
          file: ./Dockerfile.arm
          push: true
          tags: "danielgrant/gw:armv7"
          platforms: linux/arm/v7
          cache-from: type=registry,ref=danielgrant/gw:latest
          cache-to: type=inline
      - name: Build and push Docker image for ARM64
        uses: docker/build-push-action@v5
        with:
          context: .
          file: ./Dockerfile.arm
          push: true
          tags: "danielgrant/gw:arm64"
          platforms: linux/arm64
          cache-from: type=registry,ref=danielgrant/gw:latest
          cache-to: type=inline
      - name: Merge tags with docker manifest
        run: |
          TAGS=$(echo "${{ steps.meta.outputs.tags }}" | sed 's/^/--tag /' | xargs)
          docker buildx imagetools create $TAGS \
            danielgrant/gw:amd64 \
            danielgrant/gw:arm64 \
            danielgrant/gw:armv7
      - name: Update repo description
        uses: peter-evans/dockerhub-description@v4
        if: ${{ env.isLiveRelease == 'true' }}
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_PASSWORD }}
          repository: danielgrant/gw