rotz 1.2.1

Fully cross platform dotfile manager written in rust.
name: CI

on:
  push:
    branches: [main]
    tags:
      - v*
    paths:
      - "**"
      - "!docs/**"
      - "!.github/**"
      - ".github/workflows/ci.yml"
  pull_request:
    branches: [main]
    paths:
      - "**"
      - "!docs/**"
      - "!.github/**"
      - ".github/workflows/ci.yml"
  workflow_dispatch:
    inputs:
      lint:
        description: Run lint job
        type: boolean
        default: true
      test:
        description: Run test job
        type: boolean
        default: true
      build:
        description: Run build job
        type: boolean
        default: false

concurrency:
  group: ${{ github.ref }}
  cancel-in-progress: true

env:
  CARGO_TERM_COLOR: always

jobs:
  lint:
    name: lint
    runs-on: ubuntu-latest
    if: github.event_name != 'workflow_dispatch' || (github.event_name == 'workflow_dispatch' && inputs.lint)
    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy, rustfmt

      - 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') }}

      - run: cargo fmt --check

      - run: cargo clippy --all-features -- -D warnings

      - run: cargo clippy --features all-formats -- -D warnings

  test:
    name: Test Suite
    runs-on: ${{ matrix.target.runner }}
    if: github.event_name != 'workflow_dispatch' || (github.event_name == 'workflow_dispatch' && inputs.test)
    needs: lint
    strategy:
      matrix:
        target:
          - triple: x86_64-pc-windows-msvc
            runner: windows-latest
          - triple: x86_64-apple-darwin
            runner: macos-latest
          - triple: x86_64-unknown-linux-gnu
            runner: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@stable
        with:
          target: ${{ matrix.target.triple }}

      - uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
            target/
          key: ${{ runner.os }}-${{ matrix.target.triple }}-cargo-${{ hashFiles('**/Cargo.lock') }}

      - run: cargo test --features all-formats --target ${{ matrix.target.triple }}

  build:
    name: build
    needs: test
    runs-on: ${{ matrix.target.runner }}
    if: (github.event_name == 'workflow_dispatch' && inputs.build) || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v'))
    strategy:
      matrix:
        target:
          # each musl target also needs to use vendored openssl-sys in Cargo.toml for the build to work
          - triple: x86_64-pc-windows-msvc
            filename: rotz.exe
            runner: windows-latest
            compile: native

          - triple: aarch64-pc-windows-msvc
            filename: rotz.exe
            runner: windows-latest
            compile: native
            args: --no-default-features --features all-formats

          - triple: i686-pc-windows-msvc
            filename: rotz.exe
            runner: windows-latest
            compile: native

          - triple: x86_64-unknown-linux-gnu
            filename: rotz
            runner: ubuntu-latest
            compile: cross

          - triple: aarch64-unknown-linux-gnu
            filename: rotz
            runner: ubuntu-latest
            compile: cross

          - triple: i686-unknown-linux-gnu
            filename: rotz
            runner: ubuntu-latest
            compile: cross

          - triple: x86_64-unknown-linux-musl
            filename: rotz
            runner: ubuntu-latest
            compile: cross

          - triple: aarch64-unknown-linux-musl
            filename: rotz
            runner: ubuntu-latest
            compile: cross

          - triple: i686-unknown-linux-musl
            filename: rotz
            runner: ubuntu-latest
            compile: cross

          - triple: x86_64-apple-darwin
            filename: rotz
            runner: macos-latest
            compile: native

          - triple: aarch64-apple-darwin
            filename: rotz
            runner: macos-latest
            compile: native

    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@stable
        with:
          target: ${{ matrix.target.triple }}
        if: matrix.target.compile == 'native'

      - uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
          key: ${{ runner.os }}

      - run: cargo install cross --git https://github.com/cross-rs/cross
        if: matrix.target.compile == 'cross'

      - run: cargo build --release --target ${{ matrix.target.triple }} --target-dir ${{ runner.temp }} ${{ matrix.target.args || '' }}
        if: matrix.target.compile == 'native'

      - run: cross build --release --target ${{ matrix.target.triple }} --target-dir ${{ runner.temp }} ${{ matrix.target.args || '' }}
        if: matrix.target.compile == 'cross'

      - uses: actions/upload-artifact@v4
        with:
          name: rotz-${{ matrix.target.triple }}
          path: ${{ runner.temp }}/${{ matrix.target.triple }}/release/${{ matrix.target.filename }}
          if-no-files-found: error

  release:
    name: Release
    runs-on: ubuntu-latest
    needs: build
    environment: crates
    if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')

    env:
      CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@stable

      - 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') }}

      - run: cargo publish --dry-run

      - uses: actions/download-artifact@v4
        with:
          path: artifacts

      - run: |
          cd artifacts;
          for i in */; do
            cd "$i";
            zip -r "../${i%/}.zip" ./;
            cd ..;
            rm -rf "$i";
          done

      - run: |
          cd artifacts;
          for i in *.zip; do
            sha256sum "$i" | cut -d " " -f 1 > "$i.sha256";
          done

      - name: Create github Release
        uses: docker://antonyurchenko/git-release:v6
        with:
          args: artifacts/*
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - run: git clean -xdf

      - run: cargo publish