Skip to content

Commit ba19182

Browse files
authored
Merge pull request #149 from MycroftAI/feature/continuous-integration
Add continuous integration
2 parents 04053a5 + 735c4f9 commit ba19182

File tree

6 files changed

+176
-7
lines changed

6 files changed

+176
-7
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ __pycache__/
1717
*.net
1818
*.json
1919
*.pbtxt
20-
*.txt
2120
*.wav
2221

2322
# Data folders

Jenkinsfile

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
pipeline {
2+
agent any
3+
options {
4+
// Running builds concurrently could cause a race condition with
5+
// building the Docker image.
6+
disableConcurrentBuilds()
7+
buildDiscarder(logRotator(numToKeepStr: '5'))
8+
}
9+
environment {
10+
// Some branches have a "/" in their name (e.g. feature/new-and-cool)
11+
// Some commands, such as those tha deal with directories, don't
12+
// play nice with this naming convention. Define an alias for the
13+
// branch name that can be used in these scenarios.
14+
BRANCH_ALIAS = sh(
15+
script: 'echo $BRANCH_NAME | sed -e "s#/#-#g"',
16+
returnStdout: true
17+
).trim()
18+
//spawns GITHUB_USR and GITHUB_PSW environment variables
19+
GITHUB=credentials('38b2e4a6-167a-40b2-be6f-d69be42c8190')
20+
}
21+
stages {
22+
stage('Lint & Format') {
23+
// Run PyLint and Black to check code quality.
24+
when {
25+
changeRequest target: 'dev'
26+
}
27+
steps {
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}'
34+
}
35+
}
36+
stage('Run Tests') {
37+
// Run the unit and/or integration tests defined within the repository
38+
when {
39+
anyOf {
40+
branch 'dev'
41+
branch 'master'
42+
changeRequest target: 'dev'
43+
}
44+
}
45+
steps {
46+
echo 'Building Precise Testing Docker Image'
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} .'
52+
echo 'Precise Test Suite'
53+
timeout(time: 5, unit: 'MINUTES')
54+
{
55+
sh 'docker run \
56+
-v "$HOME/allure/precise/:/root/allure" \
57+
precise:${BRANCH_ALIAS}'
58+
}
59+
}
60+
}
61+
}
62+
post {
63+
cleanup {
64+
sh(
65+
label: 'Docker Container and Image Cleanup',
66+
script: '''
67+
docker container prune --force;
68+
docker image prune --force;
69+
'''
70+
)
71+
}
72+
failure {
73+
// Send failure email containing a link to the Jenkins build
74+
// the results report and the console log messages to Mycroft
75+
// developers, the developers of the pull request and the
76+
// developers that caused the build to fail.
77+
echo 'Sending Failure Email'
78+
emailext (
79+
subject: "FAILURE - Precise Build - ${BRANCH_NAME} #${BUILD_NUMBER}",
80+
body: """
81+
<p>
82+
Follow the link below to see details regarding
83+
the cause of the failure. Once a fix is pushed,
84+
this job will be re-run automatically.
85+
</p>
86+
<br>
87+
<p><a href='${BUILD_URL}'>Jenkins Build Details</a></p>
88+
<br>""",
89+
replyTo: 'devops@mycroft.ai',
90+
to: 'chris.veilleux@mycroft.ai',
91+
recipientProviders: [
92+
[$class: 'RequesterRecipientProvider'],
93+
[$class:'CulpritsRecipientProvider'],
94+
[$class:'DevelopersRecipientProvider']
95+
]
96+
)
97+
}
98+
success {
99+
// Send success email containing a link to the Jenkins build
100+
// and the results report to Mycroft developers, the developers
101+
// of the pull request and the developers that caused the
102+
// last failed build.
103+
echo 'Sending Success Email'
104+
emailext (
105+
subject: "SUCCESS - Precise Tests - Build ${BRANCH_NAME} #${BUILD_NUMBER}",
106+
body: """
107+
<p>
108+
Build completed without issue. No further action required.
109+
Build details can be found by following the link below.
110+
</p>
111+
<br>
112+
<p>
113+
<a href='${BUILD_URL}'>
114+
Jenkins Build Details
115+
</a>
116+
&nbsp(Requires account on Mycroft's Jenkins instance)
117+
</p>
118+
<br>""",
119+
replyTo: 'devops@mycroft.ai',
120+
to: 'chris.veilleux@mycroft.ai',
121+
recipientProviders: [
122+
[$class: 'RequesterRecipientProvider'],
123+
[$class:'CulpritsRecipientProvider'],
124+
[$class:'DevelopersRecipientProvider']
125+
]
126+
)
127+
}
128+
}
129+
}

pylintrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[MESSAGES CONTROL]
2+
disable=C0330

requirements/prod.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
numpy==1.16
2+
tensorflow>=1.13,<1.14 # Must be on piwheels
3+
sonopy
4+
pyaudio
5+
keras<=2.1.5
6+
h5py
7+
wavio
8+
typing
9+
prettyparse>=1.1.0
10+
precise-runner
11+
attrs
12+
fitipy<1.0
13+
speechpy-fast
14+
pyache

requirements/test.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pylint
2+
black
3+
pytest

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)