wthrr 0.8.2

Weather companion for the terminal
name: Release

on:
  push:
    tags: [v*]
  workflow_dispatch:

env:
  CARGO_TERM_COLOR: always

defaults:
  run:
    shell: bash # necessary for windows

jobs:
  lint:
    uses: tobealive/wthrr-the-weathercrab/.github/workflows/lint.yml@main

  build:
    needs: lint
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-apple-darwin # not properly signed, so there are security warnings
            os: macos-latest
          - target: x86_64-pc-windows-gnu
            os: windows-latest
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
          # - target: aarch64-unknown-linux-gnu
          #   os: ubuntu-latest
          # - target: armv7-unknown-linux-gnueabihf
          #   os: ubuntu-latest
    runs-on: ${{ matrix.os }}
    env:
      APP_NAME: wthrr
      TARGET: ${{ matrix.target }}
    steps:
      - uses: actions/checkout@v3
      - uses: actions/cache@v3
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
            target/
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
      - name: Install and configure dependencies
        # dependencies are only needed on ubuntu
        # as that's the only place where we build the AppImage and would make cross-compilation
        if: runner.os == 'Linux'
        run: |
          sudo apt-get install libfuse2
          sudo wget "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage" -O /usr/local/bin/appimagetool
          sudo chmod +x /usr/local/bin/appimagetool
          cargo install cargo-appimage
          # sudo apt-get install -qq crossbuild-essential-arm64 crossbuild-essential-armhf
          # some additional configuration for cross-compilation on linux
          # cat >>~/.cargo/config <<EOF
          # [target.aarch64-unknown-linux-gnu]
          # linker = "aarch64-linux-gnu-gcc"
          # [target.armv7-unknown-linux-gnueabihf]
          # linker = "arm-linux-gnueabihf-gcc"
          # EOF
      - name: Install rust target
        run: rustup target add $TARGET
      - name: Run build
        run: |
          cargo build --release --verbose --target $TARGET
          if [[ $RUNNER_OS == "Linux" ]]; then 
            cargo appimage 
          fi
      - name: Prepare artifacts
        run: |
          mkdir -p ./artifacts
          if [[ $RUNNER_OS == "Windows" ]]; then
            EXEC=$APP_NAME.exe
          else
            EXEC=$APP_NAME
          fi
          if [[ $GITHUB_REF_TYPE =~ ^tag$ ]]; then
            TAG=$GITHUB_REF_NAME
          else
            TAG=$GITHUB_SHA
          fi
          if [[ $RUNNER_OS == "Linux" ]]; then 
            mv ./wthrr-*-x86_64.AppImage ./artifacts/wthrr-$TAG-x86_64-linux.AppImage 
          fi
          # beautify release targets (remove '-unknown' / '-gnu' from filename)
          ARTIFACT_NAME=$APP_NAME-$TAG-$(echo $TARGET | sed -e 's/-unknown//' -e 's/-gnu//')
          mkdir $ARTIFACT_NAME
          cp README.md LICENSE $ARTIFACT_NAME/
          mv ./target/$TARGET/release/$EXEC ./$ARTIFACT_NAME/$EXEC
          # compress
          tar -czf ./artifacts/$ARTIFACT_NAME.tar.gz $ARTIFACT_NAME
      - name: Archive artifacts
        uses: actions/upload-artifact@v3
        with:
          name: result
          path: |
            ./artifacts

  # deploy to github release tag
  deploy:
    if: startsWith(github.ref, 'refs/tags/')
    needs: build
    runs-on: ubuntu-latest
    steps:
      - name: Download artifacts
        uses: actions/download-artifact@v3
        with:
          name: result
          path: ./artifacts
      - name: List
        run: find ./artifacts
      - name: Release
        uses: softprops/action-gh-release@v1
        with:
          files: ./artifacts/*.tar.gz, ./artifacts/*.AppImage