name: Licensed

on:
  push: {branches: main}
  pull_request: {branches: main}

jobs:
  test:
    runs-on: ubuntu-latest
    name: Check licenses
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0 # licensed sometimes needs more than latest commit on a branch
      - run: npm ci
      - id: licensed
        uses: jonabc/licensed-ci@v1
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
      - uses: actions/github-script@0.2.0
        if: always() && steps.licensed.outputs.pr_number
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            github.issues.createComment({
              ...context.repo,
              issue_number: ${{ steps.licensed.outputs.pr_number }}
              body: 'My custom PR message'
            })
      - run: licensed status