From bb45ccbe08804d24a6c013d7bab324cad237930c Mon Sep 17 00:00:00 2001 From: "Maruszewski, Piotr" Date: Tue, 16 Sep 2025 14:54:09 +0200 Subject: [PATCH] ci: create separate workflows for code-quality Signed-off-by: Maruszewski, Piotr --- .github/dependabot.yml | 6 + .github/dependency_review.yml | 23 +++ .github/prepare_test_env/action.yml | 41 +++++ .github/workflows/build_upload_whl.yml | 186 ++++++++-------------- .github/workflows/check_code_standard.yml | 30 ++++ .github/workflows/check_pr_format.yml | 12 ++ .github/workflows/codeql.yml | 93 +---------- .github/workflows/dependency_review.yml | 9 ++ .github/workflows/main.yml | 23 +++ .github/workflows/manual_release.yml | 37 +++-- .github/workflows/publish_release.yml | 67 ++++++++ .github/workflows/pull_request.yml | 20 +++ .github/workflows/pull_requests.yml | 29 ---- .github/workflows/run_tests.yml | 106 ++++++++++++ requirements-dev.txt | 2 +- 15 files changed, 428 insertions(+), 256 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/dependency_review.yml create mode 100644 .github/prepare_test_env/action.yml create mode 100644 .github/workflows/check_code_standard.yml create mode 100644 .github/workflows/check_pr_format.yml create mode 100644 .github/workflows/dependency_review.yml create mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/publish_release.yml create mode 100644 .github/workflows/pull_request.yml delete mode 100644 .github/workflows/pull_requests.yml create mode 100644 .github/workflows/run_tests.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..b38df29 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "pip" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/dependency_review.yml b/.github/dependency_review.yml new file mode 100644 index 0000000..dfec285 --- /dev/null +++ b/.github/dependency_review.yml @@ -0,0 +1,23 @@ +fail-on-severity: 'low' +allow-licenses: + - 'BSD-2-Clause' + - 'BSD-3-Clause' + - 'BSD-3-Clause-Clear' + - 'BSD-2-Clause-Views' + - 'MIT' + - 'Apache-2.0' + - 'ISC' + - 'BlueOak-1.0.0' + - '0BSD' + - 'Python-2.0' + - 'LGPL-3.0' + - 'MPL-2.0' +fail-on-scopes: + - 'runtime' + - 'development' + - 'unknown' +license-check: true +vulnerability-check: true +allow-dependencies-licenses: + - 'pkg:pypi/PyGithub@2.2.0' + - 'pkg:pypi/psycopg2-binary' \ No newline at end of file diff --git a/.github/prepare_test_env/action.yml b/.github/prepare_test_env/action.yml new file mode 100644 index 0000000..14cca47 --- /dev/null +++ b/.github/prepare_test_env/action.yml @@ -0,0 +1,41 @@ +name: 'Prepare test environment' +inputs: + PYTHON_VERSION: + description: 'Python version to use' + required: true + SOURCE_PATH: + description: 'Path to the source code directory' + required: false + default: 'src' + type: string + VIRTUALENV_PATH: + description: 'Virtualenv path' + required: false + default: 'virtualenv' + type: string + +runs: + using: "composite" + steps: + - name: Checkout main repository + uses: actions/checkout@v4 + with: + path: ${{ inputs.SOURCE_PATH }} + fetch-depth: 0 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ inputs.PYTHON_VERSION }} + cache: 'pip' + + - name: Install dependencies + shell: bash + run: | + python -m pip install --upgrade pip + python -m venv ${{ inputs.VIRTUALENV_PATH }} + source ${{ inputs.VIRTUALENV_PATH }}/*/activate + python --version + pip install ./${{ inputs.SOURCE_PATH }} + pip install -r ${{ inputs.SOURCE_PATH }}/requirements-test.txt + pip install -r ${{ inputs.SOURCE_PATH }}/requirements-dev.txt + pip install -r ${{ inputs.SOURCE_PATH }}/requirements.txt diff --git a/.github/workflows/build_upload_whl.yml b/.github/workflows/build_upload_whl.yml index dbb23d1..4ea525c 100644 --- a/.github/workflows/build_upload_whl.yml +++ b/.github/workflows/build_upload_whl.yml @@ -9,7 +9,7 @@ on: description: 'PyPI API token to publish package' required: false inputs: - UPLOAD_PACKAGE: + RELEASE_STEPS: description: 'Should the package be uploaded to PyPI?' required: false default: false @@ -27,55 +27,37 @@ on: required: false default: '3.10.11' type: string - PUSH_TAG: - description: 'Push tag after version bump' - required: false - default: false - type: boolean RELEASE_BUILD: description: 'Is release build?' required: false default: false type: boolean - GIT_USER: - description: 'Git user name for commit and tag' - required: true - type: string - GIT_EMAIL: - description: 'Git user email for commit and tag' - required: true - type: string PROJECT_NAME: - description: 'Project name for tests' + description: 'Project name' required: true type: string - SOURCE_PATH: - description: 'Path to the source code directory' - required: false - default: 'src' - type: string RUNS_ON: description: 'Runner type for the job' required: false default: 'ubuntu-latest' type: string + JOB_NAME: + description: 'Name of the job' + required: false + default: 'build_whl' + type: string jobs: build_whl: - permissions: - contents: write - id-token: write - environment: - name: "pypi" - url: https://pypi.org/p/${{ inputs.PROJECT_NAME }} + name: ${{ inputs.JOB_NAME }} runs-on: ${{ inputs.RUNS_ON }} steps: - uses: actions/checkout@v4 with: fetch-tags: true fetch-depth: 0 - path: ${{ inputs.SOURCE_PATH }} ref: ${{ inputs.BRANCH_NAME }} + repository: ${{ inputs.REPOSITORY_NAME }} - name: Set up Python uses: actions/setup-python@v5 @@ -83,125 +65,85 @@ jobs: python-version: ${{ inputs.PYTHON_VERSION }} cache: 'pip' - - name: Version bumping - id: VERSION_BUMP - if: inputs.RELEASE_BUILD == true - env: - GIT_AUTHOR_NAME: ${{ inputs.GIT_USER }} - GIT_AUTHOR_EMAIL: ${{ inputs.GIT_EMAIL }} - GIT_COMMITTER_NAME: ${{ inputs.GIT_USER }} - GIT_COMMITTER_EMAIL: ${{ inputs.GIT_EMAIL }} - shell: bash - run: | - python -m pip install --upgrade pip - python -m venv bump_version - source bump_version/bin/activate - pip install python-semantic-release~=10.2 - pip install -r ${{ inputs.SOURCE_PATH }}/requirements-dev.txt - pip install ./${{ inputs.SOURCE_PATH }} - mfd-create-config-files --project-dir ./${{ inputs.SOURCE_PATH }} - cd ${{ inputs.SOURCE_PATH }} - version_after_bump=$(semantic-release version --print | tail -n 1 | tr -d '\n') - version_from_tag=$(git describe --tags --abbrev=0 | tr -d '\n' | sed 's/^v//') - echo "Version after semantic-release bump is: ${version_after_bump}" - echo "Version from tag: ${version_from_tag}" - # Only check version equality if RELEASE_BUILD is true - if [ "${{ inputs.RELEASE_BUILD }}" == "true" ]; then - if [ "$version_after_bump" == "$version_from_tag" ]; then - echo "Version would not change: version_after_bump=${version_after_bump}, version_from_tag=${version_from_tag}" - exit 1 - fi - fi - semantic-release version --no-push --no-vcs-release - cat pyproject.toml - echo "version_after_bump=v${version_after_bump}" >> $GITHUB_OUTPUT - - name: Create virtual environment for whl creation - shell: bash + - name: Show python version + run: python --version + + - name: Run mfd-create-config-files run: | - python -m venv whl_creation - source whl_creation/bin/activate - pip install build==1.2.2.post1 - cd ${{ inputs.SOURCE_PATH }} - ../whl_creation/bin/python -m build --wheel --outdir ../whl_creation/dist - ls -l ../whl_creation/dist + pip install -r requirements-dev.txt + pip install . + mfd-create-config-files --project-dir . - - name: Determine if unit and functional tests should run - id: test_check - shell: bash + - name: Check if bump version is expected run: | - REPO_NAME=$(echo "${{ inputs.PROJECT_NAME }}") - echo "Repository name extracted: $REPO_NAME" + if [ "${{ inputs.RELEASE_BUILD }}" = "false" ]; then + COMMIT_MSG=$(git log -1 --pretty=%B) - UNIT_TEST_DIR="${{ inputs.SOURCE_PATH }}/tests/unit/test_$(echo "${REPO_NAME}" | tr '-' '_')" - FUNC_TEST_DIR="${{ inputs.SOURCE_PATH }}/tests/system/test_$(echo "${REPO_NAME}" | tr '-' '_')" - if [ -d "$UNIT_TEST_DIR" ]; then - echo "Unit tests directory exists: $UNIT_TEST_DIR" - echo "run_unit_tests=true" >> $GITHUB_OUTPUT - else - echo "Unit tests directory does not exist: $UNIT_TEST_DIR" - echo "run_unit_tests=false" >> $GITHUB_OUTPUT - fi - if [ -d "$FUNC_TEST_DIR" ]; then - echo "Functional tests directory exists: $FUNC_TEST_DIR" - echo "run_functional_tests=true" >> $GITHUB_OUTPUT + if echo "$COMMIT_MSG" | grep -Ei '^(docs|build|test|ci|refactor|perf|chore|revert):\s'; then + echo "CREATE_WHL=false" >> $GITHUB_ENV + echo "No version bump needed for commit message: $COMMIT_MSG, ending job" + else + echo "CREATE_WHL=true" >> $GITHUB_ENV + echo "Version bump needed for commit message: $COMMIT_MSG, continuing job" + fi else - echo "Functional tests directory does not exist: $FUNC_TEST_DIR" - echo "run_functional_tests=false" >> $GITHUB_OUTPUT + echo "Skipping potential bump version check for release build" + echo "CREATE_WHL=true" >> $GITHUB_ENV fi - - name: Install dependencies for tests - if: steps.test_check.outputs.run_unit_tests == 'true' || steps.test_check.outputs.run_functional_tests == 'true' - shell: bash - run: | - python -m venv test_env - source test_env/bin/activate - python -m pip install -r "${{ inputs.SOURCE_PATH }}/requirements.txt" -r "${{ inputs.SOURCE_PATH }}/requirements-test.txt" -r "${{ inputs.SOURCE_PATH }}/requirements-dev.txt" - python -m pip install ./${{ inputs.SOURCE_PATH }} + - name: Run python-semantic-release without version bump - force patch bump + if: env.CREATE_WHL == 'false' + uses: python-semantic-release/python-semantic-release@v10.3.1 + with: + build: true + vcs_release: false + push: false + strict: true + force: patch - - name: Run unit tests if test directory exists - if: steps.test_check.outputs.run_unit_tests == 'true' - shell: bash - run: | - source test_env/bin/activate - mfd-unit-tests --project-dir ${{ github.workspace }}/${{ inputs.SOURCE_PATH }} + - name: Run python-semantic-release + if: env.CREATE_WHL == 'true' + uses: python-semantic-release/python-semantic-release@v10.3.1 + with: + build: true + vcs_release: false + push: false + strict: true - - name: Run functional tests if test directory exists - if: steps.test_check.outputs.run_functional_tests == 'true' + - name: Check if .whl is installable shell: bash run: | - source test_env/bin/activate - mfd-system-tests --project-dir ${{ github.workspace }}/${{ inputs.SOURCE_PATH }} + python -m pip install dist/*.whl + - name: Publish package distributions to PyPI - if: ${{ inputs.RELEASE_BUILD == true && inputs.UPLOAD_PACKAGE == true }} + if: ${{ inputs.RELEASE_BUILD == true && inputs.RELEASE_STEPS == true }} uses: pypa/gh-action-pypi-publish@release/v1 with: - packages-dir: 'whl_creation/dist' + packages-dir: 'dist' password: ${{ secrets.PYPI_TOKEN }} - name: Publish comment how to build .whl - if: inputs.RELEASE_BUILD == false + if: inputs.RELEASE_BUILD == false && (github.event.pull_request != null && github.event.pull_request.head.repo.full_name == github.repository) # skip for forks uses: actions/github-script@v7 with: github-token: ${{ secrets.GH_TOKEN }} script: | const prNumber = context.payload.pull_request.number; - 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 }}'"; - await github.rest.issues.createComment({ + const commentBody = "We don't publish DEVs .whl.\n To build .whl, run 'pip install git+https://${{ inputs.REPOSITORY_NAME }}@${{ inputs.BRANCH_NAME }}'"; + + const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: prNumber, - body: commentBody }); - - name: Push git tag after version bump - if: ${{ inputs.RELEASE_BUILD == true && inputs.PUSH_TAG == true }} - shell: bash - env: - GIT_AUTHOR_NAME: ${{ inputs.GIT_USER }} - GIT_AUTHOR_EMAIL: ${{ inputs.GIT_EMAIL }} - GIT_COMMITTER_NAME: ${{ inputs.GIT_USER }} - GIT_COMMITTER_EMAIL: ${{ inputs.GIT_EMAIL }} - version_after_bump: ${{ steps.VERSION_BUMP.outputs.version_after_bump }} - run: | - cd ${{ inputs.SOURCE_PATH }} - git push origin "${version_after_bump}" \ No newline at end of file + const alreadyCommented = comments.some(comment => comment.body === commentBody); + + if (!alreadyCommented) { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body: commentBody + }); + } diff --git a/.github/workflows/check_code_standard.yml b/.github/workflows/check_code_standard.yml new file mode 100644 index 0000000..bf2de23 --- /dev/null +++ b/.github/workflows/check_code_standard.yml @@ -0,0 +1,30 @@ +name: Check Code Standard + +on: + pull_request: + types: [opened, synchronize] + +env: + SOURCE_PATH: 'src' + VIRTUALENV_PATH: 'virtualenv' + +jobs: + run_check_standard: + strategy: + fail-fast: false + matrix: + python_version: ['3.10', '3.13'] + runs-on: ubuntu-latest + steps: + - name: Checkout this repository + uses: actions/checkout@v4 + with: + path: current_repo + - uses: ./current_repo/.github/prepare_test_env + with: + PYTHON_VERSION: ${{ matrix.python_version }} + - name: Run mfd-code-standard + shell: bash + run: | + source ${{ github.workspace }}/${{ env.VIRTUALENV_PATH }}/*/activate + mfd-code-standard --project-dir ${{ github.workspace }}/${{ env.SOURCE_PATH }} diff --git a/.github/workflows/check_pr_format.yml b/.github/workflows/check_pr_format.yml new file mode 100644 index 0000000..ed32e34 --- /dev/null +++ b/.github/workflows/check_pr_format.yml @@ -0,0 +1,12 @@ +name: Title + Commit Validation + +on: + pull_request: + types: [opened, synchronize] + +jobs: + validate_pr_format: + uses: intel/mfd/.github/workflows/check_pr_format.yml@main + with: + REPOSITORY_NAME: ${{ github.event.pull_request.head.repo.full_name }} + BRANCH_NAME: ${{ github.head_ref }} diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 4c43daf..8f86482 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -1,15 +1,4 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "CodeQL Advanced" +name: CodeQL Advanced on: pull_request: @@ -18,81 +7,11 @@ on: branches: [ "main" ] jobs: - analyze: - name: Analyze (${{ matrix.language }}) - # Runner size impacts CodeQL analysis time. To learn more, please see: - # - https://gh.io/recommended-hardware-resources-for-running-codeql - # - https://gh.io/supported-runners-and-hardware-resources - # - https://gh.io/using-larger-runners (GitHub.com only) - # Consider using larger runners or machines with greater resources for possible analysis time improvements. - runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} - permissions: - # required for all workflows - security-events: write - - # required to fetch internal or private CodeQL packs - packages: read - - # only required for workflows in private repositories - actions: read - contents: read - + codeql_analysis: strategy: fail-fast: false matrix: - include: - - language: actions - build-mode: none - - language: python - build-mode: none - # CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'rust', 'swift' - # Use `c-cpp` to analyze code written in C, C++ or both - # Use 'java-kotlin' to analyze code written in Java, Kotlin or both - # Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both - # To learn more about changing the languages that are analyzed or customizing the build mode for your analysis, - # see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning. - # If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how - # 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 - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - # Add any setup steps before running the `github/codeql-action/init` action. - # This includes steps like installing compilers or runtimes (`actions/setup-node` - # or others). This is typically only required for manual builds. - # - name: Setup runtime (example) - # uses: actions/setup-example@v1 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v3 - with: - languages: ${{ matrix.language }} - build-mode: ${{ matrix.build-mode }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - - # 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 - # queries: security-extended,security-and-quality - - # If the analyze step fails for one of the languages you are analyzing with - # "We were unable to automatically build your code", modify the matrix above - # to set the build mode to "manual" for that language. Then modify this step - # to build your code. - # â„šī¸ Command-line programs to run using the OS shell. - # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun - - if: matrix.build-mode == 'manual' - shell: bash - run: | - echo 'If you are using a "manual" build mode for one or more of the' \ - 'languages you are analyzing, replace this with the commands to build' \ - 'your code, for example:' - echo ' make bootstrap' - echo ' make release' - exit 1 - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3 - with: - category: "/language:${{matrix.language}}" + language: ['actions', 'python'] + uses: intel/mfd/.github/workflows/codeql.yml@main + with: + LANGUAGE: ${{ matrix.language }} \ No newline at end of file diff --git a/.github/workflows/dependency_review.yml b/.github/workflows/dependency_review.yml new file mode 100644 index 0000000..ea04095 --- /dev/null +++ b/.github/workflows/dependency_review.yml @@ -0,0 +1,9 @@ +name: Dependency Review + +on: + pull_request: + types: [opened, synchronize] + +jobs: + dependency_review: + uses: intel/mfd/.github/workflows/dependency_review.yml@main diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..3fb960c --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,23 @@ +name: CI Build + +on: + push: + branches: + - main + +jobs: + build_whl: + strategy: + fail-fast: false + matrix: + python_version: ['3.10', '3.13'] + if: github.actor != 'mfd-intel-bot' + uses: ./.github/workflows/build_upload_whl.yml + secrets: + GH_TOKEN: ${{ secrets.GH_TOKEN }} + with: + REPOSITORY_NAME: ${{ github.repository }} + BRANCH_NAME: ${{ github.ref_name }} + PYTHON_VERSION: ${{ matrix.python_version }} + RELEASE_BUILD: true + PROJECT_NAME: 'mfd-code-quality' diff --git a/.github/workflows/manual_release.yml b/.github/workflows/manual_release.yml index c91aad2..a5d3a64 100644 --- a/.github/workflows/manual_release.yml +++ b/.github/workflows/manual_release.yml @@ -1,22 +1,18 @@ -name: CI BUILD - RELEASE MODE +name: CI Build - Release Mode + on: workflow_dispatch: jobs: - build_upload_whl: + publish_pypi: strategy: + fail-fast: false matrix: include: - - name: python-version-3-10 - python_version: '3.10' - push_tag: false - upload_package: false - continue-on-error: true - - name: python-version-3-13 - python_version: '3.13' - push_tag: true - upload_package: true - continue-on-error: true + - python_version: '3.10' + release_steps: true + - python_version: '3.13' + release_steps: false uses: ./.github/workflows/build_upload_whl.yml secrets: GH_TOKEN: ${{ secrets.GH_TOKEN }} @@ -25,9 +21,16 @@ jobs: REPOSITORY_NAME: ${{ github.repository }} BRANCH_NAME: ${{ github.ref_name }} PYTHON_VERSION: ${{ matrix.python_version }} - PUSH_TAG: ${{ matrix.push_tag }} + PROJECT_NAME: 'mfd-code-quality' + RELEASE_STEPS: ${{ matrix.release_steps }} RELEASE_BUILD: true - UPLOAD_PACKAGE: ${{ matrix.upload_package }} - GIT_USER: 'mfd-intel-bot' - GIT_EMAIL: 'mfd_intel_bot@intel.com' - PROJECT_NAME: 'mfd-code-quality' \ No newline at end of file + JOB_NAME: 'publish_pypi' + publish_release: + needs: publish_pypi + if: ${{ always() }} + uses: ./.github/workflows/publish_release.yml + secrets: + GH_TOKEN: ${{ secrets.GH_TOKEN }} + with: + REPOSITORY_NAME: ${{ github.repository }} + BRANCH_NAME: ${{ github.ref_name }} diff --git a/.github/workflows/publish_release.yml b/.github/workflows/publish_release.yml new file mode 100644 index 0000000..7694383 --- /dev/null +++ b/.github/workflows/publish_release.yml @@ -0,0 +1,67 @@ +name: Publish Release + +on: + workflow_call: + secrets: + GH_TOKEN: + description: 'GitHub token for authentication' + required: true + inputs: + RUNS_ON: + required: false + type: string + default: "ubuntu-latest" + REPOSITORY_NAME: + description: 'Repository name' + required: false + type: string + BRANCH_NAME: + description: 'Branch name to checkout' + required: true + type: string + +jobs: + push_release: + runs-on: ${{ inputs.RUNS_ON }} + steps: + - uses: actions/checkout@v4 + with: + fetch-tags: true + fetch-depth: 0 + token: ${{ secrets.GH_TOKEN }} + ref: ${{ inputs.BRANCH_NAME }} + repository: ${{ inputs.REPOSITORY_NAME }} + - name: Run mfd-create-config-files + run: | + pip install -r requirements-dev.txt + pip install . + mfd-create-config-files --project-dir . + - name: Run python-semantic-release + id: semantic_release + uses: python-semantic-release/python-semantic-release@v10.3.1 + with: + build: false + vcs_release: true + push: true + commit: false + github_token: ${{ secrets.GH_TOKEN }} + strict: true + verbosity: 2 + - name: Get old/new versions from semantic-release + run: | + echo "PREV_VERSION=${{ steps.semantic_release.outputs.previous_version }}" >> $GITHUB_ENV + echo "NEW_VERSION=${{ steps.semantic_release.outputs.version }}" >> $GITHUB_ENV + - name: Run mfd-delete-config-files + run: mfd-delete-config-files --project-dir . + - name: Update version in pyproject.toml + run: | + sed "s/$PREV_VERSION/$NEW_VERSION/" -i pyproject.toml + - name: Commit and push changes + run: | + git config --local user.email "mfd_intel_bot@intel.com" + git config --local user.name "mfd-intel-bot" + git add pyproject.toml CHANGELOG.md + git commit -s -m "chore: Release v$NEW_VERSION" + git tag -f v$NEW_VERSION + git push origin ${{ inputs.BRANCH_NAME }} --force + git push origin v$NEW_VERSION --force diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 0000000..94adfd7 --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,20 @@ +name: Dev Build + +on: + pull_request: + types: [opened, synchronize] + +jobs: + build_whl: + strategy: + fail-fast: false + matrix: + python_version: ['3.10', '3.13'] + uses: ./.github/workflows/build_upload_whl.yml + secrets: + GH_TOKEN: ${{ secrets.GH_TOKEN }} + with: + REPOSITORY_NAME: ${{ github.event.pull_request.head.repo.full_name }} + BRANCH_NAME: ${{ github.head_ref }} + PYTHON_VERSION: ${{ matrix.python_version }} + PROJECT_NAME: 'mfd-code-quality' diff --git a/.github/workflows/pull_requests.yml b/.github/workflows/pull_requests.yml deleted file mode 100644 index c12816e..0000000 --- a/.github/workflows/pull_requests.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: DEV BUILD - -on: - pull_request: - types: [opened, synchronize] - -jobs: - build_upload_whl: - strategy: - matrix: - include: - - name: python-version-3-10 - python_version: '3.10' - push_tag: false - - name: python-version-3-13 - python_version: '3.13' - push_tag: false - uses: ./.github/workflows/build_upload_whl.yml - secrets: - GH_TOKEN: ${{ secrets.GH_TOKEN }} - with: - REPOSITORY_NAME: ${{ github.repository }} - BRANCH_NAME: ${{ github.head_ref }} - PYTHON_VERSION: ${{ matrix.python_version }} - PUSH_TAG: ${{ matrix.push_tag }} - RELEASE_BUILD: false - GIT_USER: 'mfd-intel-bot' - GIT_EMAIL: 'mfd_intel_bot@intel.com' - PROJECT_NAME: 'mfd-code-quality' \ No newline at end of file diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml new file mode 100644 index 0000000..b338f19 --- /dev/null +++ b/.github/workflows/run_tests.yml @@ -0,0 +1,106 @@ +name: Run Tests (ut + ft) + +on: + pull_request: + types: [opened, synchronize] + push: + branches: + - main + +env: + SOURCE_PATH: 'src' + VIRTUALENV_PATH: 'virtualenv' + PROJECT_NAME: 'mfd-code-quality' + +jobs: + get_tests_to_run: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + python_version: ['3.10', '3.13'] + runs-on: "ubuntu-latest" + outputs: + run_unit_tests: ${{ steps.tests_path_existence.outputs.run_unit_tests }} + run_functional_tests: ${{ steps.tests_path_existence.outputs.run_functional_tests }} + steps: + - name: Checkout this repository + uses: actions/checkout@v4 + with: + path: ${{ env.SOURCE_PATH }} + - name: Determine if unit and functional tests should run + id: tests_path_existence + shell: bash + run: | + UNIT_TEST_DIR="${{ env.SOURCE_PATH }}/tests/unit/test_$(echo "${{ env.PROJECT_NAME }}" | tr '-' '_')" + FUNC_TEST_DIR="${{ env.SOURCE_PATH }}/tests/system/test_$(echo "${{ env.PROJECT_NAME }}" | tr '-' '_')" + + if [ -d "$UNIT_TEST_DIR" ]; then + echo "Unit tests directory exists: $UNIT_TEST_DIR" + echo "run_unit_tests=true" >> $GITHUB_OUTPUT + else + echo "Unit tests directory does not exist: $UNIT_TEST_DIR" + echo "run_unit_tests=false" >> $GITHUB_OUTPUT + fi + + if [ -d "$FUNC_TEST_DIR" ]; then + echo "Functional tests directory exists: $FUNC_TEST_DIR" + echo "run_functional_tests=true" >> $GITHUB_OUTPUT + else + echo "Functional tests directory does not exist: $FUNC_TEST_DIR" + echo "run_functional_tests=false" >> $GITHUB_OUTPUT + fi + + run_ft_tests: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + python_version: ['3.10', '3.13'] + name: run_ft_tests_${{ matrix.os }} + needs: get_tests_to_run + if: ${{ needs.get_tests_to_run.outputs.run_functional_tests == 'true' }} + runs-on: ${{ matrix.os }} + steps: + - name: Checkout this repository + uses: actions/checkout@v4 + with: + path: current_repo + - uses: ./current_repo/.github/prepare_test_env + with: + PYTHON_VERSION: ${{ matrix.python_version }} + - name: Run Functional Tests + shell: bash + run: | + source ${{ env.VIRTUALENV_PATH }}/*/activate + pushd ${{ env.SOURCE_PATH }} + mfd-system-tests --project-dir . + + run_ut_tests: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + python_version: ['3.10', '3.13'] + name: run_ut_tests_${{ matrix.os }} + needs: get_tests_to_run + if: ${{ needs.get_tests_to_run.outputs.run_unit_tests == 'true' }} + runs-on: ${{ matrix.os }} + steps: + - name: Checkout this repository + uses: actions/checkout@v4 + with: + path: current_repo + - uses: ./current_repo/.github/prepare_test_env + with: + PYTHON_VERSION: ${{ matrix.python_version }} + - name: Run Unit Tests + shell: bash + run: | + source ${{ env.VIRTUALENV_PATH }}/*/activate + python --version + pushd ${{ env.SOURCE_PATH }} + mfd-unit-tests-with-coverage --project-dir . + + - name: Coveralls GitHub Action + uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b #v2.3.6 diff --git a/requirements-dev.txt b/requirements-dev.txt index a19a6e8..65719fd 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1 +1 @@ --r requirements-test.txt \ No newline at end of file +-r requirements-test.txt