Skip to content
Permalink
Browse files

replaced sh with bash and added examples with tests

  • Loading branch information...
mserranom committed Jul 17, 2018
1 parent a3492f7 commit 8a1874dfff61aa58fa8db40b02d8d2b2e44a14c0
@@ -34,6 +34,8 @@ running "build" in "atlassian/default-image" image...
hello world!
```

Check the [examples](https://github.com/mserranom/bbrun/tree/master/examples) and its [tests](https://github.com/mserranom/bbrun/blob/master/examples/examples.test.js) to learn different use cases.

### Options

```
@@ -0,0 +1,64 @@
function run(name, options = "") {
const pwd = require("shelljs").pwd();
const exec = require("shelljs").exec;
const result = exec(
`cd ${pwd}/examples/${name} && node ../../index.js ${options}`,
{
silent: true
}
);
return result.stdout;
}

test("hello-world", () => {
expect(run("hello-world")).toMatch("hello world!");
});

describe("multiple-pipelines", () => {
test("all default steps", () => {
expect(run("multiple-pipelines")).toBe(`executing step in "ubuntu"
default step
executing step in "ubuntu"
step2 executed
executing step in "ubuntu"
step3 executed in ubuntu
`);
});

test("step2", () => {
expect(run("multiple-pipelines", "step2"))
.toBe(`executing step "step2" in "ubuntu"
step2 executed
`);
});
test("Step Three", () => {
expect(run("multiple-pipelines", '"Step Three"'))
.toBe(`executing step "Step Three" in "ubuntu"
step3 executed in ubuntu
`);
});

test("master_step_2", () => {
expect(
run("multiple-pipelines", "master_step_2 --pipeline branches:master")
).toBe(`executing step "master_step_2" in "ubuntu"
step2 in master branch
`);
});

test("** -> 'branch step 2'", () => {
expect(run("multiple-pipelines", '"branch step 2" --pipeline branches:**'))
.toBe(`executing step "branch step 2" in "ubuntu"
step2 in any branch
`);
});

test("all master steps", () => {
expect(run("multiple-pipelines", "--pipeline branches:master"))
.toBe(`executing step in "ubuntu"
default step in master branch
executing step in "ubuntu"
step2 in master branch
`);
});
});
@@ -0,0 +1,7 @@
pipelines:
default:
- step:
image: ubuntu
script:
- echo "hello world!"

@@ -0,0 +1,33 @@
image: ubuntu
pipelines:
default:
- step:
script:
- echo "default step"
- step:
name: step2
script:
- echo "step2 executed"
- step:
image: ubuntu
name: Step Three
script:
- echo "step3 executed in ubuntu"
branches:
'**':
- step:
script:
- echo "default step for any branch"
- step:
name: branch step 2
script:
- echo "step2 in any branch"
master:
- step:
script:
- echo "default step in master branch"
- step:
name: master_step_2
script:
- echo "step2 in master branch"

@@ -7,7 +7,9 @@
"bin": "./index.js",
"scripts": {
"prettier": "prettier --write *.js src/*.js test/*.js",
"test": "jest"
"test": "jest test/*.js",
"test-examples": "jest examples/*.js",
"test-all": "jest"
},
"repository": {
"type": "git",
@@ -33,7 +33,7 @@ function checkExists() {
function run(commands, image, dryRun, interactive, workDir) {
const cmd = interactive
? `run -P -it --entrypoint=/bin/bash -v ${pwd()}:${workDir} -w ${workDir} ${image}`
: `run -P -v ${pwd()}:${workDir} -w ${workDir} ${image} sh ${BUILD_SCRIPT}`;
: `run -P -v ${pwd()}:${workDir} -w ${workDir} ${image} bash ${BUILD_SCRIPT}`;

if (dryRun) {
console.log(`docker command:\n\tdocker ${cmd}`);
@@ -3,7 +3,7 @@
exports[`environment variables miltiple variables are added to the script 1`] = `
"executing step in \\"ubuntu\\"
docker command:
docker run -P -v PWD:/ws -w /ws ubuntu sh .bbrun.sh
docker run -P -v PWD:/ws -w /ws ubuntu bash .bbrun.sh
build script:
export foo=bar
export var=env
@@ -15,7 +15,7 @@ build script:
exports[`environment variables single variable is added to the script 1`] = `
"executing step in \\"ubuntu\\"
docker command:
docker run -P -v PWD:/ws -w /ws ubuntu sh .bbrun.sh
docker run -P -v PWD:/ws -w /ws ubuntu bash .bbrun.sh
build script:
export foo=bar
set -e
@@ -32,7 +32,7 @@ Malformed template, check https://confluence.atlassian.com/bitbucket/configure-b
exports[`no image template should use default atlassian image 1`] = `
"executing step in \\"atlassian/default-image:latest\\"
docker command:
docker run -P -v PWD:/ws -w /ws atlassian/default-image:latest sh .bbrun.sh
docker run -P -v PWD:/ws -w /ws atlassian/default-image:latest bash .bbrun.sh
build script:
set -e
echo \\"testing stuff\\"
@@ -42,7 +42,7 @@ build script:
exports[`should resolve private image names 1`] = `
"executing step in \\"account-name/openjdk:8\\"
docker command:
docker run -P -v PWD:/ws -w /ws account-name/openjdk:8 sh .bbrun.sh
docker run -P -v PWD:/ws -w /ws account-name/openjdk:8 bash .bbrun.sh
build script:
set -e
echo \\"testing stuff\\"
@@ -52,7 +52,7 @@ build script:
exports[`single step pipeline executes the default step with no arguments 1`] = `
"executing step in \\"ubuntu\\"
docker command:
docker run -P -v PWD:/ws -w /ws ubuntu sh .bbrun.sh
docker run -P -v PWD:/ws -w /ws ubuntu bash .bbrun.sh
build script:
set -e
echo \\"testing stuff\\"
@@ -62,7 +62,7 @@ build script:
exports[`single step pipeline executes the step by name 1`] = `
"executing step \\"test\\" in \\"ubuntu\\"
docker command:
docker run -P -v PWD:/ws -w /ws ubuntu sh .bbrun.sh
docker run -P -v PWD:/ws -w /ws ubuntu bash .bbrun.sh
build script:
set -e
echo \\"testing stuff\\"
@@ -72,7 +72,7 @@ build script:
exports[`template with multiple steps in the default pipeline should execute a named step in a branch 1`] = `
"executing step \\"master_step_2\\" in \\"atlassian/default-image:latest\\"
docker command:
docker run -P -v PWD:/ws -w /ws atlassian/default-image:latest sh .bbrun.sh
docker run -P -v PWD:/ws -w /ws atlassian/default-image:latest bash .bbrun.sh
build script:
set -e
echo \\"master step 2\\"
@@ -82,7 +82,7 @@ build script:
exports[`template with multiple steps in the default pipeline should execute a single step by name 1`] = `
"executing step \\"step2\\" in \\"atlassian/default-image:latest\\"
docker command:
docker run -P -v PWD:/ws -w /ws atlassian/default-image:latest sh .bbrun.sh
docker run -P -v PWD:/ws -w /ws atlassian/default-image:latest bash .bbrun.sh
build script:
set -e
echo \\"step2\\"
@@ -92,7 +92,7 @@ build script:
exports[`template with multiple steps in the default pipeline should execute a single step by name with spaces in the name 1`] = `
"executing step \\"Step Three\\" in \\"ubuntu\\"
docker command:
docker run -P -v PWD:/ws -w /ws ubuntu sh .bbrun.sh
docker run -P -v PWD:/ws -w /ws ubuntu bash .bbrun.sh
build script:
set -e
echo \\"step3\\"
@@ -102,19 +102,19 @@ build script:
exports[`template with multiple steps in the default pipeline should execute all the default steps when no argument is provided 1`] = `
"executing step in \\"atlassian/default-image:latest\\"
docker command:
docker run -P -v PWD:/ws -w /ws atlassian/default-image:latest sh .bbrun.sh
docker run -P -v PWD:/ws -w /ws atlassian/default-image:latest bash .bbrun.sh
build script:
set -e
echo \\"testing stuff\\"
executing step in \\"atlassian/default-image:latest\\"
docker command:
docker run -P -v PWD:/ws -w /ws atlassian/default-image:latest sh .bbrun.sh
docker run -P -v PWD:/ws -w /ws atlassian/default-image:latest bash .bbrun.sh
build script:
set -e
echo \\"step2\\"
executing step in \\"ubuntu\\"
docker command:
docker run -P -v PWD:/ws -w /ws ubuntu sh .bbrun.sh
docker run -P -v PWD:/ws -w /ws ubuntu bash .bbrun.sh
build script:
set -e
echo \\"step3\\"
@@ -124,13 +124,13 @@ build script:
exports[`template with multiple steps in the default pipeline should execute all the steps in a branch if no step provided 1`] = `
"executing step in \\"atlassian/default-image:latest\\"
docker command:
docker run -P -v PWD:/ws -w /ws atlassian/default-image:latest sh .bbrun.sh
docker run -P -v PWD:/ws -w /ws atlassian/default-image:latest bash .bbrun.sh
build script:
set -e
echo \\"testing stuff in master branch\\"
executing step in \\"atlassian/default-image:latest\\"
docker command:
docker run -P -v PWD:/ws -w /ws atlassian/default-image:latest sh .bbrun.sh
docker run -P -v PWD:/ws -w /ws atlassian/default-image:latest bash .bbrun.sh
build script:
set -e
echo \\"master step 2\\"
@@ -140,7 +140,7 @@ build script:
exports[`template with multiple steps in the default pipeline should understand asterisk branches 1`] = `
"executing step \\"branch step 2\\" in \\"atlassian/default-image:latest\\"
docker command:
docker run -P -v PWD:/ws -w /ws atlassian/default-image:latest sh .bbrun.sh
docker run -P -v PWD:/ws -w /ws atlassian/default-image:latest bash .bbrun.sh
build script:
set -e
echo \\"testing stuff in any branch\\"
@@ -150,7 +150,7 @@ build script:
exports[`working directory is overriden 1`] = `
"executing step in \\"ubuntu\\"
docker command:
docker run -P -v PWD:/test_wd -w /test_wd ubuntu sh .bbrun.sh
docker run -P -v PWD:/test_wd -w /test_wd ubuntu bash .bbrun.sh
build script:
set -e
echo \\"testing stuff\\"

0 comments on commit 8a1874d

Please sign in to comment.
You can’t perform that action at this time.