-
Notifications
You must be signed in to change notification settings - Fork 3.9k
83 lines (69 loc) · 2.62 KB
/
check-consistent-dependencies.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# 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/)|(scripts/.*?/requirements/))' || true)"
echo $'Relevant paths:\n'"$matched"
if [[ -n "$matched" ]]; then
echo "RELEVANT=true" >> "$GITHUB_ENV"
fi
- uses: actions/checkout@v4
if: ${{ env.RELEVANT == 'true' }}
- uses: actions/setup-python@v5
if: ${{ env.RELEVANT == 'true' }}
with:
python-version: '3.11'
- 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
}