wilayah 0.6.1

Location lookup for Indonesian villages by GPS coordinates or name
name: Release

on:
  push:
    tags:
      - "v*"
  workflow_dispatch:

jobs:
  release:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
    - uses: actions/checkout@v6
    - uses: actions-rust-lang/setup-rust-toolchain@v1
      with:
        components: clippy, rustfmt

    - name: Install system dependencies
      run: sudo apt-get update && sudo apt-get install -y poppler-utils

    - name: Restore BIG data cache
      id: big-cache
      uses: actions/cache@v5
      with:
        path: |
          data/cache/big_villages.json
          data/cache/big_villages_with_polygons.json
        key: v0-big-data-${{ hashFiles('src/builder/big_api.rs', 'Cargo.toml') }}

    - name: Build database from pipeline
      run: cargo run --example build_db --features build-db -- --include-polygons --save-parsed-villages full

    - name: Save BIG data cache
      if: steps.big-cache.outputs.cache-hit != 'true'
      uses: actions/cache/save@v5
      with:
        path: |
          data/cache/big_villages.json
          data/cache/big_villages_with_polygons.json
        key: v0-big-data-${{ hashFiles('src/builder/big_api.rs', 'Cargo.toml') }}

    - name: Run tests
      run: cargo test --features build-db

    - name: Check formatting
      run: cargo fmt --check --all

    - name: Run clippy (no-default-features)
      run: cargo clippy --no-default-features -- -D warnings
    - name: Run clippy (raw-sqlite)
      run: cargo clippy --features raw-sqlite -- -D warnings
    - name: Run clippy (build-db)
      run: cargo clippy --features build-db -- -D warnings

    - name: Publish to crates.io (dry-run)
      run: cargo publish --dry-run --allow-dirty

    - name: Publish to crates.io
      if: startsWith(github.ref, 'refs/tags/v')
      continue-on-error: true
      run: cargo publish --allow-dirty
      env:
        CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

    - name: Extract changelog for this version
      id: changelog
      run: |
        version="${{ github.ref_name }}"
        awk "/^## ${version#v}/,/^## [0-9]/" CHANGELOG.md | head -n -1 > release_notes.md || true
        if [ ! -s release_notes.md ]; then
          echo "No changelog section found for ${version#v}" > release_notes.md
        fi
        cat release_notes.md

    - name: Create GitHub Release and upload assets
      uses: softprops/action-gh-release@v3
      with:
        tag_name: ${{ github.ref_name }}
        name: ${{ github.ref_name }}
        body_path: release_notes.md
        files: |
          data/locations.db
          data/locations-poly.db
          data/cache/parsed_villages.json
          data/cache/parsed_districts.json
          data/cache/parsed_provinces.json
          data/cache/parsed_cities.json
          data/cache/parsed_island_summaries.json
          data/cache/parsed_islands.json
          data/cache/big_villages_with_polygons.json
        generate_release_notes: false