-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
117 lines (114 loc) · 5.01 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// https://www.jenkins.io/doc/book/pipeline/docker/
pipeline {
agent {
docker { image 'piersfinlayson/openapi-gen-amd64:0.0.1' }
}
stages {
stage('Clone') {
steps {
withCredentials([usernamePassword(credentialsId: 'github.packom', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh '''
cd ~/builds && \
git clone https://packom:$PASSWORD@github.com/packom/pca9956b-api && \
cd pca9956b-api && \
echo `awk '/^version / {print $3;}' Cargo.toml | sed 's/"//g'` > /tmp/old_version && \
echo "Old version is:" && \
cat /tmp/old_version
'''
}
}
}
stage('Auto-gen') {
steps {
sh '''
cd ~/builds && \
java -jar ~/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate --generate-alias-as-model -i ./pca9956b-api/api/openapi.yaml -g rust-server -o ./pca9956b-api
cd pca9956b-api && \
echo `awk '/^version / {print $3;}' Cargo.toml | sed 's/"//g'` > /tmp/new_version && \
echo "New version is:" && \
cat /tmp/new_version && \
NEWV=$(cat /tmp/new_version) && \
echo "# pca9956b-api
pca9956b-api is an HTTP RESTful API designed to control a PCA9956B IC. This repo includes:
- An [API specification](https://github.com/packom/pca9956b-api/blob/master/api/openapi.yaml) in [OpenAPI format](https://github.com/OAI/OpenAPI-Specification/).
- Skeleton client and server implementations in [Rust](https://www.rust-lang.org/).
A fully-featured server implementation for Linux, in Rust, can be found at https://github.com/packom/pca9956b.
The text below was automatically generated by the openapi-generator.
" > /tmp/README.md && \
cat ./README.md >> /tmp/README.md && \
cp /tmp/README.md ./ && \
echo "[package]
name = \\"pca9956b-api\\"
version = \\"$NEWV\\"
authors = [\\"Piers Finlayson <piers@packom.net>\\"]
edition = \\"2018\\"
license = \\"GPL-3.0-or-later\\"
repository = \\"https://github.com/packom/pca9956b-api\\"
documentation = \\"https://github.com/packom/pca9956b-api\\"
homepage = \\"https://github.com/packom/pca9956b-api\\"
description = \\"HTTP RESTful API and skeleton server/client implement for I2C bus control\\"
readme = \\"README.md\\"
keywords = [\\"i2c\\",\\"bus\\",\\"openapi\\",\\"swagger\\",\\"http\\"]
categories = [\\"api-bindings\\",\\"hardware-support\\",\\"network-programming\\",\\"embedded\\",\\"web-programming\\"]
" > /tmp/Cargo.toml && \
tail -n +9 ./Cargo.toml >> /tmp/Cargo.toml && \
cp /tmp/Cargo.toml ./ && \
find examples -name *.rs -print0 | xargs -0 sed -i 's/openapi_client/pca9956b_api/' && \
git diff -- . ':(exclude)README.md' > /tmp/diff && \
cat /tmp/diff && \
echo `stat --printf="%s" /tmp/diff` > /tmp/diff_size && \
echo "Diff size is:" && \
cat /tmp/diff_size
'''
}
}
stage('Build') {
steps {
sh '''
cd ~/builds/pca9956b-api && \
cargo build
'''
}
}
stage('Test') {
steps {
sh '''
cd ~/builds/pca9956b-api && \
cargo test
'''
}
}
stage('Check in') {
steps {
sh '''
cd ~/builds/pca9956b-api && \
git config --global user.email "piers@packom.net" && \
git config --global user.name "Piers Finlayson" && \
git status && \
git diff && \
DIFF_SIZE=$(cat /tmp/diff_size) && \
if [ $DIFF_SIZE != 0 ] ; then git add -A && git commit -m "Checking in newly autogenerated version" && git push ; else echo "No changes to check in" ; fi
'''
}
}
stage('Publish') {
steps {
withCredentials([usernamePassword(credentialsId: 'crates.packom', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
// Note yank failure is OK because there'll be nothing to yank if we have a new version
sh '''
cd ~/builds/pca9956b-api && \
DIFF_SIZE=$(cat /tmp/diff_size) && \
OLDV=$(cat /tmp/old_version) && \
NEWV=$(cat /tmp/new_version) && \
if [ $DIFF_SIZE != 0 ]
then
cargo publish --token $PASSWORD
else
echo "No changes to publish"
fi
'''
}
}
}
}
}