Skip to content

Commit

Permalink
Merge pull request #83 from DontShaveTheYak/develop
Browse files Browse the repository at this point in the history
Release 0.7.1
  • Loading branch information
shadycuz committed Jun 4, 2021
2 parents 759e404 + 5d85ae1 commit a59b91f
Show file tree
Hide file tree
Showing 38 changed files with 1,638 additions and 1,701 deletions.
27 changes: 22 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ on:
branches:
- 'master'
pull_request:
paths-ignore:
- '.github/workflows/release.yml'
- '.github/workflows/pr_label.yml'
paths:
- '*gradle*'
- '.github/workflows/test.yml'
- '.groovylintrc.json'
- '.pre-commit-config.yaml'
- 'jobs/**'
- 'src/**'
- 'tests/**'

jobs:
linting:
Expand All @@ -20,10 +25,16 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2.2.2

- name: Python Cache
uses: actions/cache@v2
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('tests/requirements.txt') }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r tests/requirements.txt
pip install --upgrade --upgrade-strategy eager -r tests/requirements.txt
- name: Run pre-commit
run: |
Expand All @@ -40,10 +51,16 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2.2.2

- name: Python Cache
uses: actions/cache@v2
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('tests/requirements.txt') }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r tests/requirements.txt
pip install --upgrade --upgrade-strategy eager -r tests/requirements.txt
- name: Test with pytest
run: pytest
22 changes: 2 additions & 20 deletions .groovylintrc.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
{
"extends": "all",
"extends": "recommended",
"rules": {
"BlockEndsWithBlankLine": {
"enabled": false
},
"BlockStartsWithBlankLine": {
"enabled": false
},
"CompileStatic": {
"enabled": false
},
"ImplicitClosureParameter": {
"enabled": false
},
"LineLength": {
"enabled": false
},
"SerializableClassMustDefineSerialVersionUID": {
"enabled": false
},
"SpaceAroundMapEntryColon": {
"enabled": false
},
"UnnecessaryGetter": {
"enabled": false
},
"UnnecessaryReturnKeyword": {
"UnnecessaryParenthesesForMethodCallWithClosure": {
"enabled": false
}
}
Expand Down
123 changes: 123 additions & 0 deletions jobs/bash/bash_example.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/* groovylint-disable DuplicateNumberLiteral, DuplicateStringLiteral */
@Library('pipeline-library')
import org.dsty.bash.BashClient
import org.dsty.bash.ScriptError
import org.dsty.bash.Result

node() {
String msg
Result result
BashClient bash = new BashClient(this)

stage('Regular Bash') {
msg = 'Hello from Bash!'

// bash() prints the output to the console like sh,
// but it also returns the stdOut, stdError, and exitCode.
// It also returns output which is stdOut and stdError combined
// but the order is not guranteed to be perfect.
result = bash("echo '${msg}'")

if (result.stdOut != msg ) {
error('Did not contain correct output.')
}

if ( result.stdErr ) {
error('Should not have output anything.')
}

if ( result.exitCode != 0 ) {
error('Exited with wrong code.')
}

// In the event of a non 0 exitCode an Exception
// is thrown. The exception will behave just like a normal Result.
// So it will also have stdOut, stdError, output and exitCode.
ScriptError exception = null

try {
bash('RegularFakeCommand')
} catch (ScriptError e) {
exception = e
}

if ( !exception.stdErr.contains('RegularFakeCommand: command not found') ) {
error('Command was found.')
}

if (exception.stdOut) {
error('Should not have stdOut.')
}

if ( exception.exitCode != 127) {
error('Exited with wrong code.')
}
}

stage('Silent Bash') {
msg = 'NotShown!'

result = bash.silent("echo '${msg}'")

if (result.stdOut != msg ) {
error('Did not contain correct output.')
}

if ( result.stdErr ) {
error('Should not have output anything.')
}

if ( result.exitCode != 0 ) {
error('Exited with wrong code.')
}
}

stage('Ignore Errors') {
// ignoreErrors will not throw an exception.
// Instead is just returns the results after
// it encounters an error.
result = bash.ignoreErrors('fakecommand', true)

if ( !result.stdErr.contains('fakecommand: command not found') ) {
error('Command was found.')
}

if (result.stdOut) {
error('Should not have stdOut.')
}

if ( result.exitCode != 127) {
error('Exited with wrong code.')
}

// By default ignoreErrors will ignore all errors and run
// the entire script before returning.

String script = '''\
fakeCommand
anotherFakeCommand
'''

// The false we are passing determines if the command output is to be
// displayed in the build console.
result = bash.ignoreErrors(script, false)

if ( !result.stdErr.contains('anotherFakeCommand') ) {
error('Should not stop on first error.')
}

// If you want to return on the first error,
// set failfast to true.
result = bash.ignoreErrors(script, false, true)

if ( result.stdErr.contains('anotherFakeCommand') ) {
error('Should stop on first error.')
}

result = bash.ignoreErrors('exit 55', false)

if ( result.exitCode != 55 ) {
error('Should capture the correct exitCode.')
}
}
}
45 changes: 0 additions & 45 deletions jobs/bash/call

This file was deleted.

46 changes: 0 additions & 46 deletions jobs/bash/ignore_errors

This file was deleted.

45 changes: 0 additions & 45 deletions jobs/bash/silent

This file was deleted.

Loading

0 comments on commit a59b91f

Please sign in to comment.