wthrr 1.2.0

Weather companion for the terminal
name: Release

on:
  workflow_call:

defaults:
  run:
    shell: bash # Convenience workaround for Windows.
env:
  CARGO_TERM_COLOR: always

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            target: linux-x86_64
          - os: windows-latest
            target: windows-x86_64
            # Apple targets are not properly signed. Users will have to mark the binaries as secure manually.
          - os: macos-11
            target: macos-x86_64
          - os: macos-latest
            target: macos-arm64
    runs-on: ${{ matrix.os }}
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4
      - uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
            target/
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
      - name: Install dependencies
        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
          cargo install cargo-deb
      - name: Build
        run: |
          cargo build --release --verbose
          if [[ $RUNNER_OS == "Linux" ]]; then
            cargo appimage
            cargo deb
          fi
      - name: Prepare artifacts
        run: |
          mkdir "${{ matrix.target }}"
          artifact=wthrr-${{ matrix.target }}
          binary=wthrr
          if [[ $RUNNER_OS == "Windows" ]]; then
            ext=.exe
          elif [[ $RUNNER_OS == "Linux" ]]; then
            mv ./target/appimage/wthrr.AppImage "./${{ matrix.target }}/$artifact.AppImage"
            mv ./target/debian/wthrr*.deb "./${{ matrix.target }}/$artifact.deb"
          fi
          mv "./target/release/$binary$ext" "./${{ matrix.target }}/$artifact$ext"
          ls ${{ matrix.target }}
      - name: Upload artifacts
        uses: actions/upload-artifact@v4
        with:
          name: wthrr-${{ matrix.target }}
          path: ${{ matrix.target }}/wthrr*
      - name: Prepare release
        if: >
          github.repository_owner == 'ttytm'
          && ((github.ref_name == 'main' && github.event_name == 'push') || github.ref_type == 'tag')
        run: |
          if [ "$GITHUB_REF_TYPE" == tag ]; then
            {
              echo "TAG=$GITHUB_REF_NAME";
              echo "TITLE=wthrr ${GITHUB_REF_NAME:1}"; # v1.0.0 -> wthrr 1.0.0
            } >> "$GITHUB_ENV"
          else
            {
              echo "IS_PRERELEASE=true";
              echo "TAG=nightly";
              echo "TITLE=nightly build $(date -u +'%Y-%m-%d %H:%M:%S UTC')";
              echo "BODY=Generated from commit $GITHUB_SHA.";
            } >> "$GITHUB_ENV"
          fi
      - name: Update nightly tag
        if: env.IS_PRERELEASE
        uses: richardsimko/update-tag@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: nightly
      - name: Release
        if: >
          github.repository_owner == 'ttytm'
          && ((github.ref_name == 'main' && github.event_name == 'push') || github.ref_type == 'tag')
        uses: softprops/action-gh-release@v2
        with:
          files: ${{ matrix.target }}/wthrr*
          tag_name: ${{ env.TAG }}
          body: ${{ env.BODY }}
          name: ${{ env.TITLE }}
          prerelease: ${{ env.IS_PRERELEASE }}
      - name: Publish on crates.io
        if: >
          matrix.os == 'ubuntu-latest' && github.repository_owner == 'ttytm'
          && ((github.ref_name == 'main' && github.event_name == 'push') || github.ref_type == 'tag')
        run: cargo publish --token ${{ secrets.CRATES_TOKEN }}