This skips the `make compile-requirements` check when there have been no changes under `requirements/**`, but it does so in a way that still registers the action as having passed, not skipped. By doing so, we can make it a required check while also avoiding the 5-6 minutes of wasted worker time. This commit also removes the activation on push-to-master, since we really just need to check PRs. I don't expect there to be silent merge conflicts with this check, so if it passes on a branch it should also pass on a successful simple rebase or merge. It would be nice if there was a way to declare success and exit early, but GH hasn't implemented it: https://github.com/actions/runner/issues/662 Alternatively, it would be great if skipped checks could count as fulfilling the branch protection rules, but no luck there. The only alternative that uses GH's built-in paths/paths-ignore feature would be to add a second workflow with the same job name and the opposite path triggers and that always passes. It's not clear that this would be any less fragile or confusing than the `git diff | grep` and step-conditionals approach.
84 lines
2.6 KiB
YAML
84 lines
2.6 KiB
YAML
# Rejects PR if requirements files are inconsistent.
|
|
#
|
|
# This will produce a failing check for any PR that does not produce a
|
|
# clean run of `make compile-requirements` on Linux.
|
|
|
|
name: Consistent Python dependencies
|
|
|
|
on:
|
|
pull_request:
|
|
|
|
defaults:
|
|
run:
|
|
shell: bash # strict bash
|
|
|
|
jobs:
|
|
check-requirements:
|
|
name: Compile requirements
|
|
runs-on: ubuntu-22.04
|
|
|
|
steps:
|
|
# Only run remaining steps if there are changes to requirements/**
|
|
- name: "Decide whether to short-circuit"
|
|
env:
|
|
GH_TOKEN: "${{ github.token }}"
|
|
PR_URL: "${{ github.event.pull_request.html_url }}"
|
|
run: |
|
|
paths=$(gh pr diff "$PR_URL" --name-only)
|
|
echo $'Paths touched in PR:\n'"$paths"
|
|
|
|
# The ^"? is because git may quote weird file paths
|
|
matched="$(echo "$paths" | grep -P '^"?requirements/' || true)"
|
|
echo $'Relevant paths:\n'"$matched"
|
|
if [[ -n "$matched" ]]; then
|
|
echo "RELEVANT=true" >> "$GITHUB_ENV"
|
|
fi
|
|
|
|
- uses: actions/checkout@v3
|
|
if: ${{ env.RELEVANT == 'true' }}
|
|
|
|
- uses: actions/setup-python@v4
|
|
if: ${{ env.RELEVANT == 'true' }}
|
|
with:
|
|
python-version: '3.8'
|
|
|
|
- name: "Recompile requirements"
|
|
if: ${{ env.RELEVANT == 'true' }}
|
|
run: |
|
|
make compile-requirements
|
|
|
|
- name: Fail if compiling requirements caused changes
|
|
if: ${{ env.RELEVANT == 'true' }}
|
|
run: |
|
|
SUMMARY_HELP=$(cat <<'EOMARKDOWN'
|
|
# Inconsistent Python dependencies
|
|
|
|
It appears that the Python dependencies in this PR are inconsistent: A re-run of
|
|
`make compile-requirements` produced changes. This might mean that your PR would
|
|
fail to deploy properly in production, or could have inconsistent behavior for
|
|
developers.
|
|
|
|
Please see the requirements README for information on how to resolve this:
|
|
https://github.com/openedx/edx-platform/blob/master/requirements/README.rst#inconsistent-dependencies
|
|
EOMARKDOWN
|
|
)
|
|
|
|
make_summary () {
|
|
echo "$SUMMARY_HELP"
|
|
echo
|
|
echo "----"
|
|
echo
|
|
echo "Diff follows:"
|
|
echo
|
|
echo '```'
|
|
git diff || true
|
|
echo '```'
|
|
}
|
|
|
|
git diff --quiet --exit-code || {
|
|
# Job Summaries are cool, but echo to the job log as well, because
|
|
# that's where the PR checks will actually link to.
|
|
make_summary | tee -a $GITHUB_STEP_SUMMARY
|
|
exit 1
|
|
}
|