CI #728
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| pull_request: | |
| release: | |
| types: [published] | |
| schedule: # run every week to see if there are any upstream issues | |
| - cron: "0 12 * * 6" | |
| jobs: | |
| style-python: | |
| name: "💄 Style: python" | |
| if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin@v4.2.2 | |
| - name: Setup python | |
| uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # pin@v5.6.0 | |
| with: | |
| python-version: 3.11 | |
| - name: Install style check dependencies | |
| run: | | |
| pip install -U ruff | |
| pip install -U wheel setuptools twine build | |
| - name: Check style | |
| run: ruff check | |
| - name: Build Plugin | |
| run: python -m build | |
| style-js: | |
| name: "💄 Style: js" | |
| if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin@v4.2.2 | |
| - name: Setup node | |
| uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # pin@v4.4.0 | |
| with: | |
| node-version: "23" | |
| - name: Install dependencies | |
| run: cd inventree_bulk_plugin/frontend && npm ci | |
| - name: Check style | |
| run: cd inventree_bulk_plugin/frontend && npm run lint | |
| tests-unit-python: | |
| name: "🧪 Unit tests: python" | |
| if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) }} | |
| needs: style-python | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin@v4.2.2 | |
| - name: Setup python | |
| uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # pin@v5.6.0 | |
| with: | |
| python-version: 3.11 | |
| - name: Install pip dependencies | |
| run: | | |
| pip install . | |
| pip install coverage==7.0.1 | |
| - name: Run tests | |
| run: | | |
| python -m coverage run -m unittest discover -s inventree_bulk_plugin.tests.unit | |
| echo $GITHUB_WORKSPACE > coverage_info | |
| - name: Upload coverage | |
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # pin@v4.6.2 | |
| with: | |
| name: unit-coverage | |
| include-hidden-files: true | |
| path: | | |
| .coverage | |
| coverage_info | |
| tests-integration-python: | |
| name: "🧪 Integration tests: python (${{ matrix.inventree-tag }})" | |
| if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) }} | |
| needs: style-python | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| inventree-tag: [latest, stable] | |
| container: | |
| image: inventree/inventree:${{ matrix.inventree-tag }} | |
| options: --user root | |
| env: | |
| INVENTREE_DB_ENGINE: postgresql | |
| INVENTREE_DB_NAME: inventree | |
| INVENTREE_DB_HOST: db | |
| INVENTREE_DB_PORT: 5432 | |
| INVENTREE_DB_USER: inventree | |
| INVENTREE_DB_PASSWORD: inventree | |
| INVENTREE_PLUGINS_ENABLED: True | |
| INVENTREE_PLUGINS_MANDATORY: inventree-bulk-plugin | |
| INVENTREE_PLUGIN_TESTING: True | |
| INVENTREE_PLUGIN_TESTING_SETUP: True | |
| INVENTREE_SITE_URL: http://localhost:8000 | |
| services: | |
| db: | |
| image: postgres:17 | |
| ports: | |
| - 5432:5432 | |
| env: | |
| POSTGRES_USER: inventree | |
| POSTGRES_PASSWORD: inventree | |
| POSTGRES_DB: inventree | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin@v4.2.2 | |
| - name: Setup inventree | |
| run: | | |
| cd /home/inventree | |
| HOME=/root invoke update | |
| - name: Setup inventree-bulk-plugin | |
| run: | | |
| cd /home/inventree | |
| # install additional dependencies required for testing | |
| # and newer coverage version due to https://github.com/nedbat/coveragepy/issues/1150 | |
| HOME=/root pip3 install django-test-migrations==1.2.0 coverage==7.4.1 django_slowtests==1.1.1 | |
| # install plugin and run migrations again | |
| HOME=/root pip3 install -e $GITHUB_WORKSPACE | |
| HOME=/root invoke migrate | |
| - name: Run tests | |
| run: | | |
| cd /home/inventree/src/backend | |
| HOME=/root coverage run --omit="InvenTree/**" InvenTree/manage.py test inventree_bulk_plugin.tests.integration | |
| echo $GITHUB_WORKSPACE > coverage_info | |
| - name: Upload coverage | |
| if: ${{ matrix.inventree-tag == 'latest' }} | |
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # pin@v4.6.2 | |
| with: | |
| name: integration-coverage | |
| include-hidden-files: true | |
| path: | | |
| /home/inventree/src/backend/.coverage | |
| /home/inventree/src/backend/coverage_info | |
| report: | |
| name: 📝 Report | |
| needs: [tests-unit-python, tests-integration-python] | |
| if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| pull-requests: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin@v4.2.2 | |
| - name: Setup python | |
| uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # pin@v5.6.0 | |
| with: | |
| python-version: 3.11 | |
| - name: Install test dependencies | |
| run: pip install coverage==7.0.1 | |
| - name: Download coverage | |
| uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # pin@v4.3.0 | |
| with: | |
| path: coverage | |
| - name: Prepare reports | |
| run: | | |
| echo "" >> .coveragerc | |
| echo "[paths]" >> .coveragerc | |
| echo "source =" >> .coveragerc | |
| echo " ." >> .coveragerc | |
| echo " $(cat coverage/unit-coverage/coverage_info)" >> .coveragerc | |
| echo " $(cat coverage/integration-coverage/coverage_info)" >> .coveragerc | |
| coverage combine coverage/integration-coverage/.coverage coverage/unit-coverage/.coverage | |
| coverage json | |
| coverage html | |
| coverage_percentage=$(jq -r ".totals.percent_covered" coverage.json | xargs printf "%.*f\n" "1") | |
| echo '## Coverage Report' > coverage.md | |
| echo "" >> coverage.md | |
| coverage report --format=markdown -m >> coverage.md | |
| - name: Upload full-coverage | |
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # pin@v4.6.2 | |
| with: | |
| name: coverage | |
| include-hidden-files: true | |
| path: | | |
| .coverage | |
| htmlcov | |
| - name: Get PR number | |
| uses: 8BitJonny/gh-get-current-pr@08e737c57a3a4eb24cec6487664b243b77eb5e36 # pin@v3.0.0 | |
| id: pr | |
| with: | |
| sha: ${{ github.event.pull_request.head.sha }} | |
| filterOutClosed: true | |
| - name: Add Coverage PR Comment | |
| uses: marocchino/sticky-pull-request-comment@67d0dec7b07ed060a405f9b2a64b8ab319fdd7db # pin@v2.9.2 | |
| if: success() && steps.pr.outputs.number | |
| with: | |
| number: ${{ steps.pr.outputs.number }} | |
| path: coverage.md | |
| - name: Write to Job Summary | |
| run: cat coverage.md >> $GITHUB_STEP_SUMMARY | |
| build-js: | |
| name: "🏗️ Build: js" | |
| needs: [style-js] | |
| if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin@v4.2.2 | |
| - name: Setup node | |
| uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # pin@v4.4.0 | |
| with: | |
| node-version: "23" | |
| - name: Install dependencies | |
| run: cd inventree_bulk_plugin/frontend && npm ci | |
| - name: Build js | |
| run: cd inventree_bulk_plugin/frontend && npm run build | |
| - name: Upload frontend artifact | |
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # pin@v4.6.2 | |
| with: | |
| include-hidden-files: true | |
| name: frontend | |
| path: inventree_bulk_plugin/static/dist | |
| publish: | |
| if: github.event_name == 'release' && github.event.action == 'published' | |
| needs: [report, build-js] | |
| name: 📦 Publish to PyPi | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: release | |
| url: https://pypi.org/p/inventree-bulk-plugin | |
| permissions: | |
| id-token: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin@v4.2.2 | |
| - name: Setup python | |
| uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # pin@v5.6.0 | |
| with: | |
| python-version: 3.11 | |
| - name: Install build dependencies | |
| run: pip install --upgrade wheel setuptools twine build | |
| - name: Download frontend artifact | |
| uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # pin@v4.3.0 | |
| with: | |
| name: frontend | |
| path: inventree_bulk_plugin/static/dist | |
| - name: Build pip package | |
| run: python3 -m build | |
| - name: Publish package to PyPI | |
| uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # pin@v1.12.4 |