# Automatic release workflow for Codeberg
# Triggers on git tags matching v* pattern (e.g., v0.0.118)
#
# Local usage:
#   nu scripts/changelog.nu
#   nu scripts/build.nu
#
# Binary naming follows cargo-binstall conventions:
#   nu-lint-<target-triple>.tar.gz
#
# Build targets are defined in flake.nix releaseTargets (single source of truth)

when:
  - event: tag
    ref: refs/tags/v*

steps:
  - name: changelog
    image: nixos/nix:latest
    commands:
      - nix-shell -p git-cliff nushell git cacert --run "nu scripts/changelog.nu"

  - name: build
    image: nixos/nix:latest
    environment:
      CACHIX_AUTH_TOKEN:
        from_secret: cachix_auth_token
    commands:
      # Targets discovered automatically from flake.nix releaseTargets
      - nix-shell -p nushell git cacert cachix --run "nu scripts/build.nu"

  - name: release
    image: woodpeckerci/plugin-gitea-release
    settings:
      base_url: https://codeberg.org
      files:
        - dist/*
      api_key:
        from_secret: codeberg_token
      target: main
      note: RELEASE_NOTES.md
      title: ${CI_COMMIT_TAG}
      prerelease: true
    depends_on:
      - changelog
      - build
