Skip to content

Commit 8be7e68

Browse files
committed
feat: Initial commit
Signed-off-by: Hubert Cymerys <[email protected]>
1 parent 8909416 commit 8be7e68

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3165
-2
lines changed
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
name: CI Build Reusable Workflow
2+
on:
3+
workflow_call:
4+
secrets:
5+
GH_TOKEN:
6+
description: 'GitHub token for authentication'
7+
required: true
8+
PYPI_TOKEN:
9+
description: 'PyPI API token to publish package'
10+
required: false
11+
inputs:
12+
UPLOAD_PACKAGE:
13+
description: 'Should the package be uploaded to PyPI?'
14+
required: false
15+
default: false
16+
type: boolean
17+
REPOSITORY_NAME:
18+
description: 'Repository name'
19+
required: false
20+
type: string
21+
BRANCH_NAME:
22+
description: 'Branch name to checkout'
23+
required: true
24+
type: string
25+
PYTHON_VERSION:
26+
description: 'Python version to use'
27+
required: false
28+
default: '3.10.11'
29+
type: string
30+
PUSH_TAG:
31+
description: 'Push tag after version bump'
32+
required: false
33+
default: false
34+
type: boolean
35+
RELEASE_BUILD:
36+
description: 'Is release build?'
37+
required: false
38+
default: false
39+
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
57+
RUNS_ON:
58+
description: 'Runner type for the job'
59+
required: false
60+
default: 'ubuntu-latest'
61+
type: string
62+
63+
jobs:
64+
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 }}
71+
runs-on: ${{ inputs.RUNS_ON }}
72+
steps:
73+
- uses: actions/checkout@v4
74+
with:
75+
fetch-tags: true
76+
fetch-depth: 0
77+
path: ${{ inputs.SOURCE_PATH }}
78+
ref: ${{ inputs.BRANCH_NAME }}
79+
80+
- name: Set up Python
81+
uses: actions/setup-python@v5
82+
with:
83+
python-version: ${{ inputs.PYTHON_VERSION }}
84+
cache: 'pip'
85+
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+
mfd-create-config-files --project-dir ./${{ inputs.SOURCE_PATH }}
102+
cd ${{ inputs.SOURCE_PATH }}
103+
version_after_bump=$(semantic-release version --print | tail -n 1 | tr -d '\n')
104+
version_from_tag=$(git describe --tags --abbrev=0 | tr -d '\n' | sed 's/^v//')
105+
echo "Version after semantic-release bump is: ${version_after_bump}"
106+
echo "Version from tag: ${version_from_tag}"
107+
# Only check version equality if RELEASE_BUILD is true
108+
if [ "${{ inputs.RELEASE_BUILD }}" == "true" ]; then
109+
if [ "$version_after_bump" == "$version_from_tag" ]; then
110+
echo "Version would not change: version_after_bump=${version_after_bump}, version_from_tag=${version_from_tag}"
111+
exit 1
112+
fi
113+
fi
114+
semantic-release version --no-push --no-vcs-release
115+
cat pyproject.toml
116+
echo "version_after_bump=v${version_after_bump}" >> $GITHUB_OUTPUT
117+
- name: Create virtual environment for whl creation
118+
shell: bash
119+
run: |
120+
python -m venv whl_creation
121+
source whl_creation/bin/activate
122+
pip install build==1.2.2.post1
123+
cd ${{ inputs.SOURCE_PATH }}
124+
../whl_creation/bin/python -m build --wheel --outdir ../whl_creation/dist
125+
ls -l ../whl_creation/dist
126+
127+
- name: Determine if unit and functional tests should run
128+
id: test_check
129+
shell: bash
130+
run: |
131+
REPO_NAME=$(echo "${{ inputs.PROJECT_NAME }}")
132+
echo "Repository name extracted: $REPO_NAME"
133+
134+
UNIT_TEST_DIR="${{ inputs.SOURCE_PATH }}/tests/unit/test_$(echo "${REPO_NAME}" | tr '-' '_')"
135+
FUNC_TEST_DIR="${{ inputs.SOURCE_PATH }}/tests/system/test_$(echo "${REPO_NAME}" | tr '-' '_')"
136+
if [ -d "$UNIT_TEST_DIR" ]; then
137+
echo "Unit tests directory exists: $UNIT_TEST_DIR"
138+
echo "run_unit_tests=true" >> $GITHUB_OUTPUT
139+
else
140+
echo "Unit tests directory does not exist: $UNIT_TEST_DIR"
141+
echo "run_unit_tests=false" >> $GITHUB_OUTPUT
142+
fi
143+
if [ -d "$FUNC_TEST_DIR" ]; then
144+
echo "Functional tests directory exists: $FUNC_TEST_DIR"
145+
echo "run_functional_tests=true" >> $GITHUB_OUTPUT
146+
else
147+
echo "Functional tests directory does not exist: $FUNC_TEST_DIR"
148+
echo "run_functional_tests=false" >> $GITHUB_OUTPUT
149+
fi
150+
151+
- name: Install dependencies for tests
152+
if: steps.test_check.outputs.run_unit_tests == 'true' || steps.test_check.outputs.run_functional_tests == 'true'
153+
shell: bash
154+
run: |
155+
python -m venv test_env
156+
source test_env/bin/activate
157+
python -m pip install -r "${{ inputs.SOURCE_PATH }}/requirements.txt" -r "${{ inputs.SOURCE_PATH }}/requirements-test.txt" -r "${{ inputs.SOURCE_PATH }}/requirements-dev.txt"
158+
159+
- name: Run unit tests if test directory exists
160+
if: steps.test_check.outputs.run_unit_tests == 'true'
161+
shell: bash
162+
run: |
163+
source test_env/bin/activate
164+
mfd-unit-tests --project-dir ${{ github.workspace }}/${{ inputs.SOURCE_PATH }}
165+
166+
- name: Run functional tests if test directory exists
167+
if: steps.test_check.outputs.run_functional_tests == 'true'
168+
shell: bash
169+
run: |
170+
source test_env/bin/activate
171+
mfd-system-tests --project-dir ${{ github.workspace }}/${{ inputs.SOURCE_PATH }}
172+
- name: Publish package distributions to PyPI
173+
if: ${{ inputs.RELEASE_BUILD == true && inputs.UPLOAD_PACKAGE == true }}
174+
uses: pypa/gh-action-pypi-publish@release/v1
175+
with:
176+
packages-dir: 'whl_creation/dist'
177+
password: ${{ secrets.PYPI_TOKEN }}
178+
179+
- name: Publish comment how to build .whl
180+
if: inputs.RELEASE_BUILD == false
181+
uses: actions/github-script@v7
182+
with:
183+
github-token: ${{ secrets.GH_TOKEN }}
184+
script: |
185+
const prNumber = context.payload.pull_request.number;
186+
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 }}'";
187+
await github.rest.issues.createComment({
188+
owner: context.repo.owner,
189+
repo: context.repo.repo,
190+
issue_number: prNumber,
191+
body: commentBody
192+
});
193+
194+
- name: Push git tag after version bump
195+
if: ${{ inputs.RELEASE_BUILD == true && inputs.PUSH_TAG == true }}
196+
shell: bash
197+
env:
198+
GIT_AUTHOR_NAME: ${{ inputs.GIT_USER }}
199+
GIT_AUTHOR_EMAIL: ${{ inputs.GIT_EMAIL }}
200+
GIT_COMMITTER_NAME: ${{ inputs.GIT_USER }}
201+
GIT_COMMITTER_EMAIL: ${{ inputs.GIT_EMAIL }}
202+
version_after_bump: ${{ steps.VERSION_BUMP.outputs.version_after_bump }}
203+
run: |
204+
cd ${{ inputs.SOURCE_PATH }}
205+
git push origin "${version_after_bump}"

.github/workflows/codeql.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL Advanced"
13+
14+
on:
15+
pull_request:
16+
branches: [ "main" ]
17+
push:
18+
branches: [ "main" ]
19+
20+
jobs:
21+
analyze:
22+
name: Analyze (${{ matrix.language }})
23+
# Runner size impacts CodeQL analysis time. To learn more, please see:
24+
# - https://gh.io/recommended-hardware-resources-for-running-codeql
25+
# - https://gh.io/supported-runners-and-hardware-resources
26+
# - https://gh.io/using-larger-runners (GitHub.com only)
27+
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
28+
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
29+
permissions:
30+
# required for all workflows
31+
security-events: write
32+
33+
# required to fetch internal or private CodeQL packs
34+
packages: read
35+
36+
# only required for workflows in private repositories
37+
actions: read
38+
contents: read
39+
40+
strategy:
41+
fail-fast: false
42+
matrix:
43+
include:
44+
- language: actions
45+
build-mode: none
46+
- language: python
47+
build-mode: none
48+
# CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'rust', 'swift'
49+
# Use `c-cpp` to analyze code written in C, C++ or both
50+
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
51+
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
52+
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
53+
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
54+
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
55+
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
56+
steps:
57+
- name: Checkout repository
58+
uses: actions/checkout@v4
59+
60+
# Add any setup steps before running the `github/codeql-action/init` action.
61+
# This includes steps like installing compilers or runtimes (`actions/setup-node`
62+
# or others). This is typically only required for manual builds.
63+
# - name: Setup runtime (example)
64+
# uses: actions/setup-example@v1
65+
66+
# Initializes the CodeQL tools for scanning.
67+
- name: Initialize CodeQL
68+
uses: github/codeql-action/init@v3
69+
with:
70+
languages: ${{ matrix.language }}
71+
build-mode: ${{ matrix.build-mode }}
72+
# If you wish to specify custom queries, you can do so here or in a config file.
73+
# By default, queries listed here will override any specified in a config file.
74+
# Prefix the list here with "+" to use these queries and those in the config file.
75+
76+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
77+
# queries: security-extended,security-and-quality
78+
79+
# If the analyze step fails for one of the languages you are analyzing with
80+
# "We were unable to automatically build your code", modify the matrix above
81+
# to set the build mode to "manual" for that language. Then modify this step
82+
# to build your code.
83+
# ℹ️ Command-line programs to run using the OS shell.
84+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
85+
- if: matrix.build-mode == 'manual'
86+
shell: bash
87+
run: |
88+
echo 'If you are using a "manual" build mode for one or more of the' \
89+
'languages you are analyzing, replace this with the commands to build' \
90+
'your code, for example:'
91+
echo ' make bootstrap'
92+
echo ' make release'
93+
exit 1
94+
95+
- name: Perform CodeQL Analysis
96+
uses: github/codeql-action/analyze@v3
97+
with:
98+
category: "/language:${{matrix.language}}"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: CI BUILD - RELEASE MODE
2+
on:
3+
workflow_dispatch:
4+
5+
jobs:
6+
build_upload_whl:
7+
strategy:
8+
matrix:
9+
include:
10+
- name: python-version-3-10
11+
python_version: '3.10'
12+
push_tag: false
13+
upload_package: false
14+
continue-on-error: true
15+
- name: python-version-3-13
16+
python_version: '3.13'
17+
push_tag: true
18+
upload_package: true
19+
continue-on-error: true
20+
uses: ./.github/workflows/build_upload_whl.yml
21+
secrets:
22+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
23+
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
24+
with:
25+
REPOSITORY_NAME: ${{ github.repository }}
26+
BRANCH_NAME: ${{ github.ref_name }}
27+
PYTHON_VERSION: ${{ matrix.python_version }}
28+
PUSH_TAG: ${{ matrix.push_tag }}
29+
RELEASE_BUILD: true
30+
UPLOAD_PACKAGE: ${{ matrix.upload_package }}
31+
GIT_USER: 'mfd-intel-bot'
32+
GIT_EMAIL: '[email protected]'
33+
PROJECT_NAME: 'mfd-typing'
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: DEV BUILD
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
7+
jobs:
8+
build_upload_whl:
9+
strategy:
10+
matrix:
11+
include:
12+
- name: python-version-3-10
13+
python_version: '3.10'
14+
push_tag: false
15+
- name: python-version-3-13
16+
python_version: '3.13'
17+
push_tag: false
18+
uses: ./.github/workflows/build_upload_whl.yml
19+
secrets:
20+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
21+
with:
22+
REPOSITORY_NAME: ${{ github.repository }}
23+
BRANCH_NAME: ${{ github.head_ref }}
24+
PYTHON_VERSION: ${{ matrix.python_version }}
25+
PUSH_TAG: ${{ matrix.push_tag }}
26+
RELEASE_BUILD: false
27+
GIT_USER: 'mfd-intel-bot'
28+
GIT_EMAIL: '[email protected]'
29+
PROJECT_NAME: 'mfd-typing'

0 commit comments

Comments
 (0)