name: release

on:
  push:
    tags:
      - v*

jobs:
  release-notes:
    runs-on: ubuntu-22.04

    if: github.repository_owner == 'visgl'

    env:
      ADMIN_TOKEN: ${{ secrets.ADMIN_TOKEN }}

    steps:
      - uses: actions/checkout@v2.1.1

      - name: Get git tags (https://github.com/actions/checkout/issues/206)
        run: git fetch --tags -f

      - name: Use Node.js
        uses: actions/setup-node@v1
        with:
          node-version: '16.x'

      - name: Publish release
        run: |
          body=$(node scripts/github-release.js) &&
          curl \
            -X POST \
            -H "Accept: application/vnd.github.v3+json" \
            https://api.github.com/repos/visgl/react-map-gl/releases \
            -d "${body}" \
            -H "Authorization: token ${ADMIN_TOKEN}"
