Skip to content
29 changes: 20 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ The best way to [report an issue is through Github](https://github.com/devlinjun
<!-- This section details the steps to setup the project for development -->

### Environment Setup and Tools
You will need to install Git and create an account on Github to take advantage of all of the features of this template. This template also uses scripts that expect Bash to be installed at `/bin/bash`.
This example uses scripts that expect Bash to be installed at `/bin/bash`. The rest of the tools should be included when you clone the repo.

#### Create your own Project from this Template
There are multiple ways to use this template as a starting point for your own project. The **best way to use this is by cloning the repo to your GitHub account and creating your project with the template feature provided by Github**:
#### Create your own Project from this Example
There are multiple ways to use this example as a starting point for your own project. The **best way to use this is by cloning the repo to your GitHub account and creating your project with the template feature provided by Github**:

<img width="1130" alt="template" src="https://user-images.githubusercontent.com/1504590/95393957-55b31c80-08b0-11eb-9126-55d8105881f4.png">

Expand Down Expand Up @@ -52,8 +52,8 @@ git push --set-upstream origin develop
Once you have a framework and development environment chosen for your project, you should update your repo with specifics about how to install the tools and dependencies needed to run/debug/develop the application (See README for checklist).


#### Update a Project or add to existing Project
The steps **to update a Project that was created using this template**, or to **add these features to an existing project** are the same. In the projects root directory:
#### Add Bash Testing to your Project
You can also **add these features to an existing project** by using this template and following these steps:
```
git checkout main;
git remote add template https://github.com/devlinjunker/example.cii.git;
Expand All @@ -67,6 +67,8 @@ git commit;
git push;
```

**Or you can just use this example as an idea for your own projects**


### Folder Structure
Break down how each folder is used in the repo and how different code file types should be organized.
Expand Down Expand Up @@ -143,11 +145,20 @@ Some ideas of things to include in your styleguide include:


#### Testing
This template doesn't include any tests yet (although we could add them...). Once you start using this for your own project though, you should include any testing details and requirements here.
This template includes tests for each of the Bash Scripts that help automate the Semantic Versioning process in GitHub Actions and that run during the Git Hooks. Each `.sh` file in the `scripts/` directory should have a corresponding `.bats` file in the `qa/scripts/` directory.

Run every BATS test with:
```
lib/bats-core/bin/bats qa/**/*.bats
```

Run a single BATS test with:
```
lib/bats-core/bin/bats <path to .bats file>
```

Ideas to consider for testing:
- unit tests
- integration tess
Other ideas to consider for testing:
- integration tests
- e2e tests
- automation tests
- contract tests
Expand Down
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ Version: 0.2-SNAPSHOT
## Intro
<!-- Quick Description, could match Github repo description or have a little more info-->

This is an example project with a goal of 100% Passing [Core Infrastructure Initiative Criteria].
This is an example project with a goal of 100% passing [Core Infrastructure Initiative Criteria] status. It is based off of the [Github Semver Project](https://github.com/devlinjunker/template.github.semver) Template.

It is based off of:
- Template [Github Semver Project](https://github.com/devlinjunker/template.github.semver)

<!--
With improvements:
Contains the following improvements for passing status:
- Automated Test Suite (for Bash Scripts)
<!--
- Static Code Analysis (Linting)
- Automated Test Suite
-->


Expand All @@ -33,6 +30,7 @@ With improvements:

- [Bulldozer] - Github Application to Auto Squash and Merge feature PRs
- [Git-mkver] - Binary that helps with determining next semantic version based on Git Tags
- [BATS] - Automated Test Suite for Bash Scripts

## Quick Setup/Run
<!-- This section should try to quickly explain how to setup the project and start using it (server/app/demo/template) - ideally in list format -->
Expand All @@ -45,7 +43,7 @@ With improvements:
- [ ] Update this README and Links with project specific details
- [ ] Review [Github Workflows] in Template (and improve for your process)
- [ ] Add Custom Project Build and Configuration Files
- Start Coding!
- Start Writing Tests and Coding!

## Links

Expand All @@ -72,4 +70,5 @@ With improvements:
[Bash]: https://tldp.org/LDP/abs/html/
[Github Actions]: https://docs.github.com/en/free-pro-team@latest/actions
[Bulldozer]: https://github.com/palantir/bulldozer
[Git-mkver]: https://idc101.github.io/git-mkver/
[Git-mkver]: https://idc101.github.io/git-mkver/
[BATS]: https://bats-core.readthedocs.io/
5 changes: 1 addition & 4 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ currently being supported with security updates -->

| Version | Supported |
| ------- | ------------------ |
| > 1.0.x | :white_check_mark: |
| > 0.12.x | :white_check_mark: |
| 0.11.x | :heavy_minus_sign: |
| < 0.10 | :x: |
| > 0.1.x | :white_check_mark: |

## Reporting a Vulnerability

Expand Down
68 changes: 68 additions & 0 deletions qa/scripts/hooks/branch-name.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env ../../..libs/bats/bin/bats
load '../../../lib/bats-support/load'
load '../../../lib/bats-assert/load'

SCRIPT_DIR="$BATS_TEST_DIRNAME"/../../../scripts/hooks

TEST_PREFIX="branch-name.sh -";


@test "$TEST_PREFIX should not allow branches that don't match output of prefix-list.sh or defaults" {
function git() {
echo "abc/test-name";
}
export -f git

BATS_PREFIX_LIST=""
export BATS_PREFIX_LIST

run "$SCRIPT_DIR"/branch-name.sh
unset BATS_PREFIX_LIST

assert_failure
}

@test "$TEST_PREFIX should allow default branch prefixes (feat, fix)" {
function git() {
echo "fix/test-name";
}
export -f git

run "$SCRIPT_DIR"/branch-name.sh

assert_success

function git() {
echo "feat/test-name";
}
export -f git

run "$SCRIPT_DIR"/branch-name.sh

assert_success
}

@test "$TEST_PREFIX should allow branches that match output of prefix-list.sh" {
function git() {
echo "abc/test-name";
}
export -f git

BATS_PREFIX_LIST="abc"
export BATS_PREFIX_LIST

run "$SCRIPT_DIR"/branch-name.sh
unset BATS_PREFIX_LIST

assert_success
}

@test "$TEST_PREFIX should allow patch branches" {
function git() {
echo "patch-0.0.1"
}
export -f git

run "$SCRIPT_DIR"/branch-name.sh
assert_success
}
34 changes: 34 additions & 0 deletions qa/scripts/hooks/branch-protections.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env ../../..libs/bats/bin/bats
load '../../../lib/bats-support/load'
load '../../../lib/bats-assert/load'

SCRIPT_DIR="$BATS_TEST_DIRNAME"/../../../scripts/hooks
TEST_PREFIX="branch-protections.sh -";

@test "$TEST_PREFIX should error on 'main' or 'develop' " {
function git() {
echo "main"
}
export -f git
run "$SCRIPT_DIR"/branch-protections.sh

assert_failure

function git() {
echo "develop"
}
export -f git
run "$SCRIPT_DIR"/branch-protections.sh

assert_failure
}

@test "$TEST_PREFIX should not error on other branches" {
function git() {
echo "abc"
}
export -f git
run "$SCRIPT_DIR"/branch-protections.sh

assert_success
}
65 changes: 65 additions & 0 deletions qa/scripts/hooks/commit-msg.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env ../../..libs/bats/bin/bats
load '../../../lib/bats-support/load'
load '../../../lib/bats-assert/load'

SCRIPT_DIR="$BATS_TEST_DIRNAME"/../../../scripts/hooks
TEST_PREFIX="commit-msg.sh -";

@test "$TEST_PREFIX should allow commit messages that match basic format <prefix>:<description>" {
BATS_PREFIX_LIST=''
export BATS_PREFIX_LIST

echo "fix: test" > tmp;

run "$SCRIPT_DIR"/commit-msg.sh tmp
assert_success

echo "fix: test 123 look at me" > tmp;

run "$SCRIPT_DIR"/commit-msg.sh tmp
assert_success

echo "feat: test" > tmp;

run "$SCRIPT_DIR"/commit-msg.sh tmp
assert_success

echo "wip: test" > tmp;

run "$SCRIPT_DIR"/commit-msg.sh tmp
assert_success

unset BATS_PREFIX_LIST
rm tmp;
}

@test "$TEST_PREFIX should NOT allow commit messages that do not match format" {
BATS_PREFIX_LIST=''
export BATS_PREFIX_LIST

echo "abctest" > tmp;

run "$SCRIPT_DIR"/commit-msg.sh tmp
assert_failure

unset less
rm tmp;
}

@test "$TEST_PREFIX should allow optional scope" {
BATS_PREFIX_LIST=''
export BATS_PREFIX_LIST

echo "fix(scope): test" > tmp;

run "$SCRIPT_DIR"/commit-msg.sh tmp
assert_success

echo "feat(scope): test" > tmp;

run "$SCRIPT_DIR"/commit-msg.sh tmp
assert_success

unset BATS_PREFIX_LIST
rm tmp;
}
65 changes: 65 additions & 0 deletions qa/scripts/hooks/post-commit.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env ../../..libs/bats/bin/bats
load '../../../lib/bats-support/load'
load '../../../lib/bats-assert/load'

SCRIPT_DIR="$BATS_TEST_DIRNAME"/../../../scripts/hooks
TEST_PREFIX="post-commit.sh -";

@test "$TEST_PREFIX should show warning if over 25 files or 400 lines" {
function sed() { # branch to compare
echo "develop"
}
export -f sed
function tail () { ## lines
echo "401"
}
function head () { ## files
echo "24"
}
export -f tail
export -f head

run "$SCRIPT_DIR"/post-commit.sh

unset sed
assert_output --partial "warning"

function sed() { # branch to compare
echo "develop"
}
export -f sed
function tail () { ## lines
echo "399"
}
function head () { ## files
echo "26"
}
export -f tail
export -f head

run "$SCRIPT_DIR"/post-commit.sh

unset sed
assert_output --partial "warning"
}

@test "$TEST_PREFIX should not show warning if under 25 files and 400 lines" {
function sed() { # branch to compare
echo "develop"
}
export -f sed
function tail () { ## lines
echo "399"
}
function head () { ## files
echo "19"
}
export -f tail
export -f head

run "$SCRIPT_DIR"/post-commit.sh

unset sed

assert_output
}
Loading