wthrr 0.4.0

Weather companion for the terminal
name: Release

on:
  push:
    tags:
      - v*

env:
  CARGO_TERM_COLOR: always

defaults:
  run:
    # necessary for windows
    shell: bash

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        include:
          - 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
          - 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
    runs-on: ${{ matrix.OS }}
    env:
      NAME: wthrr
      TARGET: ${{ matrix.TARGET }}
      OS: ${{ matrix.OS }}
    steps:
      - uses: actions/checkout@v3
      - name: Cargo cache
        uses: actions/cache@v3
        with:
          path: |
            ~/.cargo/registry
            ./target
          key: build-cargo-registry-${{matrix.TARGET}}
      - name: List
        run: find ./
      - 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: ${{ matrix.OS == 'ubuntu-latest' }}
        run: |
          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: |
          if [[ $OS =~ ^ubuntu.*$ ]]; then
            cargo appimage 
          fi
          cargo build --release --verbose --target $TARGET
      - name: List target
        run: find ./target
      - name: Prepare artifacts
        run: |
          mkdir -p ./artifacts
          if [[ $OS =~ ^windows.*$ ]]; then
            EXEC=$NAME.exe
          else
            EXEC=$NAME
          fi
          if [[ $GITHUB_REF_TYPE =~ ^tag$ ]]; then
            TAG=$GITHUB_REF_NAME
          else
            TAG=$GITHUB_SHA
          fi
          if [[ $OS =~ ^ubuntu.*$ ]]; then 
            mv ./wthrr-*-x86_64.AppImage ./artifacts/wthrr-$TAG-x86_64-linux.AppImage 
          fi
          # beautify release targets (remove '-unknown' / '-gnu' from filename)
          TRUNC_TARGET=$(echo $TARGET | sed -e 's/-unknown//' -e 's/-gnu//')
          DISPLAY_NAME=$NAME-$TAG-$TRUNC_TARGET
          mkdir $DISPLAY_NAME
          cp README.md LICENSE $DISPLAY_NAME/
          mv ./target/$TARGET/release/$EXEC ./$DISPLAY_NAME/$EXEC
          # compress
          tar -czf ./artifacts/$DISPLAY_NAME.tar.gz $DISPLAY_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