-
Notifications
You must be signed in to change notification settings - Fork 7
/
.gitlab-ci.yml
220 lines (200 loc) · 9.93 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# This file is a template, and might need editing before it works on your project.
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Android.gitlab-ci.yml
# Read more about this script on this blog post https://about.gitlab.com/2018/10/24/setting-up-gitlab-ci-for-android-projects/, by Jason Lenny
# If you are interested in using Android with FastLane for publishing take a look at the Android-Fastlane template.
image: openjdk:8-jdk
stages:
- build
- test
- visualize
include:
- template: Code-Quality.gitlab-ci.yml
variables:
# ANDROID_COMPILE_SDK is the version of Android you're compiling with.
# It should match compileSdkVersion.
ANDROID_COMPILE_SDK: "25"
# ANDROID_BUILD_TOOLS is the version of the Android build tools you are using.
# It should match buildToolsVersion.
ANDROID_BUILD_TOOLS: "25.0.3"
# It's what version of the command line tools we're going to download from the official site.
# Official Site-> https://developer.android.com/studio/index.html
# There, look down below at the cli tools only, sdk tools package is of format:
# commandlinetools-os_type-ANDROID_SDK_TOOLS_latest.zip
# when the script was last modified for latest compileSdkVersion, it was which is written down below
ANDROID_SDK_TOOLS: "6514223"
# Packages installation before running script
before_script:
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1 automake patch libtool pkg-config help2man gengetopt build-essential libpcsclite-dev
# Setup path as android_home for moving/exporting the downloaded sdk into it
- export ANDROID_HOME="${PWD}/android-home"
# Create a new directory at specified location
- install -d $ANDROID_HOME
# Here we are installing androidSDK tools from official source,
# (the key thing here is the url from where you are downloading these sdk tool for command line, so please do note this url pattern there and here as well)
# after that unzipping those tools and
# then running a series of SDK manager commands to install necessary android SDK packages that'll allow the app to build
- wget --output-document=$ANDROID_HOME/cmdline-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}_latest.zip
# move to the archive at ANDROID_HOME
- pushd $ANDROID_HOME
- unzip -d cmdline-tools cmdline-tools.zip
- popd
- export PATH=$PATH:${ANDROID_HOME}/cmdline-tools/tools/bin/
# Nothing fancy here, just checking sdkManager version
- sdkmanager --version
# use yes to accept all licenses
- yes | sdkmanager --sdk_root=${ANDROID_HOME} --licenses || true
- sdkmanager --sdk_root=${ANDROID_HOME} "platforms;android-${ANDROID_COMPILE_SDK}"
- sdkmanager --sdk_root=${ANDROID_HOME} "platform-tools"
- sdkmanager --sdk_root=${ANDROID_HOME} "build-tools;${ANDROID_BUILD_TOOLS}"
# Not necessary, but just for surity
- chmod +x ./android-projects/Virtual_Keycard/gradlew
.build_android_dependencies: &build_android_dependencies
# Build npa-emulator
- git submodule init
- git submodule update
- cd android-projects/npa-emulator/
- ./gradlew uploadArchives
- cd -
# Build Muscle Card on Android
- cd android-projects/Muscle_Card_on_Android
- ./gradlew --debug uploadArchives
- cd -
# Basic android and gradle stuff
# Check linting
lintDebug:
interruptible: true
stage: build
script:
- *build_android_dependencies
- cd android-projects/Virtual_Keycard/
- ./gradlew -Pci --console=plain :app:lintDebug -PbuildDir=lint
# Make Project
assembleDebug:
interruptible: true
stage: build
script:
- *build_android_dependencies
- cd android-projects/Virtual_Keycard/
- ./gradlew assembleDebug
artifacts:
paths:
- ./android-projects/Virtual_Keycard/app/build/outputs/
# Build OpenSC with virtualkeycard driver
buildOpenScDriver:
interruptible: true
stage: build
script:
- export PREFIX=$PWD
- git submodule update --init --recursive
# Build OpenPACE
- cd openpace/
- sed -i 's/\$(GIT) clone --depth=10 git:\/\/openssl\.net\/openssl -b OpenSSL_1_0_2-stable \$(OPENSSL_DIR)/\$(GIT) clone --depth=100 git:\/\/git.openssl.org\/openssl\.git -b OpenSSL_1_0_2-stable \$(OPENSSL_DIR)/g' src/Makefile.am
- autoreconf --verbose --install
- ./configure --enable-openssl-install --prefix=$PREFIX
- cd src/
- make install-openssl
- cd -
- make install
- cd ../
# Build OpenSC
- cd vsmartcard
- cd npa/src/opensc
- git checkout d72324ddf58f594a00c6b56b6abb8c4937b0794e
- autoreconf --verbose --install
- export LD_LIBRARY_PATH=$PREFIX/lib:$PREFIX/lib64
- ./configure --prefix=$PREFIX PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig:$PREFIX/lib64/pkgconfig --enable-sm
- export C_INCLUDE_PATH=$PREFIX/include
- make install
- cd -
- cd ..
# Build libnpa
- cd vsmartcard/npa
- autoreconf --verbose --install
- ./configure --prefix=$PREFIX PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig:$PREFIX/lib64/pkgconfig OPENSC_LIBS="-L$PREFIX/lib -L$PREFIX/lib64 -lopensc -lcrypto"
- make install
- cd -
# Build virtualkeycard driver
- cp opensc-files/card-virtualkeycard.c vsmartcard/npa/src/opensc/src/libopensc/
- cp opensc-files/pkcs15-virtualkeycard.c vsmartcard/npa/src/opensc/src/pkcs15init/
- cp opensc-files/virtualkeycard.profile $PREFIX/share/opensc/
# Build driver "virtualkeycard":
- cd vsmartcard/npa/src/opensc/src/libopensc/
- gcc -DHAVE_CONFIG_H -I . -I ../.. -DOPENSC_CONF_PATH=\"$PREFIX/etc/opensc/opensc.conf\" -I ../../src -I$PREFIX/include -pthread -I/usr/include/PCSC -fno-strict-aliasing -g -O2 -Wall -Wextra -Wno-unused-parameter -Werror=declaration-after-statement -MT card-virtualkeycard.lo -MD -MP -MF .deps/card-virtualkeycard.Tpo -c card-virtualkeycard.c -fPIC -DPIC -o .libs/card-virtualkeycard.o
- gcc -shared -fPIC -DPIC -o .libs/card-virtualkeycard.so .libs/muscle.o .libs/muscle-filesystem.o .libs/card.o .libs/sc.o .libs/card-virtualkeycard.o -Wl,-rpath -Wl,$PREFIX/lib -Wl,-rpath -Wl,$PREFIX/lib64 -L$PREFIX/lib/ -L$PREFIX/lib64/ -lnpa -lcrypto -lopensc
- cd -
# Build PKCS15-driver for virtualkeycard:
- cd vsmartcard/npa/src/opensc/src/pkcs15init/
- gcc -DHAVE_CONFIG_H -I . -I ../.. -DSC_PKCS15_PROFILE_DIRECTORY=\"$PREFIX/share/opensc/\" -I ../../src -I$PREFIX/include -fno-strict-aliasing -g -O2 -Wall -Wextra -Wno-unused-parameter -Werror=declaration-after-statement -MT pkcs15-virtualkeycard.lo -MD -MP -MF .deps/pkcs15-virtualkeycard.Tpo -c pkcs15-virtualkeycard.c -fPIC -DPIC -o .libs/pkcs15-virtualkeycard.o
- gcc -shared -fPIC -DPIC -o .libs/pkcs15-virtualkeycard.so .libs/pkcs15-virtualkeycard.o .libs/profile.o ../common/compat_strlcpy.o
- cd -
# Expand path in patch
# Choosing other delimiters, %, for sed, so we do not have to mask the slashes in $(PREFIX)
- sed -i 's%$$PREFIX%$PREFIX%g' opensc-files/opensc.conf.patch
- cd $PREFIX/etc/
- patch < ../opensc-files/opensc.conf.patch
- cd -
artifacts:
paths:
- vsmartcard/npa/src/opensc/src/libopensc/.libs/card-virtualkeycard.so
- vsmartcard/npa/src/opensc/src/pkcs15init/.libs/pkcs15-virtualkeycard.so
# Run all tests, if any fails, interrupt the pipeline(fail it)
debugTests:
interruptible: true
stage: test
script:
- git submodule init android-projects/npa-emulator/
- git submodule update android-projects/npa-emulator/
- cd android-projects/npa-emulator/
- ./gradlew uploadArchives
- cd -
- cd android-projects/Muscle_Card_on_Android
- ./gradlew --debug uploadArchives
- cd -
- cd android-projects/Muscle_Card_on_Android
- ./gradlew -Pci --console=plain :app:testDebugUnitTest :app:testDebugUnitTestCoverage
- cd -
- cd android-projects/Virtual_Keycard/
- ./gradlew -Pci --console=plain :app:testDebugUnitTest :app:testDebugUnitTestCoverage
artifacts:
paths:
- android-projects/Virtual_Keycard/app/build/reports/jacoco/testDebugUnitTestCoverage/
- android-projects/Muscle_Card_on_Android/app/build/reports/jacoco/testDebugUnitTestCoverage/
code_quality:
before_script:
- ''
stage: test
variables:
REPORT_FORMAT: html
artifacts:
paths: [gl-code-quality-report.html]
debugCoverage:
before_script:
- apk update
- apk add npm
- npm install -g --unsafe-perm cobertura-merge
- apk add py3-pip
- pip install pycobertura
# Must be in a stage later than test stage.
# The `visualize` stage does not exist by default.
# Please define it first, or chose an existing stage like `deploy`.
stage: visualize
image: registry.gitlab.com/haynes/jacoco2cobertura:1.0.7
script:
# convert report from jacoco to cobertura, using relative project path
- python /opt/cover2cover.py android-projects/Virtual_Keycard/app/build/reports/jacoco/testDebugUnitTestCoverage/testDebugUnitTestCoverage.xml android-projects/Virtual_Keycard/app/src/main/java/ > android-projects/Virtual_Keycard/app/build/cobertura.xml
- python /opt/cover2cover.py android-projects/Muscle_Card_on_Android/app/build/reports/jacoco/testDebugUnitTestCoverage/testDebugUnitTestCoverage.xml android-projects/Muscle_Card_on_Android/app/src/main/java/ > android-projects/Muscle_Card_on_Android/app/build/cobertura.xml
# merge the two reports
- cobertura-merge -o cobertura-android.xml package1=android-projects/Virtual_Keycard/app/build/cobertura.xml package2=android-projects/Muscle_Card_on_Android/app/build/cobertura.xml
# show total coverage of Virtual_Keycard for coverage badge
- pycobertura show android-projects/Virtual_Keycard/app/build/cobertura.xml | grep TOTAL
needs: ["debugTests"]
artifacts:
reports:
cobertura: cobertura-android.xml
paths:
- android-projects/Virtual_Keycard/app/build/cobertura.xml
- android-projects/Muscle_Card_on_Android/app/build/cobertura.xml