# This workflow asserts that new changelog entries get added within pull requests.
# See `/.changelogs/README.md` for more information.

name: Changelog

on:
  pull_request:
    types:
      # When new commits get pushed to the associated PR
      - synchronize

      # When a PR gets first opened
      - opened

      # When a PR gets edited, as in the title, body or the base branch gets changed
      - edited

jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # https://github.com/actions/checkout/releases/tag/v2.3.4

      - name: Use Node.js 15
        uses: actions/setup-node@56899e050abffc08c2b3b61f3ec6a79a9dc3223d # https://github.com/actions/setup-node/releases/tag/v1.4.4
        with:
          node-version: '15.x'

      - name: Install dependencies
        run: npm ci --no-audit

      - name: Assert that a new changelog was added, or that the check is skipped
        env:
          TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: node .github/scripts/check-changelog

      - name: Check that all changelogs are valid
        run: bin/changelog consume --date 2050-01-01 --dry-run
