diff --git a/Jenkinsfile b/Jenkinsfile index 279b92f..50fe3c2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -15,33 +15,22 @@ pipeline { script: 'echo $BRANCH_NAME | sed -e "s#/#-#g"', returnStdout: true ).trim() + //spawns GITHUB_USR and GITHUB_PSW environment variables + GITHUB=credentials('38b2e4a6-167a-40b2-be6f-d69be42c8190') } stages { - stage('Build, Format & Lint') { - // Build a Docker image containing the Precise application and all - // prerequisites. Use git to determine the list of files changed. - // Filter the list of changed files into a list of Python modules. - // Pass the list of Python files changed into the Black code - // formatter. Build will fail if Black finds any changes to make. - // If Black check passes, run PyLint against the same set of Python - // modules. Build will fail if lint is found in code. + stage('Lint & Format') { + // Run PyLint and Black to check code quality. when { changeRequest target: 'dev' } steps { - sh 'docker build -f test/Dockerfile -t precise:${BRANCH_ALIAS} .' - sh 'git fetch origin dev' - sh 'git --no-pager diff --name-only FETCH_HEAD > $HOME/code-quality/change-set.txt' - sh 'docker run \ - -v $HOME/code-quality/:/root/code-quality \ - --entrypoint /bin/bash \ - precise:${BRANCH_ALIAS} \ - -x -c "grep -F .py /root/code-quality/change-set.txt | xargs black --check"' - sh 'docker run \ - -v $HOME/code-quality/:/root/code-quality \ - --entrypoint /bin/bash \ - precise:${BRANCH_ALIAS} \ - -x -c "grep -F .py /root/code-quality/change-set.txt | xargs pylint"' + sh 'docker build \ + --build-arg github_api_key=$GITHUB_PSW \ + --file test/Dockerfile \ + --target code-checker \ + -t precise:${BRANCH_ALIAS} .' + sh 'docker run precise:${BRANCH_ALIAS}' } } stage('Run Tests') { @@ -55,7 +44,11 @@ pipeline { } steps { echo 'Building Precise Testing Docker Image' - sh 'docker build -f test/Dockerfile -t precise:${BRANCH_ALIAS} .' + sh 'docker build \ + --build-arg github_api_key=$GITHUB_PSW \ + --file test/Dockerfile \ + --target test-runner \ + -t precise:${BRANCH_ALIAS} .' echo 'Precise Test Suite' timeout(time: 5, unit: 'MINUTES') { diff --git a/test/Dockerfile b/test/Dockerfile index fb3e000..5d9af2f 100644 --- a/test/Dockerfile +++ b/test/Dockerfile @@ -1,10 +1,32 @@ -FROM python:3.7-slim +# This dockerfile is for continuous integration of the mycroft-precise repostiory + +# Build an environment that can run the Precise wake word spotter. +FROM python:3.7-slim as precise-build ENV TERM linux ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && apt-get -y install git python3-scipy cython libhdf5-dev python3-h5py portaudio19-dev swig libpulse-dev libatlas-base-dev -ADD . mycroft-precise -WORKDIR mycroft-precise -RUN pip install . -RUN pip install pytest -ENV PYTHONPATH /mycroft-precise +RUN mkdir -p /root/allure /opt/mycroft/mycroft-precise /root/code-quality +WORKDIR /opt/mycroft +COPY requirements/test.txt mycroft-precise/requirements/ +RUN pip install -r mycroft-precise/requirements/test.txt +COPY requirements/prod.txt mycroft-precise/requirements/ +RUN pip install -r mycroft-precise/requirements/prod.txt +COPY . mycroft-precise + +# Clone the devops repository, which contiains helper scripts for some continuous +# integraion tasks. Run the code_check.py script which performs linting (using PyLint) +# and code formatting (using Black) +FROM precise-build as code-checker +ARG github_api_key +ENV GITHUB_API_KEY=$github_api_key +RUN pip install pipenv +RUN git clone https://$github_api_key@github.com/MycroftAI/devops.git +WORKDIR /opt/mycroft/devops/jenkins +RUN git checkout continuous_integration +RUN pipenv install +ENTRYPOINT ["pipenv", "run", "python","-m", "pipeline.code_check", "--repository", "mycroft-precise", "--pull-request", "PR-149"] + +# Run the tests defined in the precise repository +FROM precise-build as test-runner +WORKDIR /opt/mycroft/mycroft-precise ENTRYPOINT ["pytest"]