scriv icon indicating copy to clipboard operation
scriv copied to clipboard

Provide a "check" command

Open nedbat opened this issue 4 years ago • 1 comments

For use in CI, to check if a pull request has followed the right procedure: did it add a new fragment, and does the fragment have content.

Question:

  • Some pull requests don't need new fragments. A PR might have a comment or label indicating that no fragment is needed. Should this command know how to interpret that signal? Or is that something the CI integration can do, and then it decides whether to use this command or not?

nedbat avatar Dec 31 '20 11:12 nedbat

I've recently setup a GitHub Actions workflow which does this, including the label to exclude a PR.

example GitHub workflow
name: has_changelog
on:
  - pull_request

jobs:
  check_has_news_in_changelog_dir:
    if: ${{ ! contains(github.event.pull_request.labels.*.name, 'no-news-is-good-news') }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:  # do a deep fetch to allow merge-base and diff
          fetch-depth: 0
      - name: check PR adds a news file
        run: |
          news_files="$(git diff --name-only "$(git merge-base origin/main "$GITHUB_SHA")" "$GITHUB_SHA" -- changelog.d/*.md)"
          if [ -n "$news_files" ]; then
            echo "Saw new files. changelog.d:"
            echo "$news_files"
          else
            echo "No news files seen"
            exit 1
          fi

It would be great to replace the bash with something from scriv. I don't think it should try to replace the label check, but that an example GitHub Actions workflow like the above could go into the docs (with room for other CI systems, if anyone contributes example configs).

I would be happy to put in a PR to add something, or at least get it started! If this would be welcome, I have two questions:

  • Where should the diff be done? Should it test config.main_branches until we find one that exists, and error if none is found?
  • Any options which are needed? Maybe --git-diff-from and --git-diff-to in case someone has a special case for the diff?

sirosen avatar Oct 07 '21 20:10 sirosen