on:
  workflow_dispatch:

  schedule:
    - cron: '@daily'

env:
  RNA_WORKDIR: /srv/rna
  RNA_VERSION: v1.3.6 # renovate: datasource=gitea-releases depName=forgejo/release-notes-assistant registryUrl=https://code.forgejo.org

jobs:
  release-notes:
    if: vars.ROLE == 'forgejo-coding'
    runs-on: docker
    container:
      image: 'data.forgejo.org/oci/ci:1'
    steps:
      - uses: https://data.forgejo.org/actions/checkout@v4

      - uses: https://data.forgejo.org/actions/cache@v4
        with:
          key: rna-${{ env.RNA_VERSION }}
          path: ${{ env.RNA_WORKDIR }}

      - name: install release-notes-assistant
        run: |
          set -x
          wget -O /usr/local/bin/rna https://code.forgejo.org/forgejo/release-notes-assistant/releases/download/${{ env.RNA_VERSION}}/release-notes-assistant
          chmod +x /usr/local/bin/rna

      - name: update open milestones
        run: |
          set -x
          mkdir -p ${{ env.RNA_WORKDIR }}
          curl -sS $FORGEJO_SERVER_URL/api/v1/repos/$FORGEJO_REPOSITORY/milestones?state=open | jq -r '.[] | .title' | while read forgejo version ; do
            milestone="$forgejo $version"
            rna --workdir ${{ env.RNA_WORKDIR }} --config .release-notes-assistant.yaml --storage milestone --storage-location "$milestone" --forgejo-url $FORGEJO_SERVER_URL --repository $FORGEJO_REPOSITORY --token ${{ secrets.RELEASE_NOTES_ASSISTANT_TOKEN }} release $version
          done
