-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathJenkinsfile-auto-deploy
88 lines (77 loc) · 2.61 KB
/
Jenkinsfile-auto-deploy
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
import groovy.json.JsonSlurperClassic
def authHeader = "-H 'Authorization: token ${GITHUB_TOKEN}'"
def contentTypeHeader = "-H 'Content-type: application/json'"
def issueUrl = "https://api.github.com/repos/Wikia/design-system/issues/${params.pull_num}"
def labels = "${params.labels}"
def githubPagesBranch = "gh-pages"
def publishPatchLabel = "publish-patch-on-merge"
def publishMinorLabel = "publish-minor-on-merge"
def publishMajorLabel = "publish-major-on-merge"
def deployDocsLabel = "deploy-docs-on-merge"
node('qa-executors') {
stage('Clone repo and validate') {
nodejs('v10 LTS') {
git credentialsId: 'bd3cf712-39a7-4b16-979e-ff86208ab2ea', url: '[email protected]:Wikia/design-system.git', branch: "master"
currentBuild.description = "Commit: ${params.commit}, PR: ${params.pull_num}"
withEnv(["ARTIFACTORY_NPM_TOKEN=${env.JENKINS_ARTIFACTORY_PASSWORD}"]) {
stage('Install dependencies') {
try {
sh 'yarn install'
} catch (e) {
error 'FAIL'
println e
}
}
stage('Run tests') {
try {
sh 'yarn test:jenkins'
} catch (e) {
error 'FAIL'
println e
}
}
if (currentBuild.currentResult.equals("SUCCESS")) {
sshagent(['bd3cf712-39a7-4b16-979e-ff86208ab2ea']) {
if (labels.contains(publishMajorLabel)) {
stage('Publish version: major') {
sh './scripts/release.sh major'
}
} else if (labels.contains(publishMinorLabel)) {
stage('Publish version: minor') {
sh './scripts/release.sh minor'
}
} else if (labels.contains(publishPatchLabel)) {
stage('Publish version: patch') {
sh './scripts/release.sh patch'
}
}
}
if (labels.contains(deployDocsLabel)) {
stage('Deploy documentation') {
sh 'yarn build:docs'
sh 'cp -R docs/ /tmp/docs'
sshagent(['bd3cf712-39a7-4b16-979e-ff86208ab2ea']) {
sh """
CURRENT_PACKAGE_VERSION=\$(egrep '"version": ".+"' package.json | cut -d '"' -f4)
git fetch origin ${githubPagesBranch}
git checkout ${githubPagesBranch}
git pull origin ${githubPagesBranch}
cp -R /tmp/docs/* ./docs/
rm -rf /tmp/docs
cp docs/CNAME ./CNAME
git add docs/ ./CNAME
if git diff --cached --exit-code --quiet; then
echo "No changes detected. Will not commit to ${githubPagesBranch}";
else
git commit -m "Documentation for \$CURRENT_PACKAGE_VERSION\nBased on ${params.pull_num} pull request and ${params.commit} commit"
git push origin ${githubPagesBranch}
fi
"""
}
}
}
}
}
}
}
}