forked from openmobilityfoundation/mds-core
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Jenkinsfile
93 lines (77 loc) · 2.71 KB
/
Jenkinsfile
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
void setBuildStatus(String message, String state) {
step([
$class: "GitHubCommitStatusSetter",
reposSource: [$class: "ManuallyEnteredRepositorySource", url: "https://github.com/lacuna-tech/mds-core"],
contextSource: [$class: "ManuallyEnteredCommitContextSource", context: "ci/jenkins/build-status"],
errorHandlers: [[$class: "ChangingBuildStatusErrorHandler", result: "UNSTABLE"]],
statusResultSource: [ $class: "ConditionalStatusResultSource", results: [[$class: "AnyBuildResult", message: message, state: state]] ]
]);
}
def buildNumber = env.BUILD_NUMBER as int
if (buildNumber > 1) milestone(buildNumber - 1)
milestone(buildNumber)
pipeline {
agent any
options {
timeout(time: 1, unit: 'HOURS') // If build hangs for an hour, kill it with a 🔫
}
stages {
stage('Build') {
steps {
nvm('version': 'v16.14.2') {
sh '''
pnpm clean
pnpm lint
pnpm build
'''
}
}
}
stage('Test') {
environment {
NODE_OPTIONS = '--max_old_space_size=4096' // fixes nodejs out-of-memory errors such as "Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory"
}
steps {
nvm('version': 'v16.14.2') {
sh '''
# Fetch develop so we can only test the diff
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch origin
set -eu
set -o pipefail
randport() {
local port=$((($RANDOM%8000)+1024));
while nc -zv localhost $port > /dev/null 2>&1; do
port=$((($RANDOM%8000)+1024));
done;
echo $port
}
export PG_PORT=$(randport)
export REDIS_PORT=$(randport)
export PORT=$(randport)
export RPC_PORT=$(randport)
export REPL_PORT=$(randport)
source env.jenkins
export PG_ID=$(docker run -d -e POSTGRES_HOST_AUTH_METHOD=trust -p $PG_PORT:5432 postgres:11-alpine)
export REDIS_ID=$(docker run -d -p $REDIS_PORT:6379 redis:5-alpine)
function cleanup() {
docker stop $PG_ID && docker rm $PG_ID
docker stop $REDIS_ID && docker rm $REDIS_ID
}
trap cleanup EXIT
pnpm clean
PG_NAME=postgres PG_HOST=localhost PG_USER=postgres REDIS_HOST=localhost pnpm test -- --filter "...[origin/develop]"
'''
}
}
}
}
post {
success {
setBuildStatus('Build and tests succeeded! 🤓', 'SUCCESS')
}
failure {
setBuildStatus('Build or tests failed. 😢', 'FAILURE')
}
}
}