name: build-release
on:
  push:
    tags:
      - "v*.*.*"

jobs:
  release:
    name: Build Release Assets
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v5

      - name: Set up Go
        uses: actions/setup-go@v6
        with:
          go-version: 1.24.9

      - name: Build the executables
        run: ./mkrel.sh epuppy ${{ github.ref_name}}

      - name: List the executables
        run: ls -l ./releases

      - name: Upload the binaries
        uses: svenstaro/upload-release-action@v2
        with:
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          tag: ${{ github.ref_name }}
          file: ./releases/*
          file_glob: true

      - name: Build Changelog
        id: github_release
        uses: mikepenz/release-changelog-builder-action@v5
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          mode: "PR"
          configurationJson: |
            {
              "template": "#{{CHANGELOG}}\n\n**Full Changelog**: #{{RELEASE_DIFF}}",
              "pr_template": "- #{{TITLE}} (##{{NUMBER}}) by #{{AUTHOR}}\n#{{BODY}}",
              "empty_template": "- no changes",
              "categories": [
                {
                    "title": "## New Features",
                    "labels": ["add", "feature"]
                },
                {
                    "title": "## Bug Fixes",
                    "labels": ["fix", "bug", "revert"]
                },
                {
                    "title": "## Documentation Enhancements",
                    "labels": ["doc"]
                },
                {
                    "title": "## Refactoring Efforts",
                    "labels": ["refactor"]
                },
                {
                    "title": "## Miscellaneus Changes",
                    "labels": []
                }
              ],
              "ignore_labels": [
                 "duplicate", "good first issue", "help wanted", "invalid", "question", "wontfix"
              ],
              "label_extractor": [
                 {
                    "pattern": "(.) (.+)",
                    "target": "$1"
                 },
                 {
                    "pattern": "(.) (.+)",
                    "target": "$1",
                    "on_property": "title"
                 }
              ]
            }
    
      - name: Create Release
        uses: softprops/action-gh-release@v2
        with:
          body: ${{steps.github_release.outputs.changelog}}
