name: Require CHANGELOG.md update

on:
  pull_request:
    branches:
      # filter target branch of pr
      - develop
      - master

jobs:
  FeatureOrHotfix:
    runs-on: ubuntu-latest
    env:
      GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
    steps:
      - name: Get Changed Files
        id: changed
        uses: foodee/pr-includes-file-change@master
        with:
          paths: ^CHANGELOG.md
      - name: set defaults
        run: |
          echo "::set-env name=FEATURE_OR_HOTFIX::false"
      - name: enable check if this is a feature pr
        if: startsWith(github.head_ref, 'feature')
        run: |
          echo "::set-env name=FEATURE_OR_HOTFIX::true"
      - name: enable check if this is a hotfix pr
        if: startsWith(github.head_ref, 'hotfix')
        run: |
          echo "::set-env name=FEATURE_OR_HOTFIX::true"
      - name: Changelog updates have been found
        if: steps.changed.outputs.matched != 'true' && env.FEATURE_OR_HOTFIX == 'true'
        run: |
          echo ${{ steps.changed.outputs.matched }}
          echo "Features and Hotfixes must contain a changelog entry."
          echo "Add meaningful information into CHANGELOG.md about this PR."
          echo "Use a branch name not matching feature/** or hotfix/** will not require a changelog update."
          exit 1
