Skip to content

Commit b5fc7fa

Browse files
authored
[ci] Refactor CI workflows to separate the PR comment actions into a new workflow (#4034)
- Refactor the CI workflows to separate the PR comments actions into a new workflow and only run for Python3.11 - This will help us to mark these actions required or not, so that is does not block merging PRs when something is broken in them. - For example: If the PR is coming from a fork Hue repo, the PR comments actions fails because of insufficient permissions on the Github token. This is a good thing but it should not break the flow of other checks.
1 parent 573ee8e commit b5fc7fa

File tree

2 files changed

+98
-44
lines changed

2 files changed

+98
-44
lines changed

.github/workflows/commitflow-py3.yml

+7-44
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ jobs:
1515
strategy:
1616
matrix:
1717
python-version: ['3.8', '3.9', '3.10', '3.11']
18-
19-
permissions:
20-
contents: write
21-
checks: write
22-
pull-requests: write
2318

2419
steps:
2520
- name: Checkout
@@ -67,45 +62,6 @@ jobs:
6762
- name: Run python unit tests
6863
run: |
6964
./build/env/bin/pytest
70-
71-
- name: Upload pytest and code coverage reports
72-
if: matrix.python-version == '3.11'
73-
uses: actions/upload-artifact@v4
74-
with:
75-
name: hue-test-reports
76-
path: ./reports
77-
78-
- name: Add pytest and code coverage PR comment
79-
if: matrix.python-version == '3.11'
80-
uses: MishaKav/pytest-coverage-comment@v1
81-
with:
82-
pytest-xml-coverage-path: ./reports/code-cov/coverage.xml
83-
junitxml-path: ./reports/pytest/test_report.xml
84-
junitxml-title: Pytest Report
85-
title: Backend Code Coverage Report
86-
badge-title: Backend Codecov
87-
report-only-changed-files: true
88-
xml-skip-covered: true
89-
remove-link-from-badge: true
90-
default-branch: master
91-
92-
- name: Check and comment if no unit test files modified
93-
if: matrix.python-version == '3.11'
94-
run: |
95-
git fetch origin master
96-
changed_files=$(git diff --name-only origin/master)
97-
98-
if echo "$changed_files" | grep -qE '(^test|_test\.py|^tests|_tests\.py|.test)'; then
99-
echo "✅ Unit test files were modified."
100-
else
101-
echo "⚠️ No unit test files modified."
102-
103-
curl -X POST \
104-
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
105-
-H "Accept: application/vnd.github.v3+json" \
106-
-d '{"body":"⚠️ No unit test files modified. Please ensure that changes are properly tested. ⚠️"}' \
107-
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments"
108-
fi
10965
11066
- name: Run python lints
11167
run: |
@@ -126,3 +82,10 @@ jobs:
12682
./tools/ci/check_for_website_dead_links.sh docs/docs-site
12783
# ./tools/ci/check_for_website_dead_links.sh docs/gethue
12884
85+
- name: Upload reports
86+
if: matrix.python-version == '3.11'
87+
uses: actions/upload-artifact@v4
88+
with:
89+
name: hue-reports
90+
path: ./reports
91+

.github/workflows/pr-comments.yml

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: PR Comments
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
8+
permissions:
9+
contents: write
10+
checks: write
11+
pull-requests: write
12+
13+
jobs:
14+
pytest-codecov-comment:
15+
runs-on: ubuntu-22.04
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Python 3.11
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: 3.11
24+
25+
- name: Cache pip
26+
uses: actions/cache@v4
27+
with:
28+
# This path is specific to Ubuntu
29+
path: ~/.cache/pip
30+
key: ${{ runner.os }}-pip-${{ hashFiles('desktop/core/requirements.txt') }}
31+
restore-keys: |
32+
${{ runner.os }}-pip-
33+
${{ runner.os }}-
34+
35+
- name: Setup node 20 and cache npm
36+
uses: actions/setup-node@v4
37+
with:
38+
node-version: 20
39+
cache: 'npm'
40+
41+
- name: Build Hue
42+
run: |
43+
sudo apt-get update
44+
sudo apt-get install -y gcc g++ build-essential python3.11-dev python3.11-venv python3.11-distutils asciidoc rsync curl sudo libkrb5-dev libldap2-dev libsasl2-dev libxml2-dev libxslt-dev libsasl2-modules-gssapi-mit libsnappy-dev libffi-dev # This should not be needed as some point
45+
sudo curl -sL https://bootstrap.pypa.io/get-pip.py | sudo python3.11
46+
sudo apt-get install -y python3-setuptools
47+
sudo apt-get install -y libncursesw5-dev libgdbm-dev libc6-dev libssl-dev openssl
48+
49+
export PYTHON_VER=python3.11
50+
export ROOT=$PWD
51+
make test_prep
52+
53+
- name: Run python unit tests
54+
run: |
55+
./build/env/bin/pytest
56+
57+
- name: Add pytest and code coverage PR comment
58+
uses: MishaKav/pytest-coverage-comment@v1
59+
with:
60+
pytest-xml-coverage-path: ./reports/code-cov/coverage.xml
61+
junitxml-path: ./reports/pytest/test_report.xml
62+
junitxml-title: Pytest Report
63+
title: Backend Code Coverage Report
64+
badge-title: Backend Codecov
65+
report-only-changed-files: true
66+
xml-skip-covered: true
67+
remove-link-from-badge: true
68+
default-branch: master
69+
70+
ut-files-comment:
71+
runs-on: ubuntu-22.04
72+
steps:
73+
- name: Checkout code
74+
uses: actions/checkout@v4
75+
76+
- name: Check and comment if no unit test files modified
77+
run: |
78+
git fetch origin master
79+
changed_files=$(git diff --name-only origin/master)
80+
81+
if echo "$changed_files" | grep -qE '(^test|_test\.py|^tests|_tests\.py|.test)'; then
82+
echo "✅ Unit test files were modified."
83+
else
84+
echo "⚠️ No unit test files modified."
85+
86+
curl -X POST \
87+
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
88+
-H "Accept: application/vnd.github.v3+json" \
89+
-d '{"body":"⚠️ No unit test files modified. Please ensure that changes are properly tested. ⚠️"}' \
90+
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments"
91+
fi

0 commit comments

Comments
 (0)