on:
  pull_request_target:
    types: [labeled, unlabeled, opened, synchronize, reopened, ready_for_review]
    paths:
      - "*/ql/src/**/*.ql"
      - "*/ql/src/**/*.qll"
      - "!**/experimental/**"

jobs:
  check-change-note:
    runs-on: ubuntu-latest
    steps:
      - name: Check if change note file is present
        uses: dorny/paths-filter@7c0f15b688b020e95e00f15c61299b022f08ca95 # v2.8.0
        id: paths_filter
        with:
          filters: |
            change_note:
              - '**/change-notes/*.md'
      - name: Get PR labels
        id: pr-labels
        uses: joerick/pr-labels-action@0a4cc4ee0ab557ec0b1ae1157fa6fa7f9f4c494b # v1.0.6
      - name: Fail if change note is missing
        uses: actions/github-script@v3
        if: |
          github.event.pull_request.draft == false &&
          steps.paths_filter.outputs.change_note == 'false' &&
          !contains(steps.pr-labels.outputs.labels, ' no-change-note-required ')
        with:
          github-token: ${{secrets.GITHUB_TOKEN}}
          script: |
            core.setFailed('No change note found.' +
            ' Either add one, or add the `no-change-note-required` label.')

on:
  pull_request_target:
    types: [labeled, unlabeled, opened, synchronize, reopened, ready_for_review]
    paths:
      - "*/ql/src/**/*.ql"
      - "*/ql/src/**/*.qll"
      - "!**/experimental/**"

jobs:
  check-change-note:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Fail if no change note found. To fix, either add one, or add the `no-change-note-required` label.
        if: |
          github.event.pull_request.draft == false &&
          !contains(github.event.pull_request.labels.*.name, 'no-change-note-required')
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          gh api 'repos/${{github.repository}}/pulls/${{github.event.number}}/files' --paginate |
          jq '.[].filename' --raw-output |
          grep '/change-notes/.*\.md$'

Remove dependence on external actions
Actions: Remove dependence on external actions
