amdgpu_top 0.11.5

Tool to displays AMDGPU usage. The tool displays information gathered from performance counters (GRBM, GRBM2), sensors, fdinfo, gpu_metrics and AMDGPU driver.
name: release

on:
  push:
    tags:
      - "v[0-9]+.[0-9]+.[0-9]+"
      - "pre-v[0-9]+.[0-9]+.[0-9]+"

permissions:
  contents: write

jobs:
  create-release:
    strategy:
      matrix:
        os: [ubuntu-22.04]
    runs-on: ${{ matrix.os }}
    name: create-release
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable
      - name: Get the tag name
        if: env.VERSION == ''
        run: echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
      - name: Print Version
        run: echo "$VERSION"
      - name: Print Cargo Version
        run: cargo -V
      - name: Package Version
        run: echo "PKG_VER=$(cargo metadata --no-deps --format-version 1 | jq '.packages[0].version' | head -n 1)" >> $GITHUB_ENV
      - name: Print Package Version
        run: echo "$PKG_VER"
      - name: Check Version
        run: |
          if ! [ "$PKG_VER" == "${VERSION#v}" ]; then
            echo "version does not match tag"
            # exit 1
          fi
      - name: Create release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: gh release create $VERSION --draft --verify-tag --title $VERSION
    outputs:
      version: ${{ env.VERSION }}
      pkg_ver: ${{ env.PKG_VER }}

  build:
    name: build
    needs: ['create-release']
    env:
      VERSION: ${{needs.create-release.outputs.version}}
      PKG_VER: ${{needs.create-release.outputs.pkg_ver}}
    strategy:
      matrix:
        os: [ubuntu-22.04, ubuntu-22.04-arm]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable
      - name: Runner Arch
        run: |
          # https://stackoverflow.com/questions/52996949/how-can-i-find-the-current-rust-compilers-default-llvm-target-triple
          echo "RUSTC_HOST_ARCH=$(rustc -vV | sed -n 's|host: ||p')" >> $GITHUB_ENV
      - name: Print Runner Arch
        run: echo "$RUSTC_HOST_ARCH"
      - name: Check Version env
        run: |
          if [ "$PKG_VER" == "" ]; then
            exit 1
          fi
          if [ "$VERSION" == "" ]; then
            exit 1
          fi
      - name: Setup Alpine Linux
        if: startsWith(env.RUSTC_HOST_ARCH, 'x86_64')
        uses: jirutka/setup-alpine@v1.3.0
        with:
          branch: edge
          packages: >
            build-base
            libdrm-dev
            git
            mold
            github-cli
            rustup
      - name: Build binary with musl
        if: startsWith(env.RUSTC_HOST_ARCH, 'x86_64')
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        shell: alpine.sh {0}
        run: |
          rustup-init --target x86_64-unknown-linux-musl --default-toolchain stable --profile minimal -y
          RUSTFLAGS='-C target-feature=-crt-static' mold -run cargo build --release --no-default-features --features="libdrm_link,tui,json" --target x86_64-unknown-linux-musl

          if [ "${RUSTC_HOST_ARCH}" == "x86_64-unknown-linux-gnu" ]; then
            cp ./target/x86_64-unknown-linux-musl/release/amdgpu_top ./
            tar czf "amdgpu_top-${{ env.PKG_VER }}-x86_64-unknown-linux-musl.tar.gz" amdgpu_top
            gh release upload --clobber "$VERSION" "amdgpu_top-${{ env.PKG_VER }}-x86_64-unknown-linux-musl.tar.gz"
          # else
            # cp ./target/release/amdgpu_top ./
            # tar czf "amdgpu_top-${{ env.PKG_VER }}-aarch64-unknown-linux-musl.tar.gz" amdgpu_top
            # gh release upload --clobber "$VERSION" "amdgpu_top-${{ env.PKG_VER }}-aarch64-unknown-linux-musl.tar.gz"
          fi
      - name: Install
        run: |
          sudo apt update
          sudo apt install libdrm-dev mold desktop-file-utils appstream
      - name: Install cargo-deb
        run: mold -run cargo install cargo-deb
      - name: Install cargo-generate-rpm
        run: mold -run cargo install cargo-generate-rpm
      - name: Install xbuild
        run: mold -run cargo install xbuild
      - name: Build binary
        run: mold -run cargo build --release --no-default-features --features="package"
      - name: Upload binary
        shell: bash
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          if [ "${RUSTC_HOST_ARCH}" == "x86_64-unknown-linux-gnu" ]; then
            cp ./target/release/amdgpu_top ./
            tar czf "amdgpu_top-${{ env.PKG_VER }}-x86_64-unknown-linux-gnu.tar.gz" amdgpu_top
            gh release upload --clobber "$VERSION" "amdgpu_top-${{ env.PKG_VER }}-x86_64-unknown-linux-gnu.tar.gz"
          else
            cp ./target/release/amdgpu_top ./
            tar czf "amdgpu_top-${{ env.PKG_VER }}-aarch64-unknown-linux-gnu.tar.gz" amdgpu_top
            gh release upload --clobber "$VERSION" "amdgpu_top-${{ env.PKG_VER }}-aarch64-unknown-linux-gnu.tar.gz"
          fi

      - name: Build Deb Package
        shell: bash
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          mold -run cargo deb -- --no-default-features --features="package"

          if [ "${RUSTC_HOST_ARCH}" == "x86_64-unknown-linux-gnu" ]; then
            gh release upload --clobber "$VERSION" ./target/debian/amdgpu-top_${{ env.PKG_VER }}-1_amd64.deb
          else
            gh release upload --clobber "$VERSION" ./target/debian/amdgpu-top_${{ env.PKG_VER }}-1_arm64.deb
          fi
      - name: Build RPM Pakcage
        shell: bash
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          mold -run cargo generate-rpm

          if [ "${RUSTC_HOST_ARCH}" == "x86_64-unknown-linux-gnu" ]; then
            gh release upload --clobber "$VERSION" ./target/generate-rpm/amdgpu_top-${{ env.PKG_VER }}-1.x86_64.rpm
          else
            gh release upload --clobber "$VERSION" ./target/generate-rpm/amdgpu_top-${{ env.PKG_VER }}-1.aarch64.rpm
          fi
      - name: Build AppImage
        shell: bash
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          if [ "${RUSTC_HOST_ARCH}" == "x86_64-unknown-linux-gnu" ]; then
            mold -run x build --platform linux --format appimage --release --arch x64
            cp ./target/x/release/linux/x64/amdgpu_top.AppImage amdgpu_top-x86_64.AppImage
            gh release upload --clobber "$VERSION" amdgpu_top-x86_64.AppImage
          else
            mold -run x build --platform linux --format appimage --release --arch arm64
            cp ./target/x/release/linux/arm64/amdgpu_top.AppImage amdgpu_top-aarch64.AppImage
            gh release upload --clobber "$VERSION" amdgpu_top-aarch64.AppImage
          fi
      - name: Build Deb Package without GUI
        shell: bash
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          mold -run cargo deb -- --no-default-features --features="libdrm_link,tui,json"

          if [ "${RUSTC_HOST_ARCH}" == "x86_64-unknown-linux-gnu" ]; then
            mv ./target/debian/amdgpu-top{,_without_gui}_${{ env.PKG_VER }}-1_amd64.deb
            gh release upload --clobber "$VERSION" ./target/debian/amdgpu-top_without_gui_${{ env.PKG_VER }}-1_amd64.deb
          else
            mv ./target/debian/amdgpu-top{,_without_gui}_${{ env.PKG_VER }}-1_arm64.deb
            gh release upload --clobber "$VERSION" ./target/debian/amdgpu-top_without_gui_${{ env.PKG_VER }}-1_arm64.deb
          fi