devo 1.0.5

Generate and run tmux workflows from a small YAML DSL
name: Release

on:
  workflow_dispatch:
    inputs:
      version_bump:
        description: "Version bump type"
        required: true
        type: choice
        options:
          - patch
          - minor
          - major

env:
  CARGO_TERM_COLOR: always

jobs:
  version-bump:
    name: Version Bump
    runs-on: ubuntu-latest
    timeout-minutes: 15
    permissions:
      contents: write
    outputs:
      new_version: ${{ steps.bump.outputs.new_version }}
    steps:
      - uses: actions/checkout@v6
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
      - uses: dtolnay/rust-toolchain@stable
      - id: bump
        run: |
          CURRENT_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[0].version')
          echo "Current version: $CURRENT_VERSION"

          IFS='.' read -r major minor patch <<< "$CURRENT_VERSION"

          case "${{ github.event.inputs.version_bump }}" in
            major)
              major=$((major + 1)); minor=0; patch=0 ;;
            minor)
              minor=$((minor + 1)); patch=0 ;;
            patch)
              patch=$((patch + 1)) ;;
          esac

          NEW_VERSION="${major}.${minor}.${patch}"
          echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
      - run: sed -i "s/^version = \".*\"/version = \"${{ steps.bump.outputs.new_version }}\"/" Cargo.toml
      - run: cargo check
      - run: |
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add Cargo.toml Cargo.lock
          git commit -m "bump version to ${{ steps.bump.outputs.new_version }}"
          git tag "v${{ steps.bump.outputs.new_version }}"
          git push origin HEAD:${{ github.ref_name }}
          git push origin "v${{ steps.bump.outputs.new_version }}"

  build-binaries:
    name: Build ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    timeout-minutes: 45
    needs: [version-bump]
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            use-cross: false
          - target: x86_64-unknown-linux-musl
            os: ubuntu-latest
            use-cross: true
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
            use-cross: true
          - target: x86_64-apple-darwin
            os: macos-14
            use-cross: false
          - target: aarch64-apple-darwin
            os: macos-14
            use-cross: false
    steps:
      - uses: actions/checkout@v6
        with:
          ref: v${{ needs.version-bump.outputs.new_version }}
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}
      - uses: actions/cache@v5
        with:
          path: |
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
            target/
          key: ${{ runner.os }}-${{ matrix.target }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-${{ matrix.target }}-cargo-build-
            ${{ runner.os }}-cargo-
      - if: matrix.use-cross
        run: cargo install cross --git https://github.com/cross-rs/cross
      - run: |
          if [ "${{ matrix.use-cross }}" = "true" ]; then
            cross build --release --target ${{ matrix.target }}
          else
            cargo build --release --target ${{ matrix.target }}
          fi
      - run: |
          cd target/${{ matrix.target }}/release
          tar czf ../../../devo-${{ matrix.target }}.tar.gz devo
      - uses: actions/upload-artifact@v7
        with:
          name: devo-${{ matrix.target }}
          path: devo-${{ matrix.target }}.tar.gz

  create-release:
    name: Create GitHub Release
    runs-on: ubuntu-latest
    timeout-minutes: 10
    needs: [version-bump, build-binaries]
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v6
        with:
          ref: v${{ needs.version-bump.outputs.new_version }}
      - uses: actions/download-artifact@v8
        with:
          path: artifacts
      - uses: softprops/action-gh-release@v3
        with:
          tag_name: v${{ needs.version-bump.outputs.new_version }}
          files: |
            artifacts/devo-x86_64-unknown-linux-gnu/devo-x86_64-unknown-linux-gnu.tar.gz
            artifacts/devo-x86_64-unknown-linux-musl/devo-x86_64-unknown-linux-musl.tar.gz
            artifacts/devo-aarch64-unknown-linux-gnu/devo-aarch64-unknown-linux-gnu.tar.gz
            artifacts/devo-x86_64-apple-darwin/devo-x86_64-apple-darwin.tar.gz
            artifacts/devo-aarch64-apple-darwin/devo-aarch64-apple-darwin.tar.gz
          generate_release_notes: true
          draft: false
          prerelease: false

  publish-crates:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    timeout-minutes: 15
    needs: [version-bump, create-release]
    permissions:
      id-token: write
    environment:
      name: crates.io
      url: https://crates.io/crates/devo
    steps:
      - uses: actions/checkout@v6
        with:
          ref: v${{ needs.version-bump.outputs.new_version }}
      - uses: dtolnay/rust-toolchain@stable
      - uses: actions/cache@v5
        with:
          path: |
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
            target/
          key: ${{ runner.os }}-cargo-publish-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-cargo-publish-
            ${{ runner.os }}-cargo-
      - uses: rust-lang/crates-io-auth-action@v1.0.4
        id: auth
      - run: cargo publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}