Skip to content

Commit 735c4f9

Browse files
chrisveilleuxforslund
authored andcommitted
Move lint and code format checks to devops repo
1 parent 803a283 commit 735c4f9

File tree

2 files changed

+43
-28
lines changed

2 files changed

+43
-28
lines changed

Jenkinsfile

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,22 @@ pipeline {
1515
script: 'echo $BRANCH_NAME | sed -e "s#/#-#g"',
1616
returnStdout: true
1717
).trim()
18+
//spawns GITHUB_USR and GITHUB_PSW environment variables
19+
GITHUB=credentials('38b2e4a6-167a-40b2-be6f-d69be42c8190')
1820
}
1921
stages {
20-
stage('Build, Format & Lint') {
21-
// Build a Docker image containing the Precise application and all
22-
// prerequisites. Use git to determine the list of files changed.
23-
// Filter the list of changed files into a list of Python modules.
24-
// Pass the list of Python files changed into the Black code
25-
// formatter. Build will fail if Black finds any changes to make.
26-
// If Black check passes, run PyLint against the same set of Python
27-
// modules. Build will fail if lint is found in code.
22+
stage('Lint & Format') {
23+
// Run PyLint and Black to check code quality.
2824
when {
2925
changeRequest target: 'dev'
3026
}
3127
steps {
32-
sh 'docker build -f test/Dockerfile -t precise:${BRANCH_ALIAS} .'
33-
sh 'git fetch origin dev'
34-
sh 'git --no-pager diff --name-only FETCH_HEAD > $HOME/code-quality/change-set.txt'
35-
sh 'docker run \
36-
-v $HOME/code-quality/:/root/code-quality \
37-
--entrypoint /bin/bash \
38-
precise:${BRANCH_ALIAS} \
39-
-x -c "grep -F .py /root/code-quality/change-set.txt | xargs black --check"'
40-
sh 'docker run \
41-
-v $HOME/code-quality/:/root/code-quality \
42-
--entrypoint /bin/bash \
43-
precise:${BRANCH_ALIAS} \
44-
-x -c "grep -F .py /root/code-quality/change-set.txt | xargs pylint"'
28+
sh 'docker build \
29+
--build-arg github_api_key=$GITHUB_PSW \
30+
--file test/Dockerfile \
31+
--target code-checker \
32+
-t precise:${BRANCH_ALIAS} .'
33+
sh 'docker run precise:${BRANCH_ALIAS}'
4534
}
4635
}
4736
stage('Run Tests') {
@@ -55,7 +44,11 @@ pipeline {
5544
}
5645
steps {
5746
echo 'Building Precise Testing Docker Image'
58-
sh 'docker build -f test/Dockerfile -t precise:${BRANCH_ALIAS} .'
47+
sh 'docker build \
48+
--build-arg github_api_key=$GITHUB_PSW \
49+
--file test/Dockerfile \
50+
--target test-runner \
51+
-t precise:${BRANCH_ALIAS} .'
5952
echo 'Precise Test Suite'
6053
timeout(time: 5, unit: 'MINUTES')
6154
{

test/Dockerfile

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
1-
FROM python:3.7-slim
1+
# This dockerfile is for continuous integration of the mycroft-precise repostiory
2+
3+
# Build an environment that can run the Precise wake word spotter.
4+
FROM python:3.7-slim as precise-build
25
ENV TERM linux
36
ENV DEBIAN_FRONTEND noninteractive
47
RUN apt-get update && apt-get -y install git python3-scipy cython libhdf5-dev python3-h5py portaudio19-dev swig libpulse-dev libatlas-base-dev
5-
ADD . mycroft-precise
6-
WORKDIR mycroft-precise
7-
RUN pip install .
8-
RUN pip install pytest
9-
ENV PYTHONPATH /mycroft-precise
8+
RUN mkdir -p /root/allure /opt/mycroft/mycroft-precise /root/code-quality
9+
WORKDIR /opt/mycroft
10+
COPY requirements/test.txt mycroft-precise/requirements/
11+
RUN pip install -r mycroft-precise/requirements/test.txt
12+
COPY requirements/prod.txt mycroft-precise/requirements/
13+
RUN pip install -r mycroft-precise/requirements/prod.txt
14+
COPY . mycroft-precise
15+
16+
# Clone the devops repository, which contiains helper scripts for some continuous
17+
# integraion tasks. Run the code_check.py script which performs linting (using PyLint)
18+
# and code formatting (using Black)
19+
FROM precise-build as code-checker
20+
ARG github_api_key
21+
ENV GITHUB_API_KEY=$github_api_key
22+
RUN pip install pipenv
23+
RUN git clone https://$github_api_key@github.com/MycroftAI/devops.git
24+
WORKDIR /opt/mycroft/devops/jenkins
25+
RUN git checkout continuous_integration
26+
RUN pipenv install
27+
ENTRYPOINT ["pipenv", "run", "python","-m", "pipeline.code_check", "--repository", "mycroft-precise", "--pull-request", "PR-149"]
28+
29+
# Run the tests defined in the precise repository
30+
FROM precise-build as test-runner
31+
WORKDIR /opt/mycroft/mycroft-precise
1032
ENTRYPOINT ["pytest"]

0 commit comments

Comments
 (0)