Skip to content

Commit d8e72a4

Browse files
authored
feat: run unit tests and build for Python 3.11 as well (#165)
* feat: run unit tests for Python 3.11 as well * feat: run build with Python 3.11 as well
1 parent 749caef commit d8e72a4

File tree

1 file changed

+128
-3
lines changed

1 file changed

+128
-3
lines changed

.github/workflows/reusable-build-test-release.yml

Lines changed: 128 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,55 @@ jobs:
396396
checks: write
397397
steps:
398398
- uses: actions/checkout@v3
399-
- name: Setup python
400-
uses: actions/setup-python@v4
399+
- uses: actions/setup-python@v4
400+
with:
401+
python-version: ${{ matrix.python-version }}
402+
- name: Setup addon
403+
run: |
404+
if [ -f "poetry.lock" ]
405+
then
406+
mkdir -p package/lib || true
407+
pip install poetry==1.2.2 poetry-plugin-export==1.2.0
408+
poetry export --without-hashes -o package/lib/requirements.txt
409+
poetry export --without-hashes --dev -o requirements_dev.txt
410+
fi
411+
if [ ! -f requirements_dev.txt ]; then echo no requirements;exit 0 ;fi
412+
pip install -r requirements_dev.txt
413+
- name: Create directories
414+
run: |
415+
mkdir -p /opt/splunk/var/log/splunk
416+
chmod -R 777 /opt/splunk/var/log/splunk
417+
- name: Copy pytest ini
418+
run: cp tests/unit/pytest-ci.ini pytest.ini
419+
- name: Run Pytest with coverage
420+
run: pytest --cov=./ --cov-report=xml --junitxml=test-results/junit.xml tests/unit
421+
- uses: actions/upload-artifact@v3
422+
if: success() || failure()
423+
with:
424+
name: test-results-unit-python_${{ matrix.python-version }}
425+
path: test-results/*
426+
427+
run-unit-tests-311:
428+
name: test-unit-python3-${{ matrix.python-version }}
429+
if: ${{ needs.test-inventory.outputs.unit == 'true' }}
430+
runs-on: ubuntu-latest
431+
needs:
432+
- test-inventory
433+
strategy:
434+
fail-fast: false
435+
matrix:
436+
python-version:
437+
- "3.11"
438+
permissions:
439+
actions: read
440+
deployments: read
441+
contents: read
442+
packages: read
443+
statuses: read
444+
checks: write
445+
steps:
446+
- uses: actions/checkout@v3
447+
- uses: actions/setup-python@v4
401448
with:
402449
python-version: ${{ matrix.python-version }}
403450
- name: Setup addon
@@ -426,7 +473,6 @@ jobs:
426473
path: test-results/*
427474

428475
build:
429-
name: build
430476
runs-on: ubuntu-latest
431477
needs:
432478
- setup-workflow
@@ -559,6 +605,85 @@ jobs:
559605
path: build/package/deployment**
560606
if: always()
561607

608+
build-311:
609+
runs-on: ubuntu-latest
610+
needs:
611+
- setup-workflow
612+
- test-inventory
613+
- meta
614+
- compliance-copyrights
615+
- lint
616+
- review_secrets
617+
- semgrep
618+
- run-unit-tests-311
619+
- fossa-scan
620+
if: |
621+
always() &&
622+
(needs.run-unit-tests-311.result == 'success' || needs.run-unit-tests-311.result == 'skipped')
623+
permissions:
624+
contents: write
625+
packages: read
626+
steps:
627+
- uses: actions/checkout@v3
628+
with:
629+
# Very Important semantic-release won't trigger a tagged
630+
# build if this is not set false
631+
persist-credentials: false
632+
- name: Setup python
633+
uses: actions/setup-python@v4
634+
with:
635+
python-version: 3.11
636+
- name: create requirements file for pip
637+
run: |
638+
if [ -f "poetry.lock" ]
639+
then
640+
echo " poetry.lock found "
641+
sudo pip3 install poetry==1.2.2 poetry-plugin-export==1.2.0
642+
poetry export --without-hashes -o requirements.txt
643+
if [ "$(grep -cve '^\s*$' requirements.txt)" -ne 0 ]
644+
then
645+
echo "Prod dependencies were found, creating package/lib folder"
646+
mkdir -p package/lib || true
647+
mv requirements.txt package/lib
648+
else
649+
echo "No prod dependencies were found"
650+
rm requirements.txt
651+
fi
652+
poetry export --without-hashes --dev -o requirements_dev.txt
653+
cat requirements_dev.txt
654+
fi
655+
- id: pip-cache
656+
run: |
657+
echo "dir=$(pip cache dir)" >> "$GITHUB_OUTPUT"
658+
- name: pip cache
659+
uses: actions/cache@v3
660+
with:
661+
path: ${{ steps.pip-cache.outputs.dir }}
662+
key: ${{ runner.os }}-pip-python311-${{ hashFiles('requirements_dev.txt') }}
663+
restore-keys: |
664+
${{ runner.os }}-pip-python311
665+
- run: pip install -r requirements_dev.txt
666+
- id: semantic
667+
if: github.event_name != 'pull_request'
668+
uses: splunk/[email protected]
669+
with:
670+
dry_run: true
671+
git_committer_name: ${{ secrets.SA_GH_USER_NAME }}
672+
git_committer_email: ${{ secrets.SA_GH_USER_EMAIL }}
673+
gpg_private_key: ${{ secrets.SA_GPG_PRIVATE_KEY }}
674+
passphrase: ${{ secrets.SA_GPG_PASSPHRASE }}
675+
env:
676+
GITHUB_TOKEN: ${{ github.token }}
677+
- id: BuildVersion
678+
uses: splunk/addonfactory-get-splunk-package-version-action@v1
679+
with:
680+
SemVer: ${{ steps.semantic.outputs.new_release_version }}
681+
PrNumber: ${{ github.event.number }}
682+
- id: uccgen
683+
uses: splunk/addonfactory-ucc-generator-action@v1
684+
with:
685+
version: ${{ steps.BuildVersion.outputs.VERSION }}
686+
562687
security-virustotal:
563688
continue-on-error: true
564689
name: security-virustotal

0 commit comments

Comments
 (0)