name: Create tag
on:
  push:
    branches:
      - release

jobs:
  #build:
    #uses: ./.gitea/workflows/common_build.yml
  createTagAndChangelog:
    runs-on: ubuntu-latest
    #needs: build
    steps:
      - name: Check out repository code
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Config git
        run: |
          git config --global user.email aminecmi+giteadrone@pm.me
          git config --global user.name giteadrone
      - name: Creating the tag and generate changelog
        run: |
          git fetch --tags -p
          PREV=$(git describe --tags --abbrev=0)
          ./build.sh --publish --from-ci
          VER=$(git describe --tags --abbrev=0)
          CHANGELOG=$(git log $PREV..HEAD --pretty="- %s")
          echo "**$VER**\n\n$CHANGELOG\n\n--------------------------------------------------------------------\n\n$(cat CHANGELOG.md)" > CHANGELOG.md
          git add CHANGELOG.md
          git commit -m "Changelog for $VER"
#      - name: Push changes
#        uses: appleboy/git-push-action@v1.0.0
#        with:
#          author_name: giteadrone
#          author_email: aminecmi+giteadrone@pm.me
#          remote: ${{ secrets.REMOTE_URL }}
#          remote_name: origin
#          followtags: true
#          ssh_key: ${{ secrets.PRIVATE_KEY }}
#          tags: true
#          branch: release
      - name: handle version update
        run: |
          curl --request GET --url https://amine-bouabdallaoui.fr/version.php --header 'Authorization: ${{ secrets.AUTH_CALL }}' --header 'Content-Type: text/plain' --data "$(cat version.txt)"