name: Changelog check
on:
  pull_request:
    types: [assigned, opened, synchronize, reopened, labeled, unlabeled]
    branches:
      - main

env:
  node-version: 18.x

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          # Fetch all history
          fetch-depth: '0'

      - name: Install pipx
        run: pip install towncrier

      # node setup
      - name: Use Node.js ${{ env.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ env.node-version }}
          cache: 'yarn'

      # node install
      - name: Install dependencies
        run: yarn

      - name: Check for presence of a Change Log fragment (only pull requests)
        run: |
          # Fetch the pull request' base branch so towncrier will be able to
          # compare the current branch with the base branch.
          # Source: https://github.com/actions/checkout/#fetch-all-branches.
          git fetch --no-tags origin main
          towncrier check --compare-with origin/main
        env:
          BASE_BRANCH: ${{ github.base_ref }}
        if: github.event_name == 'pull_request'
