Skip to content

Commit ef496c1

Browse files
Merge pull request #18 from Neko-Box-Coder/Jenkins
Adding Jenkins CI
2 parents 63131ae + c809b21 commit ef496c1

File tree

10 files changed

+373
-25
lines changed

10 files changed

+373
-25
lines changed

Build.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pushd Build || goto :error
88

99
cmake .. || goto :error
1010
cmake --build . --target Embed2C || goto :error
11-
cmake .. || goto :error
11+
cmake .. %* || goto :error
1212
cmake --build . -j 16 || goto :error
1313

1414
popd

Build.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
set -e
33

44
mkdir -p ./Build
55
pushd ./Build
6+
67
cmake ..
78
cmake --build . --target Embed2C
8-
cmake ..
9+
cmake .. "$@"
910
cmake --build . -j 16
1011

1112
popd

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ target_include_directories(runcpp2 PRIVATE "${CMAKE_CURRENT_LIST_DIR}/Include")
105105
target_link_libraries(runcpp2 PRIVATE ssLogger ghc_filesystem System2 ryml::ryml dylib CppOverride)
106106

107107
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
108-
set(STANDARD_COMPILE_FLAGS "/utf-8;/W1")
108+
set(STANDARD_COMPILE_FLAGS "/utf-8;/W1;/DGHC_WIN_DISABLE_WSTRING_STORAGE_TYPE=1")
109109
else()
110110
set(STANDARD_COMPILE_FLAGS "-Wall"
111111
"-Wno-return-local-addr"

Include/runcpp2/BuildsManager.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace runcpp2
2929
bool Initialized;
3030

3131
bool ParseMappings(const std::string& mappingsContent);
32+
std::string ProcessPath(const std::string& path);
3233

3334
public:
3435
BuildsManager(const ghc::filesystem::path& configDirectory);

Include/runcpp2/Data/ProfilesCompilesFiles.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
#define RUNCPP2_DATA_PROFILES_COMPILES_FILES_HPP
33

44
#include "runcpp2/Data/ParseCommon.hpp"
5+
6+
#define NOMINMAX 1
57
#include "ghc/filesystem.hpp"
8+
69
#include "ryml.hpp"
710
#include <unordered_map>
811

Jenkinsfile

Lines changed: 314 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,314 @@
1+
def bash(command, returnOutput=false)
2+
{
3+
return sh(script: """#!/bin/bash
4+
${command}
5+
""",
6+
returnStdout: returnOutput)
7+
}
8+
9+
def SetGithubStatus(githubToken, context, targetUrl, desc, status, repoOwner, repoName, gitHash)
10+
{
11+
bash """
12+
curl -L --fail-with-body \\
13+
-X POST \\
14+
-H "Accept: application/vnd.github+json" \\
15+
-H "Authorization: Bearer ${githubToken}" \\
16+
-H "X-GitHub-Api-Version: 2022-11-28" \\
17+
-d '{
18+
"context": "${context}",
19+
"target_url": "${targetUrl}",
20+
"description": "${desc}",
21+
"state": "${status}"
22+
}' \\
23+
https://api.github.com/repos/${repoOwner}/${repoName}/statuses/${gitHash}
24+
"""
25+
}
26+
27+
def REPO_OWNER = "Neko-Box-Coder"
28+
def REPO_NAME = "runcpp2"
29+
def TARGET_URL = 'https://github.com/Neko-Box-Coder/runcpp2.git'
30+
def STATUS_CONTEXT_URL = "https://ci.nekoboxcoder.dev/job/runcpp2/${BUILD_NUMBER}/pipeline-graph/"
31+
def FAILED_STAGE = "None"
32+
def TARGET_REF = "refs/heads/master"
33+
def STORE_BUILD = false
34+
35+
pipeline
36+
{
37+
agent none
38+
options { skipDefaultCheckout() }
39+
/*
40+
External Variables for webhook payload:
41+
42+
Webhook:
43+
GITHUB_PUSH_REF: $.ref
44+
GITHUB_PR_ACTION: $.action
45+
GITHUB_PR_GIT_URL: $.pull_request.head.repo.clone_url
46+
GITHUB_PR_REF: $.pull_request.head.ref
47+
GITHUB_PR_REPO_OWNER: $.pull_request.user.login
48+
GITHUB_PR_REPO_NAME: $.pull_request.head.repo.name
49+
X-GitHub-Event: (Header)
50+
51+
Trigger:
52+
$GITHUB_PUSH_REF , $GITHUB_PR_REF , $GITHUB_PR_ACTION
53+
^refs/heads/master , , $|^ , .[a-zA-Z/]* , (opened|synchronize)$
54+
55+
Param:
56+
TARGET_REF
57+
STORE_BUILD
58+
*/
59+
stages
60+
{
61+
stage('Setup')
62+
{
63+
agent none
64+
steps
65+
{
66+
script
67+
{
68+
echo "env.TARGET_REF: ${env.TARGET_REF}"
69+
echo "env.STORE_BUILD: ${env.STORE_BUILD}"
70+
71+
if(env.TARGET_REF != null)
72+
TARGET_REF = env.TARGET_REF
73+
74+
if(env.STORE_BUILD != null)
75+
STORE_BUILD = env.STORE_BUILD.toBoolean()
76+
77+
echo "Displaying Webhook Variables:"
78+
echo "GITHUB_PUSH_REF: ${env.GITHUB_PUSH_REF}"
79+
echo "GITHUB_PR_ACTION: ${env.GITHUB_PR_ACTION}"
80+
echo "GITHUB_PR_GIT_URL: ${env.GITHUB_PR_GIT_URL}"
81+
echo "GITHUB_PR_REF: ${env.GITHUB_PR_REF}"
82+
echo "GITHUB_PR_REPO_OWNER: ${env.GITHUB_PR_REPO_OWNER}"
83+
echo "GITHUB_PR_REPO_NAME: ${env.GITHUB_PR_REPO_NAME}"
84+
echo "X_GitHub_Event: ${env.X_GitHub_Event}"
85+
86+
//Trigger pipeline on push to master
87+
if(env.X_GitHub_Event == 'push')
88+
{
89+
if(env.GITHUB_PUSH_REF != 'refs/heads/master')
90+
error('Receiving non master push')
91+
}
92+
//Trigger pipeline with approval on PR
93+
else if(env.X_GitHub_Event == 'pull_request')
94+
{
95+
if(env.GITHUB_PR_ACTION != 'synchronize' && env.GITHUB_PR_ACTION != 'opened')
96+
error('Receiving non relevant PR action')
97+
else
98+
{
99+
timeout(time: 30, unit: 'MINUTES')
100+
{
101+
input 'Approval this job?'
102+
}
103+
}
104+
105+
TARGET_REF = env.GITHUB_PR_REF
106+
TARGET_URL = env.GITHUB_PR_GIT_URL
107+
REPO_OWNER = env.GITHUB_PR_REPO_OWNER
108+
REPO_NAME = env.GITHUB_PR_REPO_NAME
109+
}
110+
//Invalid github event
111+
else if(env.X_GitHub_Event != null)
112+
error("Invalid github event: ${env.X_GitHub_Event}")
113+
114+
echo "TARGET_REF: ${TARGET_REF}"
115+
echo "env.TARGET_REF: ${env.TARGET_REF}"
116+
echo "TARGET_URL: ${TARGET_URL}"
117+
echo "REPO_OWNER: ${REPO_OWNER}"
118+
echo "REPO_NAME: ${REPO_NAME}"
119+
echo "STATUS_CONTEXT_URL: ${STATUS_CONTEXT_URL}"
120+
echo "STORE_BUILD: ${STORE_BUILD}"
121+
}
122+
}
123+
}
124+
125+
stage('Checkout')
126+
{
127+
agent { label 'linux' }
128+
steps
129+
{
130+
cleanWs()
131+
script
132+
{
133+
checkout(
134+
[
135+
$class: 'GitSCM',
136+
branches: [[name: TARGET_REF]],
137+
doGenerateSubmoduleConfigurations: true,
138+
extensions: scm.extensions +
139+
[[
140+
$class: 'SubmoduleOption',
141+
parentCredentials: true,
142+
recursiveSubmodules: true
143+
]],
144+
userRemoteConfigs: [[url: TARGET_URL]]
145+
]
146+
)
147+
148+
GIT_HASH = bash("echo \$(git rev-parse --verify HEAD)", true)
149+
echo "GITHASH: ${GIT_HASH}"
150+
151+
if(!STORE_BUILD)
152+
{
153+
withCredentials([string(credentialsId: 'github-token',
154+
variable: 'GITHUB_TOKEN')])
155+
{
156+
SetGithubStatus('$GITHUB_TOKEN',
157+
"Build ${BUILD_NUMBER}",
158+
STATUS_CONTEXT_URL,
159+
"Stage ${env.STAGE_NAME} started",
160+
"pending",
161+
REPO_OWNER,
162+
REPO_NAME,
163+
GIT_HASH)
164+
}
165+
}
166+
167+
stash 'source'
168+
}
169+
}
170+
post { failure { script { FAILED_STAGE = env.STAGE_NAME } } }
171+
}
172+
173+
stage('Build')
174+
{
175+
parallel
176+
{
177+
stage('Linux Build')
178+
{
179+
agent { label 'linux' }
180+
steps
181+
{
182+
cleanWs()
183+
bash "ls -lah"
184+
unstash 'source'
185+
bash "ls -lah"
186+
bash('chmod +x ./Build.sh')
187+
bash './Build.sh -DRUNCPP2_BUILD_TESTS=ON'
188+
stash 'linux_build'
189+
}
190+
post { failure { script { FAILED_STAGE = env.STAGE_NAME } } }
191+
}
192+
stage('Windows Build')
193+
{
194+
agent { label 'windows' }
195+
steps
196+
{
197+
cleanWs()
198+
bat 'dir'
199+
unstash 'source'
200+
bat 'dir'
201+
bat 'Build.bat -DRUNCPP2_BUILD_TESTS=ON'
202+
stash 'windows_build'
203+
}
204+
post { failure { script { FAILED_STAGE = env.STAGE_NAME } } }
205+
}
206+
}
207+
208+
//NOTE: We use Debug builds for now even for release.
209+
}
210+
211+
stage('Test')
212+
{
213+
parallel
214+
{
215+
stage('Linux Test')
216+
{
217+
agent { label 'linux' }
218+
steps
219+
{
220+
cleanWs()
221+
bash "ls -lah"
222+
unstash 'linux_build'
223+
bash "ls -lah"
224+
bash './Build/BuildsManagerTest'
225+
}
226+
post { failure { script { FAILED_STAGE = env.STAGE_NAME } } }
227+
}
228+
stage('Windows Test')
229+
{
230+
agent { label 'windows' }
231+
steps
232+
{
233+
cleanWs()
234+
bat 'dir'
235+
unstash 'windows_build'
236+
bat 'dir'
237+
bat '.\\Build\\Debug\\BuildsManagerTest.exe'
238+
}
239+
post { failure { script { FAILED_STAGE = env.STAGE_NAME } } }
240+
}
241+
}
242+
}
243+
244+
stage('Notify')
245+
{
246+
agent { label 'linux' }
247+
when { expression { STORE_BUILD == false } }
248+
steps
249+
{
250+
cleanWs()
251+
withCredentials([string(credentialsId: 'github-token', variable: 'GITHUB_TOKEN')])
252+
{
253+
SetGithubStatus('$GITHUB_TOKEN',
254+
"Build ${BUILD_NUMBER}",
255+
STATUS_CONTEXT_URL,
256+
"Pipeline passed",
257+
"success",
258+
REPO_OWNER,
259+
REPO_NAME,
260+
GIT_HASH)
261+
}
262+
}
263+
}
264+
265+
stage('Release')
266+
{
267+
agent { label 'linux' }
268+
when { expression { STORE_BUILD == true } }
269+
steps
270+
{
271+
cleanWs()
272+
dir('WindowsBuild') { unstash 'windows_build' }
273+
dir('LinuxBuild') { unstash 'linux_build' }
274+
275+
archiveArtifacts artifacts: 'LinuxBuild/Build/runcpp2',
276+
defaultExcludes: false,
277+
fingerprint: true,
278+
onlyIfSuccessful: true
279+
280+
archiveArtifacts artifacts: 'WindowsBuild/Build/Debug/runcpp2.exe',
281+
defaultExcludes: false,
282+
fingerprint: true,
283+
onlyIfSuccessful: true
284+
}
285+
}
286+
} //stages
287+
288+
post
289+
{
290+
failure
291+
{
292+
node('linux')
293+
{
294+
script
295+
{
296+
if(!STORE_BUILD)
297+
{
298+
withCredentials([string(credentialsId: 'github-token', variable: 'GITHUB_TOKEN')])
299+
{
300+
SetGithubStatus('$GITHUB_TOKEN',
301+
"Build ${BUILD_NUMBER}",
302+
STATUS_CONTEXT_URL,
303+
"Stage ${FAILED_STAGE} failed",
304+
"failure",
305+
REPO_OWNER,
306+
REPO_NAME,
307+
GIT_HASH)
308+
}
309+
}
310+
}
311+
}
312+
}
313+
}
314+
} //pipeline

0 commit comments

Comments
 (0)