
name: REL

on:
  push:
    tags: ["v[0-9]*"]

jobs:
  release:
    name: Release
    runs-on: ubuntu-latest
    steps:

      - name: "Checkout code"
        uses: actions/checkout@v3

      - name: "Build tarball"
        run: |
          make checkver
          make dist
          EXTENSION=$(grep ^EXTENSION Makefile | sed 's/.*= *//')
          EXT_VERSION=$(grep ^EXT_VERSION Makefile | sed 's/.*= *//')
          test "${{github.ref}}" = "refs/tags/v${EXT_VERSION}" || { echo "ERR: tag mismatch"; exit 1; }
          echo "PACKAGE=${EXTENSION}" >> $GITHUB_ENV
          echo "VERSION=${EXT_VERSION}" >> $GITHUB_ENV
          echo "TGZ=${EXTENSION}-${EXT_VERSION}.tar.gz" >> $GITHUB_ENV
          echo "DRAFT=false" >> $GITHUB_ENV
          echo "PRERELEASE=false" >> $GITHUB_ENV

      - name: "Create Github release"
        env:
          GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
        run: |
          title="${PACKAGE} v${VERSION}"
          ghf="--notes-file=docs/notes/v${VERSION}.md"
          if test "${DRAFT}" = "true"; then ghf="${ghf} --draft"; fi
          if test "${PRERELEASE}" = "true"; then ghf="${ghf} --prerelease"; fi
          gh release create "v${VERSION}" "${TGZ}" --title="${title}" ${ghf}

