name: Build and Release Rust Binary

on:
  push:
    tags:
      - 'v*' # Triggers the workflow only when you push a version tag like v1.0.0

jobs:
  build-and-release:
    runs-on: codeberg-medium
    steps:
      - name: Checkout source code
        uses: actions/checkout@v6
      - name: Install Rust Toolchain
        uses: https://codeberg.org/wackbyte/rust-toolchain@trunk
        with:
          toolchain: stable
          target: x86_64-unknown-linux-gnu
      - name: Build release binary
        run: cargo build --release
      - name: Prepare release asset
        run: |
          mkdir dist
          cp -R examples dist/examples
          cp target/release/ckgreeter dist/ckgreeter
      - name: Publish Forgejo Release
        uses: actions/forgejo-release@v1
        with:
          direction: upload
          url: https://codeberg.org/
          repo: CanadianBaconBoi/CKGreeter
          token: ${{ secrets.FORGEJO_TOKEN }}
          tag: ${{ forgejo.ref_name }}
          release-dir: dist
          release-notes: "Automated Release with Actions"
