name: Create a GitHub release page

on:
  push:
    tags:
      - '*.*.*'
  workflow_dispatch:

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

permissions: {}

jobs:
  build_and_publish:
    name: Create a GitHub release page
    runs-on: ubuntu-latest
    permissions:
      contents: write  # Push a release.
    steps:
      - name: Checkout Repository
        uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10  # v6.0.3
        with:
          persist-credentials: false
      - name: Prepare variables
        id: prepare_variables
        run: |
          git fetch --tags --force
          latest_tag=$(git describe --tags --abbrev=0)
          echo "latest_tag=${latest_tag}" >> "$GITHUB_ENV"
          echo "date=$(date +'%Y-%m-%d')" >> "$GITHUB_ENV"
          EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
          echo "tag_body<<$EOF" >> "$GITHUB_ENV"
          git --no-pager tag -l "${latest_tag}" --format='%(contents:body)' >> "$GITHUB_ENV"
          echo "$EOF" >> "$GITHUB_ENV"
      - name: Create GitHub Release 🚀
        run: |
          gh release create "$latest_tag" \
            --title "Version $latest_tag, $date" \
            --notes "$tag_body"
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          latest_tag: ${{ env.latest_tag }}
          date: ${{ env.date }}
          tag_body: ${{ env.tag_body }}
