# https://docs.github.com/en/actions

on:
  push:
    tags:
      - "**"

name: Release

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: false

permissions:
  contents: read

jobs:
  release:
    name: Release

    runs-on: ubuntu-latest

    permissions:
      contents: write # required to create GitHub releases

    steps:
      - name: Checkout
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          persist-credentials: false

      - name: Install PHP with extensions
        uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # 2.37.2
        with:
          php-version: 8.3
          coverage: none
          extensions: none
          tools: none

      - name: Determine tag
        run: echo "RELEASE_TAG=${GITHUB_REF#refs/tags/}" >> "$GITHUB_ENV"

      - name: Parse ChangeLog
        run: build/scripts/extract-release-notes.php "${RELEASE_TAG}" > release-notes.md

      - name: Create release
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: gh release create "${RELEASE_TAG}" --title "phpunit/php-code-coverage ${RELEASE_TAG}" --notes-file release-notes.md
