Skip to content

Commit f51ae6f

Browse files
committed
ci: create separate workflows for code-quality
Signed-off-by: Maruszewski, Piotr <[email protected]>
1 parent 60e9601 commit f51ae6f

14 files changed

+361
-261
lines changed

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "pip"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"

.github/dependency_review.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
fail-on-severity: 'low'
2+
allow-licenses:
3+
- 'BSD-2-Clause'
4+
- 'BSD-3-Clause'
5+
- 'BSD-3-Clause-Clear'
6+
- 'BSD-2-Clause-Views'
7+
- 'MIT'
8+
- 'Apache-2.0'
9+
- 'ISC'
10+
- 'BlueOak-1.0.0'
11+
- '0BSD'
12+
- 'Python-2.0'
13+
- 'LGPL-3.0'
14+
- 'MPL-2.0'
15+
fail-on-scopes:
16+
- 'runtime'
17+
- 'development'
18+
- 'unknown'
19+
license-check: true
20+
vulnerability-check: true
21+
allow-dependencies-licenses:
22+
- 'pkg:pypi/[email protected]'
23+
- 'pkg:pypi/psycopg2-binary'
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: 'Prepare test environment'
2+
inputs:
3+
PYTHON_VERSION:
4+
description: 'Python version to use'
5+
required: true
6+
SOURCE_PATH:
7+
description: 'Path to the source code directory'
8+
required: false
9+
default: 'src'
10+
type: string
11+
VIRTUALENV_PATH:
12+
description: 'Virtualenv path'
13+
required: false
14+
default: 'virtualenv'
15+
type: string
16+
17+
runs:
18+
using: "composite"
19+
steps:
20+
- name: Checkout main repository
21+
uses: actions/checkout@v4
22+
with:
23+
path: ${{ inputs.SOURCE_PATH }}
24+
fetch-depth: 0
25+
- name: Set up Python
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: ${{ inputs.PYTHON_VERSION }}
29+
cache: 'pip'
30+
31+
- name: Install dependencies
32+
shell: bash
33+
run: |
34+
python -m pip install --upgrade pip
35+
python -m venv ${{ inputs.VIRTUALENV_PATH }}
36+
source ${{ inputs.VIRTUALENV_PATH }}/*/activate
37+
python --version
38+
pip install ./${{ inputs.SOURCE_PATH }}
39+
pip install -r ${{ inputs.SOURCE_PATH }}/requirements-test.txt
40+
pip install -r ${{ inputs.SOURCE_PATH }}/requirements-dev.txt
41+
pip install -r ${{ inputs.SOURCE_PATH }}/requirements.txt

.github/workflows/build_upload_whl.yml

Lines changed: 63 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
description: 'PyPI API token to publish package'
1010
required: false
1111
inputs:
12-
UPLOAD_PACKAGE:
12+
RELEASE_STEPS:
1313
description: 'Should the package be uploaded to PyPI?'
1414
required: false
1515
default: false
@@ -27,181 +27,119 @@ on:
2727
required: false
2828
default: '3.10.11'
2929
type: string
30-
PUSH_TAG:
31-
description: 'Push tag after version bump'
32-
required: false
33-
default: false
34-
type: boolean
3530
RELEASE_BUILD:
3631
description: 'Is release build?'
3732
required: false
3833
default: false
3934
type: boolean
40-
GIT_USER:
41-
description: 'Git user name for commit and tag'
42-
required: true
43-
type: string
44-
GIT_EMAIL:
45-
description: 'Git user email for commit and tag'
46-
required: true
47-
type: string
48-
PROJECT_NAME:
49-
description: 'Project name for tests'
50-
required: true
51-
type: string
52-
SOURCE_PATH:
53-
description: 'Path to the source code directory'
54-
required: false
55-
default: 'src'
56-
type: string
5735
RUNS_ON:
5836
description: 'Runner type for the job'
5937
required: false
6038
default: 'ubuntu-latest'
6139
type: string
40+
JOB_NAME:
41+
description: 'Name of the job'
42+
required: false
43+
default: 'build_whl'
44+
type: string
6245

6346
jobs:
6447
build_whl:
65-
permissions:
66-
contents: write
67-
id-token: write
68-
environment:
69-
name: "pypi"
70-
url: https://pypi.org/p/${{ inputs.PROJECT_NAME }}
48+
name: ${{ inputs.JOB_NAME }}
7149
runs-on: ${{ inputs.RUNS_ON }}
7250
steps:
7351
- uses: actions/checkout@v4
7452
with:
7553
fetch-tags: true
7654
fetch-depth: 0
77-
path: ${{ inputs.SOURCE_PATH }}
7855
ref: ${{ inputs.BRANCH_NAME }}
56+
repository: ${{ inputs.REPOSITORY_NAME }}
7957

8058
- name: Set up Python
8159
uses: actions/setup-python@v5
8260
with:
8361
python-version: ${{ inputs.PYTHON_VERSION }}
8462
cache: 'pip'
8563

86-
- name: Version bumping
87-
id: VERSION_BUMP
88-
if: inputs.RELEASE_BUILD == true
89-
env:
90-
GIT_AUTHOR_NAME: ${{ inputs.GIT_USER }}
91-
GIT_AUTHOR_EMAIL: ${{ inputs.GIT_EMAIL }}
92-
GIT_COMMITTER_NAME: ${{ inputs.GIT_USER }}
93-
GIT_COMMITTER_EMAIL: ${{ inputs.GIT_EMAIL }}
94-
shell: bash
95-
run: |
96-
python -m pip install --upgrade pip
97-
python -m venv bump_version
98-
source bump_version/bin/activate
99-
pip install python-semantic-release~=10.2
100-
pip install -r ${{ inputs.SOURCE_PATH }}/requirements-dev.txt
101-
pip install ./${{ inputs.SOURCE_PATH }}
102-
mfd-create-config-files --project-dir ./${{ inputs.SOURCE_PATH }}
103-
cd ${{ inputs.SOURCE_PATH }}
104-
version_after_bump=$(semantic-release version --print | tail -n 1 | tr -d '\n')
105-
version_from_tag=$(git describe --tags --abbrev=0 | tr -d '\n' | sed 's/^v//')
106-
echo "Version after semantic-release bump is: ${version_after_bump}"
107-
echo "Version from tag: ${version_from_tag}"
108-
# Only check version equality if RELEASE_BUILD is true
109-
if [ "${{ inputs.RELEASE_BUILD }}" == "true" ]; then
110-
if [ "$version_after_bump" == "$version_from_tag" ]; then
111-
echo "Version would not change: version_after_bump=${version_after_bump}, version_from_tag=${version_from_tag}"
112-
exit 1
113-
fi
114-
fi
115-
semantic-release version --no-push --no-vcs-release
116-
cat pyproject.toml
117-
echo "version_after_bump=v${version_after_bump}" >> $GITHUB_OUTPUT
118-
- name: Create virtual environment for whl creation
119-
shell: bash
64+
- name: Show python version
65+
run: python --version
66+
67+
- name: Run mfd-create-config-files
12068
run: |
121-
python -m venv whl_creation
122-
source whl_creation/bin/activate
123-
pip install build==1.2.2.post1
124-
cd ${{ inputs.SOURCE_PATH }}
125-
../whl_creation/bin/python -m build --wheel --outdir ../whl_creation/dist
126-
ls -l ../whl_creation/dist
69+
pip install -r requirements-dev.txt
70+
pip install .
71+
mfd-create-config-files --project-dir .
12772
128-
- name: Determine if unit and functional tests should run
129-
id: test_check
130-
shell: bash
73+
- name: Check if bump version is expected
13174
run: |
132-
REPO_NAME=$(echo "${{ inputs.PROJECT_NAME }}")
133-
echo "Repository name extracted: $REPO_NAME"
75+
if [ "${{ inputs.RELEASE_BUILD }}" = "false" ]; then
76+
COMMIT_MSG=$(git log -1 --pretty=%B)
13477
135-
UNIT_TEST_DIR="${{ inputs.SOURCE_PATH }}/tests/unit/test_$(echo "${REPO_NAME}" | tr '-' '_')"
136-
FUNC_TEST_DIR="${{ inputs.SOURCE_PATH }}/tests/system/test_$(echo "${REPO_NAME}" | tr '-' '_')"
137-
if [ -d "$UNIT_TEST_DIR" ]; then
138-
echo "Unit tests directory exists: $UNIT_TEST_DIR"
139-
echo "run_unit_tests=true" >> $GITHUB_OUTPUT
140-
else
141-
echo "Unit tests directory does not exist: $UNIT_TEST_DIR"
142-
echo "run_unit_tests=false" >> $GITHUB_OUTPUT
143-
fi
144-
if [ -d "$FUNC_TEST_DIR" ]; then
145-
echo "Functional tests directory exists: $FUNC_TEST_DIR"
146-
echo "run_functional_tests=true" >> $GITHUB_OUTPUT
78+
if echo "$COMMIT_MSG" | grep -Ei '^(docs|build|test|ci|refactor|perf|chore|revert):\s'; then
79+
echo "CREATE_WHL=false" >> $GITHUB_ENV
80+
echo "No version bump needed for commit message: $COMMIT_MSG, ending job"
81+
else
82+
echo "CREATE_WHL=true" >> $GITHUB_ENV
83+
echo "Version bump needed for commit message: $COMMIT_MSG, continuing job"
84+
fi
14785
else
148-
echo "Functional tests directory does not exist: $FUNC_TEST_DIR"
149-
echo "run_functional_tests=false" >> $GITHUB_OUTPUT
86+
echo "Skipping potential bump version check for release build"
87+
echo "CREATE_WHL=true" >> $GITHUB_ENV
15088
fi
15189
152-
- name: Install dependencies for tests
153-
if: steps.test_check.outputs.run_unit_tests == 'true' || steps.test_check.outputs.run_functional_tests == 'true'
154-
shell: bash
155-
run: |
156-
python -m venv test_env
157-
source test_env/bin/activate
158-
python -m pip install -r "${{ inputs.SOURCE_PATH }}/requirements.txt" -r "${{ inputs.SOURCE_PATH }}/requirements-test.txt" -r "${{ inputs.SOURCE_PATH }}/requirements-dev.txt"
159-
python -m pip install ./${{ inputs.SOURCE_PATH }}
90+
- name: Run python-semantic-release without version bump - force patch bump
91+
if: env.CREATE_WHL == 'false'
92+
uses: python-semantic-release/[email protected]
93+
with:
94+
build: true
95+
vcs_release: false
96+
push: false
97+
strict: true
98+
force: patch
16099

161-
- name: Run unit tests if test directory exists
162-
if: steps.test_check.outputs.run_unit_tests == 'true'
163-
shell: bash
164-
run: |
165-
source test_env/bin/activate
166-
mfd-unit-tests --project-dir ${{ github.workspace }}/${{ inputs.SOURCE_PATH }}
100+
- name: Run python-semantic-release
101+
if: env.CREATE_WHL == 'true'
102+
uses: python-semantic-release/[email protected]
103+
with:
104+
build: true
105+
vcs_release: false
106+
push: false
107+
strict: true
167108

168-
- name: Run functional tests if test directory exists
169-
if: steps.test_check.outputs.run_functional_tests == 'true'
109+
- name: Check if .whl is installable
170110
shell: bash
171111
run: |
172-
source test_env/bin/activate
173-
mfd-system-tests --project-dir ${{ github.workspace }}/${{ inputs.SOURCE_PATH }}
112+
python -m pip install dist/*.whl
113+
174114
- name: Publish package distributions to PyPI
175-
if: ${{ inputs.RELEASE_BUILD == true && inputs.UPLOAD_PACKAGE == true }}
115+
if: ${{ inputs.RELEASE_BUILD == true && inputs.RELEASE_STEPS == true }}
176116
uses: pypa/gh-action-pypi-publish@release/v1
177117
with:
178-
packages-dir: 'whl_creation/dist'
118+
packages-dir: 'dist'
179119
password: ${{ secrets.PYPI_TOKEN }}
180120

181121
- name: Publish comment how to build .whl
182-
if: inputs.RELEASE_BUILD == false
122+
if: inputs.RELEASE_BUILD == false && (github.event.pull_request != null && github.event.pull_request.head.repo.full_name == github.repository) # skip for forks
183123
uses: actions/github-script@v7
184124
with:
185125
github-token: ${{ secrets.GH_TOKEN }}
186126
script: |
187127
const prNumber = context.payload.pull_request.number;
188-
const commentBody = "We don't publish DEVs .whl.\n To build .whl, run 'pip install git+https://github.com/${{ inputs.REPOSITORY_NAME }}@${{ inputs.BRANCH_NAME }}'";
189-
await github.rest.issues.createComment({
128+
const commentBody = "We don't publish DEVs .whl.\n To build .whl, run 'pip install git+https://${{ inputs.REPOSITORY_NAME }}@${{ inputs.BRANCH_NAME }}'";
129+
130+
const { data: comments } = await github.rest.issues.listComments({
190131
owner: context.repo.owner,
191132
repo: context.repo.repo,
192133
issue_number: prNumber,
193-
body: commentBody
194134
});
195135
196-
- name: Push git tag after version bump
197-
if: ${{ inputs.RELEASE_BUILD == true && inputs.PUSH_TAG == true }}
198-
shell: bash
199-
env:
200-
GIT_AUTHOR_NAME: ${{ inputs.GIT_USER }}
201-
GIT_AUTHOR_EMAIL: ${{ inputs.GIT_EMAIL }}
202-
GIT_COMMITTER_NAME: ${{ inputs.GIT_USER }}
203-
GIT_COMMITTER_EMAIL: ${{ inputs.GIT_EMAIL }}
204-
version_after_bump: ${{ steps.VERSION_BUMP.outputs.version_after_bump }}
205-
run: |
206-
cd ${{ inputs.SOURCE_PATH }}
207-
git push origin "${version_after_bump}"
136+
const alreadyCommented = comments.some(comment => comment.body === commentBody);
137+
138+
if (!alreadyCommented) {
139+
await github.rest.issues.createComment({
140+
owner: context.repo.owner,
141+
repo: context.repo.repo,
142+
issue_number: prNumber,
143+
body: commentBody
144+
});
145+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Check Code Standard
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
7+
env:
8+
SOURCE_PATH: 'src'
9+
VIRTUALENV_PATH: 'virtualenv'
10+
11+
jobs:
12+
run_check_standard:
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
python_version: ['3.10', '3.13']
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout this repository
20+
uses: actions/checkout@v4
21+
with:
22+
path: current_repo
23+
- uses: ./current_repo/.github/prepare_test_env
24+
with:
25+
PYTHON_VERSION: ${{ matrix.python_version }}
26+
- name: Run mfd-code-standard
27+
shell: bash
28+
run: |
29+
source ${{ github.workspace }}/${{ env.VIRTUALENV_PATH }}/*/activate
30+
mfd-code-standard --project-dir ${{ github.workspace }}/${{ env.SOURCE_PATH }}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Title + Commit Validation
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
7+
jobs:
8+
validate_pr_format:
9+
uses: intel/mfd/.github/workflows/check_pr_format.yml@main
10+
with:
11+
REPOSITORY_NAME: ${{ github.event.pull_request.head.repo.full_name }}
12+
BRANCH_NAME: ${{ github.head_ref }}

0 commit comments

Comments
 (0)