name: "[Single] Update Tag"

on:
  workflow_dispatch:
    inputs:
      tag:
        description: "Release Tag"
        required: true
        type: string

  workflow_call:
    inputs:
      tag:
        description: "Release Tag"
        required: true
        type: string

jobs:
  update_tag:
    name: Update tag
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Set Env
        run: |
          echo "BUILDTIME=$(TZ=Asia/Shanghai date)" >> $GITHUB_ENV
          echo "CURRENT_GIT_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV
        shell: bash

      - name: Update Tag
        uses: greenhat616/update-tag@v1
        with:
          tag_name: ${{ inputs.tag }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Create release body
        run: |
          cat > release.txt << 'EOF'
          ## Clash Nyanpasu Nightly Build
          Release created at  ${{ env.BUILDTIME }}.
          Daily build of **Clash Nyanpasu** on *main* branch.
          You could download previous Nightly Builds from [here](https://t.me/ClashNyanpasu).
          ***[See the development log here](https://t.me/s/keikolog/)***
          EOF

      - name: Update Release
        uses: softprops/action-gh-release@v2
        with:
          name: Clash Nyanpasu Dev
          tag_name: ${{ inputs.tag }}
          body_path: release.txt
          prerelease: true
          generate_release_notes: true
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
