Skip to content

Commit 2044709

Browse files
v1vMpdreamz
andauthored
ci: enable CI release automation (#88)
Co-authored-by: Martijn Laarman <[email protected]>
1 parent c0ad2bd commit 2044709

File tree

5 files changed

+101
-26
lines changed

5 files changed

+101
-26
lines changed

.ci/Jenkinsfile

Lines changed: 85 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ pipeline {
3131
steps {
3232
pipelineManager([ cancelPreviousRunningBuilds: [ when: 'PR' ] ])
3333
deleteDir()
34-
gitCheckout(basedir: "${BASE_DIR}", githubNotifyFirstTimeContributor: true)
34+
gitCheckout(basedir: "${BASE_DIR}", githubNotifyFirstTimeContributor: true, shallow: false)
35+
dir("${BASE_DIR}"){
36+
sh(label: 'Fetch tags', script: 'git fetch --prune --tags')
37+
}
3538
stash allowEmpty: true, name: 'source', useDefaultExcludes: false
3639
}
3740
}
@@ -50,6 +53,10 @@ pipeline {
5053
}
5154
}
5255
stage('Parallel'){
56+
when {
57+
not { buildingTag() }
58+
beforeAgent true
59+
}
5360
parallel {
5461
stage('Linux') {
5562
options { skipDefaultCheckout() }
@@ -61,7 +68,6 @@ pipeline {
6168
deleteDir()
6269
unstash 'source'
6370
dir("${BASE_DIR}"){
64-
sh script: 'git fetch --prune --tags', label: 'build'
6571
dotnet(){
6672
sh script: './build.sh release -c false', label: 'build'
6773
}
@@ -73,7 +79,10 @@ pipeline {
7379
archiveArtifacts(allowEmptyArchive: true, artifacts: "${MSBUILDDEBUGPATH}/**/MSBuild_*.failure.txt")
7480
}
7581
always {
76-
junit(allowEmptyResults: true, keepLongStdio: true, testResults: "${BASE_DIR}/build/output/junit-*.xml")
82+
dir("${BASE_DIR}"){
83+
junit(allowEmptyResults: true, keepLongStdio: true, testResults: 'build/output/junit-*.xml')
84+
archiveArtifacts(allowEmptyArchive: true, artifacts: 'build/output/**/*')
85+
}
7786
}
7887
}
7988
}
@@ -92,8 +101,7 @@ pipeline {
92101
withGithubNotify(context: 'Windows') {
93102
unstash 'source'
94103
dir("${BASE_DIR}"){
95-
bat script: 'git fetch --prune --tags', label: 'build'
96-
bat script: 'choco install dotnetcore-sdk -m -y --no-progress -r --version 3.1.200', label: 'Tools'
104+
bat script: 'choco install dotnetcore-sdk -m -y --no-progress -r --version 3.1.202', label: 'Tools'
97105
bat script: 'build.bat release -c false', label: 'build'
98106
}
99107
}
@@ -102,25 +110,70 @@ pipeline {
102110
unsuccessful {
103111
archiveArtifacts(allowEmptyArchive: true, artifacts: "${MSBUILDDEBUGPATH}/**/MSBuild_*.failure.txt")
104112
}
113+
always {
114+
dir("${BASE_DIR}"){
115+
junit(allowEmptyResults: true, keepLongStdio: true, testResults: 'build/output/junit-*.xml')
116+
archiveArtifacts(allowEmptyArchive: true, artifacts: 'build/output/**/*')
117+
}
118+
}
105119
}
106120
}
107-
stage('Deploy') {
108-
when {
109-
branch 'master'
110-
}
111-
steps {
112-
dir("${BASE_DIR}"){
113-
release('secret/apm-team/ci/elastic-observability-appveyor')
114-
}
121+
}
122+
}
123+
}
124+
}
125+
stage('Release') {
126+
when {
127+
beforeAgent true
128+
anyOf {
129+
tag pattern: '\\d+\\.\\d+\\.\\d+(-(alpha|beta|rc)\\d*)?', comparator: 'REGEXP'
130+
branch 'master'
131+
}
132+
}
133+
stages {
134+
stage('Generate') {
135+
steps {
136+
deleteDir()
137+
unstash 'source'
138+
dir("${BASE_DIR}"){
139+
dotnet() {
140+
sh(label: 'Generate local nuget packages', script: './build.sh generatepackages -s true')
141+
sh(label: 'Validate *.npkg files that were created', script: './build.sh validatepackages -s true')
142+
sh(label: 'Inspect public API change', script: './build.sh generateapichanges -s true')
115143
}
116-
post {
117-
always {
118-
archiveArtifacts(allowEmptyArchive: true, artifacts: "${BASE_DIR}/**/build/output/*.nupkg")
144+
}
145+
}
146+
}
147+
stage('Release to feedz.io') {
148+
when { branch 'master' }
149+
steps {
150+
dir("${BASE_DIR}"){
151+
deploy(secret: 'secret/apm-team/ci/elastic-observability-feedz.io')
152+
}
153+
}
154+
}
155+
stage('Release Notes') {
156+
when { buildingTag() }
157+
steps {
158+
dir("${BASE_DIR}"){
159+
withGitRelease(credentialsId: '2a9602aa-ab9f-4e52-baf3-b71ca88469c7-UserAndToken') {
160+
dotnet() {
161+
sh(label: 'Generate release notes', script: './build.sh generatereleasenotes -s true')
162+
sh(label: 'Inspect public API change', script: './build.sh generateapichanges -s true')
163+
sh(label: 'Create or update release for tag on github', script: "./build.sh createreleaseongithub -s true --token ${GITHUB_TOKEN}")
119164
}
120165
}
121166
}
122167
}
123168
}
169+
stage('Release to NuGet') {
170+
when { buildingTag() }
171+
steps {
172+
dir("${BASE_DIR}"){
173+
//deploy(secret: 'secret/apm-team/ci/elastic-observability-nuget')
174+
}
175+
}
176+
}
124177
}
125178
}
126179
}
@@ -133,15 +186,27 @@ pipeline {
133186

134187
def dotnet(Closure body){
135188
def dockerTagName = 'docker.elastic.co/observability-ci/ecs-dotnet-sdk-linux:latest'
136-
sh label: 'Docker build', script: "docker build --tag ${dockerTagName} .ci/docker/sdk-linux"
189+
// When running in the CI with multiple parallel stages
190+
// the access could be considered as a DDOS attack.
191+
retryWithSleep(retries: 2, seconds: 5, backoff: true) {
192+
sh label: 'Docker build', script: "docker build --tag ${dockerTagName} .ci/docker/sdk-linux"
193+
}
137194
docker.image("${dockerTagName}").inside("-e HOME='${env.WORKSPACE}/${env.BASE_DIR}'"){
138195
body()
139196
}
140197
}
141198

142-
def release(secret){
199+
def deploy(Map args = [:]) {
200+
def secret = args.secret
143201
def repo = getVaultSecret(secret: secret)
144-
withEnvMask(vars: [[var: 'REPO_API_KEY', password: repo.data.apiKey], [var: 'REPO_API_URL', password: repo.data.url]]){
145-
bat(label: 'Deploy', script: ".ci/deploy.bat ${REPO_API_KEY} ${REPO_API_URL}")
202+
withEnvMask(vars: [ [var: 'REPO_API_KEY', password: repo.data.apiKey],
203+
[var: 'REPO_API_URL', password: repo.data.url] ]) {
204+
if (isUnix()) {
205+
dotnet(){
206+
sh(label: 'Deploy', script: ".ci/deploy.sh ${REPO_API_KEY} ${REPO_API_URL}")
207+
}
208+
} else {
209+
bat(label: 'Deploy', script: ".ci/deploy.bat ${REPO_API_KEY} ${REPO_API_URL}")
210+
}
146211
}
147212
}

.ci/deploy.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
#
3+
# This script deploys to nuget given the API key and URL
4+
#
5+
set -euo pipefail
6+
7+
while IFS= read -r -d '' nupkg
8+
do
9+
echo "dotnet nuget push ${nupkg}"
10+
dotnet nuget push "${nupkg}" -k "${1}" -s "${2}"
11+
done < <(find . -type f -not -path './build/output/*' -name '*.nupkg' -print0)

.ci/docker/sdk-linux/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
FROM mcr.microsoft.com/dotnet/core/sdk:3.1
1+
FROM mcr.microsoft.com/dotnet/core/sdk:3.1.202

.ci/jobs/defaults.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@
4141
after: true
4242
before: true
4343
prune: true
44-
shallow-clone: true
45-
depth: 3
44+
shallow-clone: false
4645
do-not-fetch-tags: true
4746
submodule:
4847
disable: false

build/scripts/Targets.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ let private validatePackages (arguments:ParseResults<Arguments>) =
5757
Paths.Output.GetFiles("*.nupkg") |> Seq.sortByDescending(fun f -> f.CreationTimeUtc)
5858
|> Seq.map (fun p -> Paths.RootRelative p.FullName)
5959

60-
let appVeyorArgs =
61-
if Fake.Core.Environment.environVarAsBool "APPVEYOR" then ["-r"; "true"] else []
60+
let jenkinsOnWindowsArgs =
61+
if Fake.Core.Environment.hasEnvironVar "JENKINS_URL" && Fake.Core.Environment.isWindows then ["-r"; "true"] else []
6262

63-
let args = ["-v"; currentVersionInformational.Value; "-k"; Paths.SignKey; "-t"; output] @ appVeyorArgs
63+
let args = ["-v"; currentVersionInformational.Value; "-k"; Paths.SignKey; "-t"; output] @ jenkinsOnWindowsArgs
6464
nugetPackages |> Seq.iter (fun p -> exec "dotnet" (["nupkg-validator"; p] @ args) |> ignore)
6565

6666

0 commit comments

Comments
 (0)