lade 0.2.0

Load automatically and hierarchically env variables from secret stores (Infisical/Dopper/1Password).
name: Release

on:
  push:
    tags:
      - "v*"

jobs:
  check-bump:
    runs-on: ubuntu-latest
    if: github.ref_type == 'tag'

    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
        with:
          key: ${{ runner.os }}
      - name: Check version
        run: |
          VERSION=$(cargo run -- --version | cut -d' ' -f2)
          if [[ "${{ github.ref_name }}" != "v$VERSION" ]]; then
            echo "Tag does not match code version, stopping."
            exit -1
          fi
          echo "Releasing v$VERSION"
      - uses: ncipollo/release-action@v1
        with:
          tag: ${{ github.ref_name }}
          makeLatest: true
          generateReleaseNotes: true

  crates:
    needs:
      - check-bump
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
        with:
          key: ${{ runner.os }}
      - uses: katyo/publish-crates@v2
        with:
          registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
          ignore-unpublished-changes: true

  binaries:
    needs:
      - check-bump
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        include:
          - os: macos-latest
            target: x86_64-apple-darwin
            suffix: ""
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            suffix: ""
          - os: ubuntu-latest
            target: x86_64-unknown-linux-musl
            suffix: ""
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            suffix: ".exe"
    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}
      - uses: Swatinem/rust-cache@v2
        with:
          key: ${{ runner.os }}
      - name: Build
        uses: actions-rs/cargo@v1
        with:
          use-cross: true
          command: build
          args: "--locked --release --target ${{ matrix.target }}"
      - name: Compress
        run: |
          mv "target/${{ matrix.target }}/release/lade${{ matrix.suffix }}" .
          tar czvf "lade-${{ github.ref_name }}-${{ matrix.target }}.tar.gz" "lade${{ matrix.suffix }}"
      - name: Upload
        uses: svenstaro/upload-release-action@v2
        with:
          tag: ${{ github.ref }}
          file: "lade-${{ github.ref_name }}-${{ matrix.target }}.tar.gz"
          asset_name: "lade-${{ github.ref_name }}-${{ matrix.target }}.tar.gz"
          overwrite: false

  bump:
    needs:
      - crates
      - binaries
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
        with:
          key: ${{ runner.os }}
      - name: Bump version
        id: bump
        run: |
          cargo install cargo-edit
          cargo set-version --bump beta
          echo "version=$(cargo metadata --format-version 1 --no-deps | jq -r .packages[0].version)" >> $GITHUB_OUTPUT
      - uses: peter-evans/create-pull-request@v4
        with:
          branch: bump-${{ steps.bump.outputs.version }}
          delete-branch: true
          commit-message: "chore: prepare release ${{ steps.bump.outputs.version }}"
          title: "chore: prepare release ${{ steps.bump.outputs.version }}"
          body: "Automatic suggested bump"
          base: main