Move lint and code format checks to devops repo
parent
803a283e09
commit
735c4f9109
|
@ -15,33 +15,22 @@ pipeline {
|
||||||
script: 'echo $BRANCH_NAME | sed -e "s#/#-#g"',
|
script: 'echo $BRANCH_NAME | sed -e "s#/#-#g"',
|
||||||
returnStdout: true
|
returnStdout: true
|
||||||
).trim()
|
).trim()
|
||||||
|
//spawns GITHUB_USR and GITHUB_PSW environment variables
|
||||||
|
GITHUB=credentials('38b2e4a6-167a-40b2-be6f-d69be42c8190')
|
||||||
}
|
}
|
||||||
stages {
|
stages {
|
||||||
stage('Build, Format & Lint') {
|
stage('Lint & Format') {
|
||||||
// Build a Docker image containing the Precise application and all
|
// Run PyLint and Black to check code quality.
|
||||||
// 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.
|
|
||||||
when {
|
when {
|
||||||
changeRequest target: 'dev'
|
changeRequest target: 'dev'
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
sh 'docker build -f test/Dockerfile -t precise:${BRANCH_ALIAS} .'
|
sh 'docker build \
|
||||||
sh 'git fetch origin dev'
|
--build-arg github_api_key=$GITHUB_PSW \
|
||||||
sh 'git --no-pager diff --name-only FETCH_HEAD > $HOME/code-quality/change-set.txt'
|
--file test/Dockerfile \
|
||||||
sh 'docker run \
|
--target code-checker \
|
||||||
-v $HOME/code-quality/:/root/code-quality \
|
-t precise:${BRANCH_ALIAS} .'
|
||||||
--entrypoint /bin/bash \
|
sh 'docker run precise:${BRANCH_ALIAS}'
|
||||||
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"'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Run Tests') {
|
stage('Run Tests') {
|
||||||
|
@ -55,7 +44,11 @@ pipeline {
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
echo 'Building Precise Testing Docker Image'
|
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'
|
echo 'Precise Test Suite'
|
||||||
timeout(time: 5, unit: 'MINUTES')
|
timeout(time: 5, unit: 'MINUTES')
|
||||||
{
|
{
|
||||||
|
|
|
@ -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 TERM linux
|
||||||
ENV DEBIAN_FRONTEND noninteractive
|
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
|
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
|
RUN mkdir -p /root/allure /opt/mycroft/mycroft-precise /root/code-quality
|
||||||
WORKDIR mycroft-precise
|
WORKDIR /opt/mycroft
|
||||||
RUN pip install .
|
COPY requirements/test.txt mycroft-precise/requirements/
|
||||||
RUN pip install pytest
|
RUN pip install -r mycroft-precise/requirements/test.txt
|
||||||
ENV PYTHONPATH /mycroft-precise
|
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"]
|
ENTRYPOINT ["pytest"]
|
||||||
|
|
Loading…
Reference in New Issue