duoload 0.1.2

Export vocabulary from Duocards
Documentation
name: Release

on:
  push:
    tags:
      - 'v*'

jobs:
  check-version:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Get version from Cargo.toml
        id: cargo-version
        run: |
          VERSION=$(grep '^version = ' Cargo.toml | cut -d '"' -f2)
          echo "cargo_version=$VERSION" >> "$GITHUB_OUTPUT"
          
      - name: Check version matches tag
        run: |
          TAG_VERSION=${GITHUB_REF#refs/tags/v}
          CARGO_VERSION=${{ steps.cargo-version.outputs.cargo_version }}
          if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
            echo "Tag version ($TAG_VERSION) does not match Cargo.toml version ($CARGO_VERSION)"
            exit 1
          fi

  build:
    needs: check-version
    strategy:
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            artifact_name: duoload-linux-amd64
        #   - os: ubuntu-latest
            # target: aarch64-unknown-linux-gnu
            # artifact_name: duoload-linux-arm64
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            artifact_name: duoload-windows-amd64.exe
          - os: macos-latest
            target: x86_64-apple-darwin
            artifact_name: duoload-macos-amd64
          - os: macos-latest
            target: aarch64-apple-darwin
            artifact_name: duoload-macos-arm64

    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4

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

    #   - name: Install OpenSSL for cross-compilation
    #     if: matrix.target == 'aarch64-unknown-linux-gnu'
    #     run: |
    #       sudo apt-get update
    #       sudo apt-get install -y gcc-aarch64-linux-gnu
    #       sudo apt-get install -y libssl-dev
    #       export OPENSSL_DIR=/usr
    #       export OPENSSL_INCLUDE_DIR=/usr/include
    #       export OPENSSL_LIB_DIR=/usr/lib/aarch64-linux-gnu
    #       echo "OPENSSL_DIR=/usr" >> "$GITHUB_ENV"
    #       echo "OPENSSL_INCLUDE_DIR=/usr/include" >> "$GITHUB_ENV"
    #       echo "OPENSSL_LIB_DIR=/usr/lib/aarch64-linux-gnu" >> "$GITHUB_ENV"

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

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.artifact_name }}
          path: target/${{ matrix.target }}/release/duoload${{ matrix.os == 'windows-latest' && '.exe' || '' }}

  docker:
    needs: [build, check-version]
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - uses: actions/checkout@v4
      
      - name: Get version
        id: cargo-version
        run: |
          VERSION=$(grep '^version = ' Cargo.toml | cut -d '"' -f2)
          echo "version=$VERSION" >> "$GITHUB_OUTPUT"

      - name: Download Linux artifacts
        uses: actions/download-artifact@v4
        with:
          path: artifacts
          pattern: duoload-linux-*

      - name: List artifacts contents
        run: |
          echo "Contents of artifacts directory:"
          ls -la artifacts/
          echo "Contents of artifacts/duoload-linux-*:"
          ls -la artifacts/duoload-linux-*

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Log in to GitHub Container Registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build and push Docker images
        uses: docker/build-push-action@v5
        with:
          context: .
          platforms: linux/amd64
          push: true
          tags: |
            ghcr.io/${{ github.repository_owner }}/duoload:${{ steps.cargo-version.outputs.version }}
            ghcr.io/${{ github.repository_owner }}/duoload:latest
          build-args: |
            VERSION=${{ steps.cargo-version.outputs.version }}
          cache-from: type=gha
          cache-to: type=gha,mode=max

  release:
    needs: [build, docker, check-version]
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4
      
      - name: Get version
        id: cargo-version
        run: |
          VERSION=$(grep '^version = ' Cargo.toml | cut -d '"' -f2)
          echo "version=$VERSION" >> "$GITHUB_OUTPUT"

      - name: Download all artifacts
        uses: actions/download-artifact@v4
        with:
          path: artifacts
          pattern: duoload-*

      - name: Create Release
        uses: softprops/action-gh-release@v2
        with:
          name: Release v${{ steps.cargo-version.outputs.version }}
          body: |
            Release v${{ steps.cargo-version.outputs.version }}
            
            ## Binaries
            * Linux (AMD64): `duoload-linux-amd64`
            * Windows (AMD64): `duoload-windows-amd64.exe`
            * macOS (AMD64): `duoload-macos-amd64`
            * macOS (ARM64): `duoload-macos-arm64`

            ## Docker Images
            Docker images are available on GitHub Container Registry:
            ```bash
            # Pull specific version
            docker pull ghcr.io/${{ github.repository_owner }}/duoload:${{ steps.cargo-version.outputs.version }}
            
            # Pull latest version
            docker pull ghcr.io/${{ github.repository_owner }}/duoload:latest
            ```
          files: |
            artifacts/duoload-*
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}