forked from coveo/plasma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TokensExtraction.groovy
125 lines (106 loc) · 3.74 KB
/
TokensExtraction.groovy
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
118
119
120
121
122
123
124
#!groovy
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import java.net.URLEncoder;
library(
identifier: "[email protected]",
retriever: modernSCM(github(credentialsId: "github-app-dev", repository: "jenkins-common-lib", repoOwner: "coveo")),
changelog: false
)
library(
identifier: "jsadmin_pipeline@master",
retriever: modernSCM(github(credentialsId: "github-app-dev", repository: "jsadmin_pipeline", repoOwner: "coveo")),
changelog: false
)
pipeline {
agent { label "build && docker && linux" }
parameters {
extendedChoice(
name: 'LIBRARIES',
description: 'Name of the Figma libraries to extract tokens from (leave all unchecked to extract them all)',
type: 'PT_CHECKBOX',
value: 'Icons Colors',
multiSelectDelimiter: ' ',
quoteValue: false,
saveJSONParameterToFile: false,
visibleItemCount: 50
)
}
environment {
NPM_TOKEN = credentials("npmjs_com_token")
GIT = credentials("github-commit-token")
GH_TOKEN = credentials("github-commit-token")
FIGMA_TOKEN = credentials("adminui-read-only-figma-token")
}
options {
ansiColor("xterm")
timestamps()
disableConcurrentBuilds()
timeout(time: 60, unit: 'MINUTES')
}
stages {
stage('Prepare') {
steps {
script {
sh "mkdir -p ${env.BRANCH_NAME}"
checkout([
$class: 'GitSCM',
branches: scm.branches,
extensions: scm.extensions + [[$class: "CleanCheckout"]] + [[$class: "LocalBranch", localBranch: "**"]] + [[$class: 'CloneOption', noTags: false, reference: '', shallow: false]],
userRemoteConfigs: [[credentialsId: "github-app-dev", url: "https://github.com/coveo/plasma.git"]]
])
sh "git config --global user.email \"[email protected]\""
sh "git config --global user.name \"Jenkins CI\""
sh "git remote set-url origin \"https://${env.GIT_USR}:${env.GIT_PSW}@github.com/coveo/plasma.git\""
def nodeHome = tool name: env.BUILD_NODE_VERSION, type: "nodejs"
env.PATH = "${nodeHome}/bin:${env.PATH}"
sh "npm config set //registry.npmjs.org/:_authToken=${env.NPM_TOKEN}"
sh "npm cache clean --force"
sh "rm -rf node_modules"
sh "npm install -g pnpm"
sh "pnpm install"
}
}
}
stage('Fetch tokens') {
steps {
script {
if (params.LIBRARIES.length() > 0) {
sh "pnpm run --filter @coveord/plasma-tokens tokens:fetch --libraries ${params.LIBRARIES}"
} else {
sh "pnpm run --filter @coveord/plasma-tokens tokens:fetch"
}
}
}
}
stage('Build tokens') {
steps {
script {
sh "pnpm run --filter @coveord/plasma-tokens tokens:build"
}
}
}
stage('Open pull request') {
steps {
script {
def prBranch = "design-token-extraction"
def prTitle = "Design tokens extraction"
def prbody = "This PR was created by the automatic design tokens extraction process, review with caution 🎁"
sh "git checkout -B ${prBranch}"
sh "git add ."
sh "git commit -m \"feat(tokens): extract design tokens from figma libraries\""
sh "git push -u -f origin ${prBranch}:${prBranch}"
withCredentials([usernamePassword(credentialsId: 'github-app-dev',
usernameVariable: 'GITHUB_APP',
passwordVariable: 'GITHUB_ACCESS_TOKEN')
]) {
runPackage.call(
"github-create-or-update-pr",
"--repo=plasma --head=${prBranch} --title=\"${prTitle}\" --body=\"${prbody}\""
)
}
}
}
}
}
}