# Woodpecker CI Release Pipeline
# Equivalent to .github/workflows/release.yml
# Triggered on git tags (v*)

when:
  event: tag
  tag: v*

steps:
  # === BUILD RELEASE ===

  build-release:
    image: rust:latest
    commands:
      - curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin
      - cargo build --release --locked
      - mkdir -p dist
      - cp target/release/typedialog dist/
      - cp target/release/typedialog-tui dist/
      - cp target/release/typedialog-web dist/
      - cp target/release/typedialog-ag dist/
      - cp target/release/typedialog-ag-server dist/
      - cp README.md dist/ 2>/dev/null || true
      - cp LICENSE dist/ 2>/dev/null || true
      - cd dist && tar czf ../typedialog-${CI_COMMIT_TAG}-x86_64-linux.tar.gz .
      - cd .. && sha256sum typedialog-${CI_COMMIT_TAG}-x86_64-linux.tar.gz > typedialog-${CI_COMMIT_TAG}-x86_64-linux.tar.gz.sha256

  # === GENERATE SBOM ===

  generate-sbom:
    image: rust:latest
    commands:
      - cargo install cargo-sbom --locked
      - cargo sbom --output-format spdx_json_2_3 > sbom-spdx.json
      - cargo sbom --output-format cyclone_dx_json_1_4 > sbom-cyclonedx.json
    depends_on:
      - build-release

  # === PUBLISH ARTIFACTS ===
  # Note: This requires Woodpecker server configured with Forgejo/Gitea integration
  # Artifacts will be available in the pipeline artifacts section

  publish-artifacts:
    image: alpine:latest
    commands:
      - echo "✓ Release artifacts generated successfully"
      - echo "📦 Binary: typedialog-${CI_COMMIT_TAG}-x86_64-linux.tar.gz"
      - echo "🔐 Checksum: typedialog-${CI_COMMIT_TAG}-x86_64-linux.tar.gz.sha256"
      - echo "📋 SBOM (SPDX): sbom-spdx.json"
      - echo "📋 SBOM (CycloneDX): sbom-cyclonedx.json"
      - ls -lh *.tar.gz *.sha256 *.json
    depends_on:
      - generate-sbom
