command-vault 0.3.0

An advanced command history manager with tagging and search capabilities
Documentation
name: Release

on:
  push:
    tags:
      - 'v*'
  pull_request:
    types: [closed]
    branches: [main]

jobs:
  create-release:
    if: |
      (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) ||
      (github.event_name == 'pull_request' && github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'version-bump'))
    runs-on: ubuntu-latest
    permissions:
      contents: write
    outputs:
      upload_url: ${{ steps.create_release.outputs.upload_url }}
      version: ${{ steps.get_version.outputs.version }}
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Get version from Cargo.toml
        id: get_version
        run: |
          VERSION=$(grep '^version = ' Cargo.toml | sed 's/version = "\(.*\)"/\1/')
          echo "version=${VERSION}" >> $GITHUB_OUTPUT

      - name: Create Git tag
        if: github.event_name == 'pull_request'
        run: |
          git config --local user.email "github-actions[bot]@users.noreply.github.com"
          git config --local user.name "github-actions[bot]"
          git tag -a "v${{ steps.get_version.outputs.version }}" -m "Release v${{ steps.get_version.outputs.version }}"
          git push origin "v${{ steps.get_version.outputs.version }}"

      - name: Create Release
        id: create_release
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: v${{ steps.get_version.outputs.version }}
          release_name: Release v${{ steps.get_version.outputs.version }}
          draft: false
          prerelease: false

  build-release:
    needs: create-release
    runs-on: ${{ matrix.os }}
    permissions:
      contents: write
    strategy:
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            artifact_name: command-vault
            asset_name: command-vault-linux-amd64
          - os: macos-latest
            target: x86_64-apple-darwin
            artifact_name: command-vault
            asset_name: command-vault-macos-x86_64
          - os: macos-latest
            target: aarch64-apple-darwin
            artifact_name: command-vault
            asset_name: command-vault-macos-arm64
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            artifact_name: command-vault.exe
            asset_name: command-vault-windows-amd64.exe

    steps:
      - uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}

      - name: Build
        run: cargo build --release --target ${{ matrix.target }}

      - name: Prepare asset for upload (Windows)
        if: matrix.os == 'windows-latest'
        shell: pwsh
        run: |
          cd target/${{ matrix.target }}/release
          Compress-Archive -Path ${{ matrix.artifact_name }} -DestinationPath ../../../${{ matrix.asset_name }}.zip

      - name: Prepare asset for upload (Unix)
        if: matrix.os != 'windows-latest'
        shell: bash
        run: |
          cd target/${{ matrix.target }}/release
          tar czf ../../../${{ matrix.asset_name }}.tar.gz ${{ matrix.artifact_name }}

      - name: Upload Release Asset
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ needs.create-release.outputs.upload_url }}
          asset_path: ${{ matrix.os == 'windows-latest' && format('{0}.zip', matrix.asset_name) || format('{0}.tar.gz', matrix.asset_name) }}
          asset_name: ${{ matrix.os == 'windows-latest' && format('{0}.zip', matrix.asset_name) || format('{0}.tar.gz', matrix.asset_name) }}
          asset_content_type: application/octet-stream