Skip to content

SW-4258 modify workflow #2

SW-4258 modify workflow

SW-4258 modify workflow #2

Workflow file for this run

name: Build
on:
workflow_call:
inputs:
python_v:
description: "Python version needed to run the code, eg. 3.10.6"
default: 3.10.6
required: false
type: string
source_dir:
description: "The source directory of the code, to be used by Sonar Scan"
required: false
type: string
exclude_from_coverage:
description: "Directories to be excluded from the test coverage report"
required: false
type: string
pylint_fail_under:
description: "The minimum pylint score for a build to succeed"
default: 0
required: false
type: number
env:
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
jobs:
# We need the latest release for alpha, beta and stable to define the new code for Sonarcloud
# If no previous release available, the overall code will be analyzed.
# (New code = code changes from the latest release)
latestRelease:
name: Get latest release
runs-on: ubuntu-20.04
continue-on-error: true
outputs:
latest_release: ${{ steps.latestRelease.outputs.tag }}
steps:
- name: Get latest alpha tag
if: github.ref == 'refs/heads/alpha' && github.event_name != 'pull_request'
uses: oprypin/find-latest-tag@v1
with:
repository: ${{ github.repository }}
releases-only: true
regex: 'v\d+\.\d+\.\d+a\d+$'
token: ${{ env.PERSONAL_ACCESS_TOKEN }}
id: latestAlphaTag
- name: Get latest beta tag
if: github.ref == 'refs/heads/beta' && github.event_name != 'pull_request'
uses: oprypin/find-latest-tag@v1
with:
repository: ${{ github.repository }}
releases-only: true
regex: 'v\d+\.\d+\.\d+b\d+$'
token: ${{ env.PERSONAL_ACCESS_TOKEN }}
id: latestBetaTag
- name: Get latest stable tag
if: github.ref == 'refs/heads/stable' && github.event_name != 'pull_request'
uses: oprypin/find-latest-tag@v1
with:
repository: ${{ github.repository }}
releases-only: true
regex: 'v\d+\.\d+\.\d+(.post\d+)?$'
token: ${{ env.PERSONAL_ACCESS_TOKEN }}
id: latestStableTag
- name: Select latest version for ${{ github.ref }}
run: |
if [ ${{ steps.latestAlphaTag.outputs.tag }} ]; then
echo 'tag=${{ steps.latestAlphaTag.outputs.tag }}' >> $GITHUB_OUTPUT
elif [ ${{ steps.latestBetaTag.outputs.tag }} ]; then
echo 'tag=${{ steps.latestBetaTag.outputs.tag }}' >> $GITHUB_OUTPUT
elif [ ${{ steps.latestStableTag.outputs.tag }} ]; then
echo 'tag=${{ steps.latestStableTag.outputs.tag }}' >> $GITHUB_OUTPUT
else
echo 'tag=' >> $GITHUB_OUTPUT
fi
id: latestRelease
- run: echo "New code defined since version ${{ steps.latestRelease.outputs.tag }} (only on push triggers)"
build:
name: Build
runs-on: ubuntu-20.04
needs: latestRelease
steps:
- name: New code definition
if: ${{ needs.latestRelease.outputs.latest_release }}
run: echo "${{ github.ref }} is at version ${{ needs.latestRelease.outputs.latest_release }}"
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up Python ${{ inputs.python_v }}
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python_v }}
- uses: actions/cache@v3 # Cache dependencies to speed up process
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint pytest pytest-cov pytest-html
if test -f "requirements-dev.txt"
then
pip install --force-reinstall -r requirements-dev.txt
fi
- name: Run pytest
id: pytest
run: |
pytest -v --cov --cov-report=xml --cov-report=html --junit-xml=xunit-result.xml --html=pytest-report.html
- name: Analysing the code with pylint
if: always()
run: |
if (( $(echo "${{ inputs.python_v }} < 3" |bc -l) )); then
pylint --ignore-patterns=tests/* **/*.py 2>&1 | tee pylint-report.log
else
set -o pipefail # This will use the exit code of the pylint command, and not the tee
pylint --ignore-patterns=tests/* --fail-under=${{ inputs.pylint_fail_under }} **/*.py 2>&1 | tee pylint-report.log
fi
- name: SonarCloud Scan
if: always()
uses: SonarSource/sonarcloud-github-action@master
with:
# qualitygate.wait=true: will fail the build if the quality gate is not met
# projectVersion: the version to which the code needs to be compared (will only apply on push, no PR)
args: >
-Dsonar.projectVersion=${{ needs.latestRelease.outputs.latest_release }}
-Dsonar.python.version=${{ inputs.python_v }}
-Dsonar.organization=${{ github.repository_owner }}
-Dsonar.projectKey=${{ github.repository_owner }}_${{ github.event.repository.name }}
-Dsonar.projectName=${{ github.event.repository.name }}
-Dsonar.sources=${{ inputs.source_dir }}
-Dsonar.tests=tests
-Dsonar.python.coverage.reportPaths=coverage*.xml
-Dsonar.python.xunit.reportPath=xunit-result*.xml
-Dsonar.dynamicAnalysis=reuseReports
-Dsonar.coverage.exclusions=${{ inputs.exclude_from_coverage }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- uses: actions/upload-artifact@v3
with:
name: pylint-report.log
path: ./pylint-report.log
- uses: actions/upload-artifact@v3
with:
name: code-coverage
path: htmlcov
- uses: actions/upload-artifact@v3
with:
name: pytest-report
path: pytest-report.html
format:
uses: format.yml

Check failure on line 157 in .github/workflows/build.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/build.yml

Invalid workflow file

invalid value workflow reference: no version specified