Skip to content

Commit

Permalink
Add initial support for validating GoCD pipeline file syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilsbhat committed May 6, 2023
1 parent c0582d6 commit 2fb9958
Show file tree
Hide file tree
Showing 13 changed files with 860 additions and 18 deletions.
11 changes: 5 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ require (
github.com/go-resty/resty/v2 v2.7.0
github.com/imdario/mergo v0.3.13
github.com/jinzhu/copier v0.3.5
github.com/sirupsen/logrus v1.6.0
github.com/stretchr/testify v1.8.0
github.com/sirupsen/logrus v1.9.0
github.com/stretchr/testify v1.8.2
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
28 changes: 16 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,37 @@ github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
github.com/jinzhu/copier v0.3.5 h1:GlvfUwHk62RokgqVNvYsku0TATCF7bAHVwEXoBh3iJg=
github.com/jinzhu/copier v0.3.5/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
50 changes: 50 additions & 0 deletions internal/fixtures/sample-pipeline-defect.gocd.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package artifacts_and_html_reports

import cd.go.contrib.plugins.configrepo.groovy.dsl.GoCD

GoCD.script {
pipeline {
pipeline('website') {
group = "example-group"

trackingTool {
link = 'https://github.com/gocd/api.go.cd/issues/${ID}'
regex = ~/##(\\d+)/
}

materials {
git {
url = 'https://github.com/gocd/api.go.cd'
branch = 'release-18.1.0'
}
}
stages {
stage('build-website') {
jobs {
job('build') {
tasks {
bash {
commandString = 'bundle install --path .bundle -j4'
}
bash {
commandString = 'bundle exec rake build'
}
}

artifacts {
build {
source = 'build/18.1.0'
destination = 'website'
}
}

tabs {
tab('website') { path = 'website/18.1.0/index.html' }
}
}
}
}
}
}
}
}
61 changes: 61 additions & 0 deletions internal/fixtures/sample-pipeline-defect.gocd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"format_version": 9,
"label_template": "${COUNT}",
"enable_pipeline_locking": false,
"name": "my_pipeline",
"group": "configrepo-example",
"tracking_tool": null,
"timer": null,
"environment_variables": [],
"materials": [
{
"type": "git",
"url": "https://github.com/NikAraga/gocd-pipeline-sample-json.git",
"destination": "code",
"filter": {
"ignore": [
"**/*.*",
"**/*.html"
]
},
"name": "git",
"auto_update": true,
"branch": "master",
"submodule_folder": null
}
],
"stages": [
{
"name": "my_stage_1",
"fetch_materials": true,
"clean_working_directory": false,
"never_cleanup_artifacts": false,
"approval": null,
"environment_variables": [],
"jobs": [
{
"name": "my_job_1",
"run_instance_count": null,
"timeout": 0,
"environment_variables": [],
"tasks": [
{
"type": "exec",
"run_if": "passed",
"on_cancel": {
"type": "exec",
"command": "ls",
"working_directory": null
},
"command": "echo",
"arguments": [
"Hello From GOCD pipeline"
],
"working_directory": null
}
],
"properties": null
}
]
}
}
60 changes: 60 additions & 0 deletions internal/fixtures/sample-pipeline-defect.gocd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#ci.gocd.yaml
format_version: 9
environments:
testing:
environment_variables:
DEPLOYMENT: testing
secure_variables:
ENV_PASSWORD: "s&Du#@$xsSa"
pipelines:
- example-deploy-testing
- build-testing
pipelines:
mypipe1: # definition of mypipe1 pipeline
group: mygroup # note that the group name can contain only of alphanumeric & underscore characters
display_order: 10
label_template: "${mygit[:8]}"
lock_behavior: none
parameters: # list of parameters that can be configured for a pipeline
param1: value1
materials:
mygit: # this is the name of material, the name can contain only of alphanumeric & underscore characters
# keyword git says about type of material and url at once
git: http://my.example.org/mygit.git
branch: ci
myupstream: # this name does not matter, but there should be no 2 materials with the same name
# type is optional here, material type is implied based on presence of pipeline and stage fields
# type: dependency
pipeline: pipe2
stage: test
stages: # list of stages in order
- build: # name of stage
clean_workspace: true
jobs:
csharp: # name of the job
resources:
- net45
artifacts:
- build:
source: bin/
destination: build
- test:
source: tests/
destination: test-reports/
- test:
source: coverage.xml
tabs:
report: test-reports/index.html
tasks: # ordered list of tasks to execute in job csharp
fetch:
pipeline: pipe2
stage: build
job: test
source: test-bin/
destination: bin/
- exec: # indicates type of task
command: make
arguments:
- "VERBOSE=true"
# shorthand for script-executor plugin
- script: ./build.sh ci
50 changes: 50 additions & 0 deletions internal/fixtures/sample-pipeline.gocd.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package artifacts_and_html_reports

import cd.go.contrib.plugins.configrepo.groovy.dsl.GoCD

GoCD.script {
pipelines {
pipeline('website') {
group = "example-group"

trackingTool {
link = 'https://github.com/gocd/api.go.cd/issues/${ID}'
regex = ~/##(\\d+)/
}

materials {
git {
url = 'https://github.com/gocd/api.go.cd'
branch = 'release-18.1.0'
}
}
stages {
stage('build-website') {
jobs {
job('build') {
tasks {
bash {
commandString = 'bundle install --path .bundle -j4'
}
bash {
commandString = 'bundle exec rake build'
}
}

artifacts {
build {
source = 'build/18.1.0'
destination = 'website'
}
}

tabs {
tab('website') { path = 'website/18.1.0/index.html' }
}
}
}
}
}
}
}
}
62 changes: 62 additions & 0 deletions internal/fixtures/sample-pipeline.gocd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"format_version" : 9,
"label_template": "${COUNT}",
"enable_pipeline_locking": false,
"name": "my_pipeline",
"group" : "configrepo-example",
"tracking_tool": null,
"timer": null,
"environment_variables": [],
"materials": [
{
"type": "git",
"url": "https://github.com/NikAraga/gocd-pipeline-sample-json.git",
"destination": "code",
"filter": {
"ignore": [
"**/*.*",
"**/*.html"
]
},
"name": "git",
"auto_update": true,
"branch": "master",
"submodule_folder": null
}
],
"stages": [
{
"name": "my_stage_1",
"fetch_materials": true,
"clean_working_directory": false,
"never_cleanup_artifacts": false,
"approval": null,
"environment_variables": [],
"jobs": [
{
"name": "my_job_1",
"run_instance_count": null,
"timeout": 0,
"environment_variables": [],
"tasks": [
{
"type": "exec",
"run_if": "passed",
"on_cancel": {
"type": "exec",
"command": "ls",
"working_directory": null
},
"command": "echo",
"arguments": [
"Hello From GOCD pipeline"
],
"working_directory": null
}
],
"properties": null
}
]
}
]
}
1 change: 1 addition & 0 deletions internal/fixtures/sample-pipeline.gocd.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Dummy file to test
Loading

0 comments on commit 2fb9958

Please sign in to comment.