-
Notifications
You must be signed in to change notification settings - Fork 2
174 lines (146 loc) · 6.03 KB
/
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
name: CI - Test Runner
# Run the workflow when commits are pushed on main or when a PR is modified
# Version 1.1 modified by Romain Hirschi
on:
push:
branches:
- main
pull_request:
types:
- opened
- synchronize
- reopened
jobs:
ci:
name: CI
# Execute the CI on the course's runners
runs-on: ubuntu-latest
steps:
# First step : Checkout the repository on the runner
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of Sonar analysis (if we use Sonar Later)
# This step removes the current gradle cache to avoid any caching issues
- name: Remove current gradle cache
run: rm -rf ~/.gradle
# Kernel-based Virtual Machine (KVM) is an open source virtualization technology built into Linux. Enabling it allows the Android emulator to run faster.
- name: Enable KVM group perms
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: "17"
# Caching is a very useful part of a CI, as a workflow is executed in a clean environment every time,
# this means that one would need to re-download and re-process gradle files for every run. Which is very time consuming.
#
# To avoid that, we cache the the gradle folder to reuse it later.
- name: Gradle cache
uses: gradle/actions/setup-gradle@v3
# Cache the Emulator, if the cache does not hit, create the emulator
- name: AVD cache
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-34
- name: create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 34
target: google_apis
arch: x86_64
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
script: echo "Generated AVD snapshot for caching."
# Load google-services.json and local.properties from the secrets
- name: Decode secrets
env:
GOOGLE_SERVICES: ${{ secrets.GOOGLE_SERVICES }}
LOCAL_PROPERTIES: ${{ secrets.LOCAL_PROPERTIES }}
run: |
echo "$GOOGLE_SERVICES" | base64 --decode > ./app/google-services.json
echo "$LOCAL_PROPERTIES" | base64 --decode > ./local.properties
# Grant execute permission for gradlew
- name: Grant execute permission for gradlew
run: |
chmod +x ./gradlew
# Install the firebase emulator suite
- name: Install Firebase Emulator Suite
run: npm install -g firebase-tools
# Install dependencies for the firebase emulator suite
- name: Install dependencies for the firebase emulator suite
run: npm install
# Navigate to the `functions` directory, install dependencies, then return to root
- name: Install dependencies for the Firebase Emulator Suite
run: |
cd functions
npm install
cd ..
# Check formatting
- name: KTFmt Check
run: |
./gradlew ktfmtCheck
# Create .env file to hold secret credentials
- name: Create functions/.env.unio-1b8ee file
run: |
echo "FUNCTIONS_COMPANY_EMAIL=${{ secrets.FUNCTIONS_COMPANY_EMAIL }}" > functions/.env.unio-1b8ee
echo "FUNCTIONS_COMPANY_PASSWORD=${{ secrets.FUNCTIONS_COMPANY_PASSWORD }}" >> functions/.env.unio-1b8ee
# Run
# waiting for Arnaud's PR, temporarily commenting this
#- name: Run Node tests with Firestore and Storage emulators
# run: firebase emulators:exec --only firestore,storage 'npm run test'
# This step runs gradle commands to build the application
- name: Assemble
run: |
# To run the CI with debug information, add --info
./gradlew assemble lint --parallel --build-cache
# Run Unit tests
- name: Run tests
run: |
# To run the CI with debug information, add --info
./gradlew check --parallel --build-cache
# Run connected tests on the emulator
- name: Run connected tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 34
target: google_apis
arch: x86_64
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
script: firebase emulators:exec --import=firebase/emulator-data './gradlew connectedCheck --parallel --build-cache'
# Upload the test results to the artifacts
- name: Upload Test Results
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: test-results
path: app/build/reports/androidTests/connected/debug/
retention-days: 1
# This step generates the coverage report which will be uploaded to sonar
- name: Generate Coverage Report
run: |
./gradlew jacocoTestReport
# Upload the coverage report to the artifacts
- name: Upload Jacoco Test Report
uses: actions/upload-artifact@v4
with:
name: jacocoTestReport
path: build/reports/jacoco/jacocoTestReport/
# Upload the various reports to sonar
- name: Upload report to SonarCloud
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew sonar --parallel --build-cache