Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jenkins #1

Draft
wants to merge 34 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c9216c9
First attempt at a build
jcustenborder Nov 9, 2023
f945020
Put in a steps block.
jcustenborder Nov 9, 2023
e560a41
First pass at manipulating the version.
jcustenborder Nov 9, 2023
a946e6c
Place script in a script block.
jcustenborder Nov 9, 2023
5eea1f3
Parse the version.
jcustenborder Nov 9, 2023
38fbb1f
Parse the version.
jcustenborder Nov 9, 2023
57bf44a
Change regex syntax.
jcustenborder Nov 9, 2023
7c731cd
Figuring out the regex syntax.
jcustenborder Nov 9, 2023
9032ca7
Figuring out the regex syntax.
jcustenborder Nov 9, 2023
c3a85eb
Figuring out the regex syntax.
jcustenborder Nov 9, 2023
12d431b
created stage to read the version.
jcustenborder Nov 9, 2023
fefa902
Added stages for generating version numbers in dev and production.
jcustenborder Nov 9, 2023
97309ae
Run on PR branches.
jcustenborder Nov 9, 2023
c3959fb
Added stage to configure npm. Disable progress and colors.
jcustenborder Nov 9, 2023
b25b883
Echo the current version.
jcustenborder Nov 9, 2023
23e158f
Pretty print the json.
jcustenborder Nov 9, 2023
b1284e5
Removed config calls.
jcustenborder Nov 9, 2023
a05b743
Output the the object type for version.
jcustenborder Nov 9, 2023
72faa71
Output the object type for version.
jcustenborder Nov 9, 2023
ed50366
Convert version to a string.
jcustenborder Nov 9, 2023
0b43a86
Added logic to update the dependencies.
jcustenborder Nov 9, 2023
545f826
Archive the version number.
jcustenborder Nov 9, 2023
5a1cf13
Corrected syntax.
jcustenborder Nov 9, 2023
393783d
Corrected syntax.
jcustenborder Nov 9, 2023
837710b
Corrected file path.
jcustenborder Nov 9, 2023
3bb32ea
Added call to archive artifacts.
jcustenborder Nov 9, 2023
f7782ab
Multiple package files need to be updated.
jcustenborder Nov 9, 2023
55f7b07
Ignore .idea and Jenkinsfile
jcustenborder Nov 9, 2023
5b2674c
Convert packageFile to a String.
jcustenborder Nov 9, 2023
3f49224
Update devDependencies as well.
jcustenborder Nov 9, 2023
03fddef
Try disabling at the container.
jcustenborder Nov 9, 2023
8c7a084
Added test and publish stages.
jcustenborder Nov 9, 2023
ed9271f
Remove color config.
jcustenborder Nov 9, 2023
95bd06c
Enable ansicolor.
jcustenborder Nov 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ swim-*/
tsconfig.json
tsdoc.json
typedoc.json
.idea/
Jenkinsfile
157 changes: 157 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
pipeline {
options {
timeout(time: 1, unit: 'HOURS')
ansiColor('xterm')
}
agent {
kubernetes {
cloud 'kubernetes'
inheritFrom 'default'
yaml '''
apiVersion: v1
kind: Pod
spec:
containers:
- name: node
image: node:20
command:
- cat
tty: true
'''
}
}

stages {
stage('read-version') {
steps {
script {
def packageContents = readJSON file: 'package.json'
originalVersion = packageContents['version']

def matcher = (originalVersion =~ /^(\d+)\.(\d+)\.(\d+)/)

if (!matcher) {
fail("Could not determine the version from ${originalVersion}")
}

//def means local variable. Removing means global.
version_major = Integer.parseInt(matcher[0][1])
version_minor = Integer.parseInt(matcher[0][2])
version_revision = Integer.parseInt(matcher[0][3])

echo "Version read ${version_major}.${version_minor}.${version_revision}"
}
}
}

stage('generate-version-dev') {
when {
anyOf {
branch pattern: "^\\d+.\\d+.\\d+", comparator: "REGEXP";
branch pattern: "PR-\\d+", comparator: "REGEXP"
}
}
steps {
script {
def now = new Date()
def timestamp = now.format("yyMMddHHmmss", TimeZone.getTimeZone('UTC'))
version = "${version_major}.${version_minor}.${version_revision}-dev.${timestamp}" as String // Whoever came up with Groovy strings is an ass.
echo "Setting version to '${version}'"
}
}
}

stage('generate-version-prod') {
when {
branch 'main';
}
steps {
script {
version = ""
}
}
}

stage('modify-version') {
when {
anyOf {
branch 'main';
branch pattern: "^\\d+.\\d+.\\d+", comparator: "REGEXP";
branch pattern: "PR-\\d+", comparator: "REGEXP"
}
}
steps {
script {
def packageFiles = findFiles glob: '**/package.json'
packageFiles.each { packageFile ->
def packageContents = readJSON file: "${packageFile}"
packageContents.version = version as String

def dependencies = packageContents['dependencies']
def dependencyUpdates = [:]

dependencies.each { entry ->
if (entry.value == originalVersion) {
dependencyUpdates.put(entry.key, version)
}
}

if (dependencyUpdates) {
dependencies.putAll(dependencyUpdates)
}

def devDependencies = packageContents['devDependencies']
def devDependencyUpdates = [:]

devDependencies.each { entry ->
if (entry.value == originalVersion) {
devDependencyUpdates.put(entry.key, version)
}
}

if (devDependencyUpdates) {
devDependencies.putAll(devDependencyUpdates)
}


writeJSON file: "${packageFile}", json: packageContents, pretty: 4
archiveArtifacts artifacts: "${packageFile}"
}

writeFile file: 'version.txt', text: version
archiveArtifacts artifacts: 'version.txt'
}
}
}

stage('build') {
steps {
container('node') {
sh 'npm install'
sh 'npm run bootstrap'
sh 'npx swim-build'
archiveArtifacts artifacts: "swim-core/**/dist/**/*.*"
archiveArtifacts artifacts: "swim-host/**/dist/**/*.*"
archiveArtifacts artifacts: "dist/**/*.*"
}
}
}

stage('test') {
steps {
container('node') {
sh 'npx swim-build test'
}
}
}

stage('publish') {
steps {
container('node') {
sh 'npx swim-build publish'
}
}
}
}
}

2 changes: 2 additions & 0 deletions swim-core/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ swim-*/
tsconfig.json
tsdoc.json
typedoc.json
.idea/
Jenkinsfile
2 changes: 2 additions & 0 deletions swim-host/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ swim-*/
tsconfig.json
tsdoc.json
typedoc.json
.idea/
Jenkinsfile