timecalc 0.4.15

Calculate the total duration of a given set of intervals and durations
Documentation
---
name: Prepare release

on:
  workflow_dispatch:
    inputs:
      version:
        description: The tag to release
  push:
    tags:
      - 'v[0-9]+.[0-9]+.[0-9]+'

env:
  CARGO_TERM_COLOR: always
  RUSTFLAGS: -D warnings
  RUSTDOCFLAGS: -D warnings

jobs:
  set_version:
    name: Set version
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.set_version_step.outputs.version }}
    steps:
      - name: Set version
        id: set_version_step
        run: |
          version=""
          if [[ "${{ github.event_name }}" == "push" ]]; then
            version="${GITHUB_REF_NAME}"
          else
            version="${{ github.event.inputs.version }}"
          fi
          echo "version=${version#v}" >> $GITHUB_OUTPUT

  create_release_draft:
    name: Create release draft
    runs-on: ubuntu-latest
    permissions:
      contents: write
    needs: set_version
    steps:
      - name: Echo version
        run: echo "Creating release for ${{ needs.set_version.outputs.version }}"
      - name: Checkout
        uses: actions/checkout@v6
      - name: Create release draft
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ github.ref_name }}
          name: ${{ needs.set_version.outputs.version }}
          draft: true
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  build:
    strategy:
      matrix:
        name:
          - linux-x86-64-gnu
          - linux-x86-64-musl
          - linux-armv7-gnu
          - linux-arm64-gnu
          - mac-x86-64
          - windows-x86-64
        include:
          - name: linux-x86-64-gnu
            os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            cross: false

          - name: linux-x86-64-musl
            os: ubuntu-latest
            target: x86_64-unknown-linux-musl
            cross: true

          - name: linux-armv7-gnu
            os: ubuntu-latest
            target: armv7-unknown-linux-gnueabihf
            cross: true

          - name: linux-arm64-gnu
            os: ubuntu-latest
            target: aarch64-unknown-linux-gnu
            cross: true

          - name: mac-x86-64
            os: macos-latest
            target: x86_64-apple-darwin
            cross: false

          - name: windows-x86-64
            os: windows-latest
            target: x86_64-pc-windows-msvc
            cross: false

    name: Binaries for ${{ matrix.name }}
    needs:
      - set_version
      - create_release_draft
    runs-on: ${{ matrix.os }}
    permissions:
      contents: write
    steps:
      - name: Checkout
        uses: actions/checkout@v6
      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: stable
          targets: ${{ matrix.target }}
      - name: Install cross
        if: matrix.cross
        uses: taiki-e/install-action@v2
        with:
          tool: cross
      - name: Get build cache
        uses: Swatinem/rust-cache@v2
      - name: Build
        shell: bash
        run: |
          if [[ "${{ matrix.cross }}" == "true" ]]; then
            cross build --release --locked --target ${{ matrix.target }}
          else
            cargo build --release --locked --target ${{ matrix.target }}
          fi
      - name: Package
        shell: bash
        run: |
          bin="target/${{ matrix.target }}/release/timecalc"
          if [[ "${{ matrix.name }}" == windows-* ]]; then
            bin="${bin}.exe"
          fi
          outdir="timecalc-${{ needs.set_version.outputs.version }}-${{ matrix.target }}"
          mkdir "${outdir}"
          mv "${bin}" "${outdir}/"
          cp README.md LICENSE "${outdir}/"

          if [[ "${{ matrix.name }}" == windows-* ]]; then
            7z a "${outdir}.zip" "${outdir}"
          else
            tar cavf "${outdir}.tgz" "${outdir}"
          fi
      - name: Upload artifact to release draft
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ github.ref_name }}
          name: ${{ needs.set_version.outputs.version }}
          draft: true
          files: |
            timecalc-*.tgz
            timecalc-*.zip
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}