name: Generate Release notes

on:
  workflow_dispatch:
    inputs:
      milestoneNumber:
        description: "Milestone title"
        required: true
      generatorVersion:
        description: "Changelog Generator version"
        required: true

jobs:
  build:
    name: Generate release notes
    runs-on: ubuntu-latest
    steps:
      - name: Capture milestone number and generator version
        run: |
          echo MILESTONE_NUMBER=${{ github.event.inputs.milestoneNumber }} >> $GITHUB_ENV
          echo GENERATOR_VERSION=${{ github.event.inputs.generatorVersion }} >> $GITHUB_ENV

      - name: Download changelog generator
        run: wget https://github.com/spring-io/github-changelog-generator/releases/download/v$GENERATOR_VERSION/github-changelog-generator.jar

      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          java-version: '17'
          distribution: 'temurin'

      - name: Prepare configuration file
        run: |
          cat << EOF > application.yml
          changelog:
            repository: spring-exprimental/spring-ai
            sections:
              - title: ":star: New features"
                labels: [ "type: feature" ]
              - title: ":rocket: Enhancements"
                labels: [ "type: enhancement" ]
              - title: ":lady_beetle: Bug fixes"
                labels: [ "type: bug" ]
              - title: ":notebook_with_decorative_cover: Documentation"
                labels: [ "in: documentation" ]
              - title: ":hammer: Tasks"
                labels: [ "type: task" ]
          EOF

      - name: Generate release notes
        run: java -jar github-changelog-generator.jar $MILESTONE_NUMBER release-notes.md

      - name: Print release notes
        run: cat release-notes.md
