forked from LaurentMazare/tch-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
91 lines (81 loc) · 3.79 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
node {
@Library("kenbun_pipeline")_
checkout scm
generalPipeline{
def product = 'kidou'
def name = 'tch-rs'
if (env.BRANCH_NAME == 'main') {
build_and_deploy()
} else {
build_and_lint()
}
}
}
// Sadly, this does not work with new packages
def latest_published_version(String pkg) {
sh(returnStdout: true, script: 'cargo search -q "' + pkg + '" --registry kenbun | sed \'s/' + pkg + ' = "\\(.*\\)".*/\\1/\'')
}
def current_version(String pkg) {
sh(returnStdout: true, script: 'cargo pkgid -p "' + pkg + '" | sed \'s/.*[@:#]\\(.*\\)/\\1/\'')
}
def version_changed(String pkg) {
latest_published_version(pkg) != current_version(pkg)
}
def publish_if_updated(String pkg) {
if (version_changed(pkg)) {
echo 'publishing new version of ' + pkg
if (pkg == "tch-rs") {
sh('cargo publish --registry=kenbun');
} else {
sh('cargo publish -p "' + pkg + '" --registry=kenbun')
}
} else {
echo 'Version of ' + pkg + ' did not change, not publishing...'
}
}
def build_and_deploy() {
stage("build and deploy") {
docker.withRegistry(env.nexusDockerRepo, 'nexus') {
def rustImage = docker.image('docker.kenbun.de/kenbun/rust-build-container-cpp:2.1.0-ubuntu22.04-rust1.70')
rustImage.pull()
withCredentials([string(credentialsId: 'meuse-api-key', variable: 'meuse_api_key')]) {
rustImage.withRun() { c ->
rustImage.inside("--env CARGO_REGISTRIES_KENBUN_TOKEN=${meuse_api_key} --env CARGO_REGISTRIES_KENBUN_INDEX=ssh://git@github.com/kenbunitag/rust-registry.git -v " + env.WORKSPACE.toString() + ":/io --network='host'") {
withCredentials([usernamePassword(credentialsId: 'nexus', usernameVariable: 'nexusUser', passwordVariable: 'nexusPassword')]) {
withCredentials([sshUserPrivateKey(credentialsId: 'github-ssh', keyFileVariable: 'ssh_identity', usernameVariable: 'ssh_username')]) {
withCredentials([file(credentialsId: 'github-ssh-password', variable: 'github_ssh_password')]) {
sshagent(credentials: ['github-ssh']) {
sh("./build.sh")
publish_if_updated('torch-sys')
publish_if_updated('tch')
}
}
}
}
}
}
}
}
}
}
def build_and_lint() {
stage("build and test") {
docker.withRegistry(env.nexusDockerRepo, 'nexus') {
def rustImage = docker.image('docker.kenbun.de/kenbun/rust-build-container-cpp:2.1.0-ubuntu22.04-rust1.70')
rustImage.pull()
withCredentials([string(credentialsId: 'meuse-api-key', variable: 'meuse_api_key')]) {
rustImage.withRun() { c ->
rustImage.inside("--env CARGO_REGISTRIES_KENBUN_TOKEN=${meuse_api_key} --env CARGO_REGISTRIES_KENBUN_INDEX=ssh://git@github.com/kenbunitag/rust-registry.git -v " + env.WORKSPACE.toString() + ":/io --network='host'") {
withCredentials([sshUserPrivateKey(credentialsId: 'github-ssh', keyFileVariable: 'ssh_identity', usernameVariable: 'ssh_username')]) {
withCredentials([file(credentialsId: 'github-ssh-password', variable: 'github_ssh_password')]) {
sshagent(credentials: ['github-ssh']) {
sh("./build.sh")
}
}
}
}
}
}
}
}
}