diff --git a/.github/workflows/README.md b/.github/workflows/README.md
index 3f5f790..d4c335b 100644
--- a/.github/workflows/README.md
+++ b/.github/workflows/README.md
@@ -25,6 +25,8 @@ This directory contains files related to Github configurations and actions:
- Runs the verify-merge.sh script in `scripts/` directory and fails the action if the script does not complete succesfully
- Prevents mergin branches with name `poc` or where last commit contains `wip`
- Verifies that Pull Request Title matches branch prefix
+ - Runs BATS tests and errors if they fail
+ - Lints the shell script files with Shellcheck
### Cut `release-*` Branch Action (release-cut.yaml)
- Verifies `feature` commits have been added to `develop` since last release cut
@@ -34,6 +36,8 @@ This directory contains files related to Github configurations and actions:
### Verify `main` Merge Action (main-verify-merge.yaml)
- Verifies that Pull Request Title is correct format `release-*` or `hotfix-*`
- Verifies that Pull Request branch is `release-*` or `hotfix-*` branch
+ - Runs BATS tests and errors if they fail
+ - Lints the shell script files with Shellcheck
### On Merge to `main` Action (main-on-merge.yaml)
- Syncs README.md files to wiki
diff --git a/.github/workflows/develop-verify-merge.yaml b/.github/workflows/develop-verify-merge.yaml
index da4dbcb..f5aeb7b 100644
--- a/.github/workflows/develop-verify-merge.yaml
+++ b/.github/workflows/develop-verify-merge.yaml
@@ -15,6 +15,8 @@ jobs:
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
+ with:
+ submodules: 'recursive'
- name: Prevent POC/WIP branches
run: |
@@ -34,4 +36,10 @@ jobs:
with:
regex: '(\([\w\s]*\)*\))?:[\w\s]*'
allowed_prefixes: ${{ steps.extract_branch.outputs.prefix }}
- prefix_case_sensitive: true
\ No newline at end of file
+ prefix_case_sensitive: true
+
+ - name: "Verify BATS Tests Pass"
+ run: 'scripts/bin/test.sh'
+
+ - name: "Lint with Shellcheck"
+ run: 'scripts/bin/lint.sh'
\ No newline at end of file
diff --git a/.github/workflows/main-verify-merge.yaml b/.github/workflows/main-verify-merge.yaml
index aebdfba..99fc34a 100644
--- a/.github/workflows/main-verify-merge.yaml
+++ b/.github/workflows/main-verify-merge.yaml
@@ -13,6 +13,8 @@ jobs:
steps:
- uses: actions/checkout@v2
+ with:
+ submodules: 'recursive'
- name: "Verify 'main' PR are from 'release-*' or 'patch-*' branch"
run: ./scripts/workflows/branch-match.sh
@@ -24,4 +26,10 @@ jobs:
uses: deepakputhraya/action-pr-title@master
with:
regex: '-[0-9]+.[0-9]+(.[0-9]+)?'
- allowed_prefixes: release,patch
\ No newline at end of file
+ allowed_prefixes: release,patch
+
+ - name: "Verify BATS Tests Pass"
+ run: 'scripts/bin/test.sh'
+
+ - name: "Lint with Shellcheck"
+ run: 'scripts/bin/lint.sh'
\ No newline at end of file
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..bbefb51
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,9 @@
+[submodule "lib/bats-core"]
+ path = lib/bats-core
+ url = https://github.com/bats-core/bats-core
+[submodule "lib/bats-assert"]
+ path = lib/bats-assert
+ url = https://github.com/bats-core/bats-assert
+[submodule "lib/bats-support"]
+ path = lib/bats-support
+ url = https://github.com/bats-core/bats-support
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index c239566..880a2c5 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -11,10 +11,10 @@ The best way to [report an issue is through Github](https://github.com/devlinjun
### 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**:
@@ -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;
@@ -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.
@@ -78,9 +80,13 @@ Break down how each folder is used in the repo and how different code file types
|-- workflows/
|---- (Github workflow .yaml files)
|-- (other github specific files)
-- img/
-|-- (project image files)
+- qa/
+|-- scripts/
+|---- files specific to testing the script files (BATS)
+|-- (other testing files should be stored in here)
- scripts/
+|-- bin/
+|---- (Scripts for developers to run the project)
|-- hooks/
|---- (Git Hooks Scripts)
|-- release/
@@ -134,24 +140,30 @@ Review the [Security Policy](https://github.com/devlinjunker/template.github.sem
#### Style Guide
-Once you start your project, you should update the style guide here or [link to a Wiki page](https://github.com/devlinjunker/template.github.semver/wiki/Styleguide) from here.
+This example uses the [Shellcheck](https://www.shellcheck.net/) command line tool to ensure that the Bash Scripts that help automate the Semantic Versioning process are written with up to date standards.
+
+See the [Shellcheck Wiki](https://github.com/koalaman/shellcheck/wiki/Checks) for a full list of the checks that it is performing
-Some ideas of things to include in your styleguide include:
- - Code Formating and (linting) tools used to ensure the style is met
- - Organization of Files
- - Best practices for designing new features
+Run the linting process with:
+```
+scripts/bin/lint.sh
+```
#### 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.
-
-Ideas to consider for testing:
- - unit tests
- - integration tess
- - e2e tests
- - automation tests
- - contract tests
- - mutation tests
+This example 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 test with:
+```
+qa/runner.sh
+```
+
+Run a single test with:
+```
+qa/runner.sh --file
+```
+
+See the [READMEs in `qa/` directory](https://github.com/devlinjunker/example.cii/tree/develop/qa)
#### Release
diff --git a/README.md b/README.md
index 9bfd598..4458c45 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
---
-Version: 0.1.0
+Version: 0.2.0
---
# Example - CII 100%
@@ -8,7 +8,7 @@ Version: 0.1.0
[![GitHub License](https://img.shields.io/github/license/devlinjunker/example.cii?color=blue)](https://github.com/devlinjunker/example.cii/blob/develop/LICENSE)
[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/devlinjunker/example.cii)](https://github.com/devlinjunker/example.cii/releases)
[![GitHub last commit](https://img.shields.io/github/last-commit/devlinjunker/example.cii)](https://github.com/devlinjunker/example.cii/commits/main)
-
+[![CII Best Practices Summary](https://img.shields.io/cii/summary/4558?label=core-infrastructure)](https://bestpractices.coreinfrastructure.org/en/projects/4558)
[![GitHub issues](https://img.shields.io/github/issues/devlinjunker/example.cii)](https://github.com/devlinjunker/example.cii/issues)
[![GitHub priority issues](https://img.shields.io/github/issues/devlinjunker/example.cii/-priority?color=red&label=priority%20issues)](https://github.com/devlinjunker/example.cii/issues?q=is%3Aopen+is%3Aissue+label%3A-priority)
@@ -16,16 +16,11 @@ Version: 0.1.0
## Intro
-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)
-
-
## Dependencies/Frameworks
@@ -33,6 +28,8 @@ 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
+- [ShellCheck] - Linting Tool for Bash Scripts
## Quick Setup/Run
@@ -45,7 +42,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
@@ -72,4 +69,6 @@ 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/
\ No newline at end of file
+[Git-mkver]: https://idc101.github.io/git-mkver/
+[BATS]: https://bats-core.readthedocs.io/
+[ShellCheck]: https://www.shellcheck.net/
\ No newline at end of file
diff --git a/SECURITY.md b/SECURITY.md
index 0303d95..bc6a7e5 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -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
diff --git a/lib/.gitignore b/lib/.gitignore
new file mode 100644
index 0000000..99ecbf0
--- /dev/null
+++ b/lib/.gitignore
@@ -0,0 +1 @@
+shellcheck*/
diff --git a/lib/bats-assert b/lib/bats-assert
new file mode 160000
index 0000000..0a8dd57
--- /dev/null
+++ b/lib/bats-assert
@@ -0,0 +1 @@
+Subproject commit 0a8dd57e2cc6d4cc064b1ed6b4e79b9f7fee096f
diff --git a/lib/bats-core b/lib/bats-core
new file mode 160000
index 0000000..4c98d3a
--- /dev/null
+++ b/lib/bats-core
@@ -0,0 +1 @@
+Subproject commit 4c98d3ad65eb77e5caf56984cdc67674e656e980
diff --git a/lib/bats-support b/lib/bats-support
new file mode 160000
index 0000000..d140a65
--- /dev/null
+++ b/lib/bats-support
@@ -0,0 +1 @@
+Subproject commit d140a65044b2d6810381935ae7f0c94c7023c8c3
diff --git a/lib/shellcheck-v0.7.1.darwin.x86_64.tar.xz b/lib/shellcheck-v0.7.1.darwin.x86_64.tar.xz
new file mode 100644
index 0000000..ff90c29
Binary files /dev/null and b/lib/shellcheck-v0.7.1.darwin.x86_64.tar.xz differ
diff --git a/lib/shellcheck-v0.7.1.linux.x86_64.tar.xz b/lib/shellcheck-v0.7.1.linux.x86_64.tar.xz
new file mode 100644
index 0000000..aecfb4d
Binary files /dev/null and b/lib/shellcheck-v0.7.1.linux.x86_64.tar.xz differ
diff --git a/qa/README.md b/qa/README.md
new file mode 100644
index 0000000..05820d7
--- /dev/null
+++ b/qa/README.md
@@ -0,0 +1,22 @@
+# Testing
+
+The `qa/` directory contains files used during testing. It is named "qa" so that it will precede the `script/` and `src/` directories that it will be testing in Pull Requests.
+
+Each feature that is added to this project should include test files that detail the expectations for the new feature. If there is a new unit testing framework needed, please [submit an issue](https://github.com/devlinjunker/example.cii/issues/new/choose).
+
+For now this includes:
+ - unit tests with BATS for script files
+
+## Test Running Script
+The `scripts/bin/` directory also contains a script file (`test.sh`) that manages running all of the test files. This will either:
+ - run all tests if no arguments are passed (or `-a/--all`)
+ - or will try to find a specific file to run with the `-f/--file` argument
+
+## Other Ideas
+ - integration tests
+ - e2e tests
+ - automation tests
+ - contract tests
+ - mutation tests
+ - helpers?
+ - BATS helper - mocking/stubbing/spying (see [here](scripts/release/release-prep-upmerge.bats))
\ No newline at end of file
diff --git a/qa/scripts/README.md b/qa/scripts/README.md
new file mode 100644
index 0000000..f26c5cb
--- /dev/null
+++ b/qa/scripts/README.md
@@ -0,0 +1,17 @@
+## Testing Script Files
+
+Shell Script testing is done with [BATS]. These tests are organized in the same structure as the `script/` file directory and test files will have the same name as the script they are testing.
+
+
+To run every BATS test:
+```
+lib/bats-core/bin/bats qa -r
+```
+
+To run a single BATS test:
+```
+lib/bats-core/bin/bats
+```
+
+
+[BATS]: https://bats-core.readthedocs.io/
\ No newline at end of file
diff --git a/qa/scripts/hooks/branch-name.bats b/qa/scripts/hooks/branch-name.bats
new file mode 100644
index 0000000..293803b
--- /dev/null
+++ b/qa/scripts/hooks/branch-name.bats
@@ -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
+}
\ No newline at end of file
diff --git a/qa/scripts/hooks/branch-protections.bats b/qa/scripts/hooks/branch-protections.bats
new file mode 100644
index 0000000..3095328
--- /dev/null
+++ b/qa/scripts/hooks/branch-protections.bats
@@ -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
+}
\ No newline at end of file
diff --git a/qa/scripts/hooks/commit-msg.bats b/qa/scripts/hooks/commit-msg.bats
new file mode 100644
index 0000000..78e2c0f
--- /dev/null
+++ b/qa/scripts/hooks/commit-msg.bats
@@ -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 :" {
+ 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;
+}
\ No newline at end of file
diff --git a/qa/scripts/hooks/post-commit.bats b/qa/scripts/hooks/post-commit.bats
new file mode 100644
index 0000000..afadc65
--- /dev/null
+++ b/qa/scripts/hooks/post-commit.bats
@@ -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
+}
\ No newline at end of file
diff --git a/qa/scripts/hooks/pre-commit.bats b/qa/scripts/hooks/pre-commit.bats
new file mode 100644
index 0000000..20c3b68
--- /dev/null
+++ b/qa/scripts/hooks/pre-commit.bats
@@ -0,0 +1,57 @@
+#!/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="pre-commit.sh -";
+
+
+@test "$TEST_PREFIX should error on protected branch (develop or main)" {
+ function git() {
+ echo "develop";
+ }
+ export -f git
+
+ run "$SCRIPTS_DIR"/pre-commit.sh
+
+ assert_failure
+
+ function git() {
+ echo "main";
+ }
+ export -f git
+
+ run "$SCRIPT_DIR"/pre-commit.sh
+
+ assert_failure
+}
+
+@test "$TEST_PREFIX should not error on branch name that matches prefix list" {
+ function git() {
+ echo "abc/test-name";
+ }
+ export -f git
+
+ BATS_PREFIX_LIST="abc"
+ export BATS_PREFIX_LIST
+
+ run "$SCRIPT_DIR"/pre-commit.sh
+
+ unset BATS_PREFIX_LIST
+ assert_success
+}
+
+@test "$TEST_PREFIX should not error on patch branch" {
+ function git() {
+ echo "patch-1.2.3";
+ }
+ export -f git
+
+ BATS_PREFIX_LIST=""
+ export BATS_PREFIX_LIST
+
+ run "$SCRIPT_DIR"/pre-commit.sh
+
+ unset BATS_PREFIX_LIST
+ assert_success
+}
\ No newline at end of file
diff --git a/qa/scripts/hooks/pre-push.bats b/qa/scripts/hooks/pre-push.bats
new file mode 100644
index 0000000..43d1173
--- /dev/null
+++ b/qa/scripts/hooks/pre-push.bats
@@ -0,0 +1,56 @@
+#!/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="pre-push.sh -";
+
+@test "$TEST_PREFIX should error on protected branch (develop or main)" {
+ function git() {
+ echo "develop";
+ }
+ export -f git
+
+ run "$SCRIPTS_DIR"/pre-push.sh
+
+ assert_failure
+
+ function git() {
+ echo "main";
+ }
+ export -f git
+
+ run "$SCRIPT_DIR"/pre-commit.sh
+
+ assert_failure
+}
+
+@test "$TEST_PREFIX should not error on branch name that matches prefix list" {
+ function git() {
+ echo "abc/test-name";
+ }
+ export -f git
+
+ BATS_PREFIX_LIST="abc"
+ export BATS_PREFIX_LIST
+
+ run "$SCRIPT_DIR"/pre-push.sh
+
+ unset BATS_PREFIX_LIST
+ assert_success
+}
+
+@test "$TEST_PREFIX should not error on patch branch" {
+ function git() {
+ echo "patch-1.2.3";
+ }
+ export -f git
+
+ BATS_PREFIX_LIST=""
+ export BATS_PREFIX_LIST
+
+ run "$SCRIPT_DIR"/pre-push.sh
+
+ unset BATS_PREFIX_LIST
+ assert_success
+}
\ No newline at end of file
diff --git a/qa/scripts/hooks/prefix-list.bats b/qa/scripts/hooks/prefix-list.bats
new file mode 100644
index 0000000..dd2245f
--- /dev/null
+++ b/qa/scripts/hooks/prefix-list.bats
@@ -0,0 +1,41 @@
+#!/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="prefix-list.sh -";
+
+@test "$TEST_PREFIX should output default list of allowed branches" {
+ function less() {
+ echo ''
+ }
+ export -f less
+ run "$SCRIPT_DIR"/prefix-list.sh
+
+ unset less
+
+ assert_output --partial 'feat'
+ assert_output --partial 'fix'
+}
+
+@test "$TEST_PREFIX should include values from labels file" {
+ function less() {
+ echo '- name: "abc"'
+ }
+ export -f less
+
+ run "$SCRIPT_DIR"/prefix-list.sh
+ unset less
+
+ assert_output --partial 'abc'
+}
+
+@test "$TEST_PREFIX should use BATS_PREFIX_LIST if set (for mocking tests)" {
+ BATS_PREFIX_LIST='abc 123'
+ export BATS_PREFIX_LIST;
+
+ run "$SCRIPT_DIR"/prefix-list.sh
+ unset less
+
+ assert_output 'abc 123'
+}
\ No newline at end of file
diff --git a/qa/scripts/release/release-cut-check.bats b/qa/scripts/release/release-cut-check.bats
new file mode 100644
index 0000000..d30b7f7
--- /dev/null
+++ b/qa/scripts/release/release-cut-check.bats
@@ -0,0 +1,37 @@
+#!/usr/bin/env ../../..libs/bats/bin/bats
+load '../../../lib/bats-support/load'
+load '../../../lib/bats-assert/load'
+
+SCRIPT_DIR="$BATS_TEST_DIRNAME"/../../../scripts/release
+
+TEST_PREFIX="release-cut-check.sh -";
+
+@test "$TEST_PREFIX should error if found branch matching branch RELEASE_BRANCH" {
+ RELEASE_BRANCH='abc'
+ export RELEASE_BRANCH;
+ function git() {
+ echo "abc
+ 123
+ test"
+ }
+ export -f git
+
+ run "$SCRIPT_DIR"/release-cut-check.sh
+
+ assert_failure
+}
+
+@test "$TEST_PREFIX should NOT error if cannot find branch matching RELEASE_BRANCH" {
+ RELEASE_BRANCH='abc'
+ export RELEASE_BRANCH;
+ function git() {
+ echo "xyz
+ 123
+ test"
+ }
+ export -f git
+
+ run "$SCRIPT_DIR"/release-cut-check.sh
+
+ assert_success
+}
\ No newline at end of file
diff --git a/qa/scripts/release/release-prep-upmerge.bats b/qa/scripts/release/release-prep-upmerge.bats
new file mode 100644
index 0000000..49050f8
--- /dev/null
+++ b/qa/scripts/release/release-prep-upmerge.bats
@@ -0,0 +1,33 @@
+#!/usr/bin/env ../../..libs/bats/bin/bats
+load '../../../lib/bats-support/load'
+load '../../../lib/bats-assert/load'
+
+SCRIPT_DIR="$BATS_TEST_DIRNAME"/../../../scripts/release
+
+TEST_PREFIX="release-prep-upmerge.sh -";
+
+## Mock git binary that stores all call args in file by line
+function git() {
+ echo "$@" >> $BATS_TMPDIR/git.args
+}
+
+setup() {
+ export -f git
+}
+
+teardown() {
+ unset git
+}
+
+@test "$TEST_PREFIX should call git and merge main into develop" {
+ run "$SCRIPT_DIR"/release-prep-upmerge.sh
+
+ first=$(sed '1q;d' $BATS_TMPDIR/git.args)
+ second=$(sed '2q;d' $BATS_TMPDIR/git.args)
+ third=$(sed '3q;d' $BATS_TMPDIR/git.args)
+
+ # checkout develop and merge main into it
+ assert_equal "$first" "checkout develop"
+ assert_equal "$second" "pull"
+ assert_equal "$third" "merge main"
+}
\ No newline at end of file
diff --git a/qa/scripts/release/update-versions.bats b/qa/scripts/release/update-versions.bats
new file mode 100644
index 0000000..ce7842c
--- /dev/null
+++ b/qa/scripts/release/update-versions.bats
@@ -0,0 +1,42 @@
+#!/usr/bin/env ../../..libs/bats/bin/bats
+load '../../../lib/bats-support/load'
+load '../../../lib/bats-assert/load'
+
+SCRIPT_DIR="$BATS_TEST_DIRNAME"/../../../scripts/release
+
+TEST_PREFIX="update-versions.sh -";
+
+@test "$TEST_PREFIX should error if no args passed" {
+ run "$SCRIPT_DIR"/update-versions.sh
+
+ assert_failure
+ assert_output --partial 'Error'
+}
+
+@test "$TEST_PREFIX should update version number in README file with argument" {
+ # get full path of script
+ SCRIPT_PATH=$(dirname "$SCRIPT_DIR"/update-versions.sh)/update-versions.sh
+
+ # go to tmp
+ mkdir tmp
+ cd tmp
+
+ # create README.md file
+ echo "---
+Version: 1.2.3
+---" > README.md
+
+ # run script
+ $SCRIPT_PATH "0.0.1"
+
+ # expect README.md updated
+ output=$(cat README.md | grep "0.0.1" | wc -l | tr -d ' ')
+ assert_equal "$output" "1"
+
+ # expect no other files?
+ output=$(ls -1q | wc -l | tr -d ' ')
+ assert_equal "$output" "1"
+
+ cd ..
+ rm -rf tmp
+}
\ No newline at end of file
diff --git a/qa/scripts/workflows/branch-match.bats b/qa/scripts/workflows/branch-match.bats
new file mode 100644
index 0000000..528e69f
--- /dev/null
+++ b/qa/scripts/workflows/branch-match.bats
@@ -0,0 +1,31 @@
+#!/usr/bin/env ../../..libs/bats/bin/bats
+load '../../../lib/bats-support/load'
+load '../../../lib/bats-assert/load'
+
+SCRIPT_DIR="$BATS_TEST_DIRNAME"/../../../scripts/workflows
+
+TEST_PREFIX="branch-match.sh -";
+
+@test "$TEST_PREFIX should pass if BRANCH matches REGEXP" {
+ BRANCH="test-abc"
+ REGEXP="test"
+ export BRANCH
+ export REGEXP
+
+ run "$SCRIPT_DIR"/branch-match.sh
+
+ unset BRANCH
+ assert_success
+}
+
+@test "$TEST_PREFIX should error if BRANCH does not match REGEXP" {
+ BRANCH="-abc"
+ REGEXP="test"
+ export BRANCH
+ export REGEXP
+
+ run "$SCRIPT_DIR"/branch-match.sh
+
+ unset BRANCH
+ assert_failure
+}
\ No newline at end of file
diff --git a/qa/scripts/workflows/collect-wiki.bats b/qa/scripts/workflows/collect-wiki.bats
new file mode 100644
index 0000000..a22f9b7
--- /dev/null
+++ b/qa/scripts/workflows/collect-wiki.bats
@@ -0,0 +1,79 @@
+#!/usr/bin/env ../../..libs/bats/bin/bats
+load '../../../lib/bats-support/load'
+load '../../../lib/bats-assert/load'
+
+SCRIPT_DIR="$BATS_TEST_DIRNAME"/../../../scripts/workflows
+
+TEST_PREFIX="collect-wiki.sh -";
+
+setup() {
+ # get full path of script
+ SCRIPT_PATH=$(dirname "$SCRIPT_DIR"/collect-wiki.sh)/collect-wiki.sh
+
+ if [ ! -z tmp ]; then
+ rm -rf tmp
+ fi
+ mkdir tmp
+ cd tmp
+}
+
+teardown() {
+ cd ..
+ rm -rf tmp
+}
+
+
+@test "$TEST_PREFIX should create wiki/ dir with CONTRIBUTING, SECURITY and home page file" {
+ echo "" > CONTRIBUTING.md
+ echo "" > SECURITY.md
+
+ $SCRIPT_PATH
+
+ # expect wiki/ to exist
+ run ls wiki
+ assert_success
+
+ # expect 3 files (home page + CONTRIBUTING and SECURITY)
+ output=$(ls -A1q wiki | wc -l | tr -d ' ')
+ assert_equal "$output" "3"
+}
+
+@test "$TEST_PREFIX should fail if no CONTRIBUTING or SECURITY file" {
+ run $SCRIPT_PATH
+
+ assert_failure
+}
+
+@test "$TEST_PREFIX should include other README files in wiki/ dir and home page" {
+ echo "" > CONTRIBUTING.md
+ echo "" > SECURITY.md
+ mkdir test
+ echo "" > test/README.md
+
+ $SCRIPT_PATH
+
+ # expect 4 files
+ output=$(ls -A1q wiki | wc -l | tr -d ' ')
+ assert_equal "$output" "4"
+
+ run grep 'CONTRIBUTING.md' wiki/.README-\(synced\).md
+ assert_success
+
+ run grep 'SECURITY.md' wiki/.README-\(synced\).md
+ assert_success
+
+ run grep 'test/README.md' wiki/.README-\(synced\).md
+ assert_success
+}
+
+@test "$TEST_PREFIX should NOT include other markdown files in wiki/ dir" {
+ echo "" > CONTRIBUTING.md
+ echo "" > SECURITY.md
+ echo "" > TEST.md
+
+ $SCRIPT_PATH
+
+ # expect 3 files
+ output=$(ls -A1q wiki | wc -l | tr -d ' ')
+ assert_equal "$output" "3"
+}
\ No newline at end of file
diff --git a/qa/scripts/workflows/verify-merge.bats b/qa/scripts/workflows/verify-merge.bats
new file mode 100644
index 0000000..eb4a494
--- /dev/null
+++ b/qa/scripts/workflows/verify-merge.bats
@@ -0,0 +1,44 @@
+#!/usr/bin/env ../../..libs/bats/bin/bats
+load '../../../lib/bats-support/load'
+load '../../../lib/bats-assert/load'
+
+SCRIPT_DIR="$BATS_TEST_DIRNAME"/../../../scripts/workflows
+
+TEST_PREFIX="verify-merge.sh -";
+
+@test "$TEST_PREFIX should error if BRANCH is 'poc' branch" {
+ BRANCH="poc/test"
+ export BRANCH
+
+ run "$SCRIPT_DIR"/verify-merge.sh
+
+ assert_failure
+}
+
+@test "$TEST_PREFIX should error if last commit is 'wip' " {
+ BRANCH="test"
+ export BRANCH
+
+ function git() {
+ echo "wip: test"
+ }
+ export -f git
+
+ run "$SCRIPT_DIR"/verify-merge.sh
+
+ assert_failure
+}
+
+@test "$TEST_PREFIX should pass if above are NOT true" {
+ BRANCH="test"
+ export BRANCH
+
+ function git() {
+ echo "feat: test"
+ }
+ export -f git
+
+ run "$SCRIPT_DIR"/verify-merge.sh
+
+ assert_success
+}
\ No newline at end of file
diff --git a/scripts/bin/README.md b/scripts/bin/README.md
new file mode 100644
index 0000000..1a33c18
--- /dev/null
+++ b/scripts/bin/README.md
@@ -0,0 +1,14 @@
+# Developer Scripts
+
+The scripts in this directory should be used by developers, they can help with development tasks that require multiple processes and are easier automated.
+
+This includes:
+
+## lint.sh
+- Runs the linting programs to ensure the style guide is met
+
+
+## test.sh
+- Runs the test files to prevent regressions
+ - run all tests if no arguments are passed (or `-a/--all`)
+ - or will try to find a specific file to run with the `-f/--file` argument
\ No newline at end of file
diff --git a/scripts/bin/lint.sh b/scripts/bin/lint.sh
new file mode 100755
index 0000000..ab71f66
--- /dev/null
+++ b/scripts/bin/lint.sh
@@ -0,0 +1,28 @@
+#! /bin/bash
+
+DIR=$(dirname "$0")
+
+lint_scripts() {
+ if [[ ! -f "$DIR/../../lib/shellcheck*/" ]]; then
+ pushd "$DIR"/../../lib/ || exit
+ if [[ "$OSTYPE" == "linux-gnu"* ]]; then
+ tar -xf shellcheck*linux*.tar*
+ elif [[ "$OSTYPE" == "darwin"* ]]; then
+ tar -xf shellcheck*darwin*.tar*
+ else
+ echo "Error: OS not supported ($OSTYPE)"
+ exit 1
+ fi
+ popd || exit
+ fi
+
+ # shellcheck disable=SC2211,SC2046
+ "$DIR"/../../lib/shellcheck*/shellcheck $(find "$DIR"/../../scripts/**/*.sh -name '*.sh')
+}
+
+
+main() {
+ lint_scripts
+}
+
+main "$@"
\ No newline at end of file
diff --git a/scripts/bin/test.sh b/scripts/bin/test.sh
new file mode 100755
index 0000000..27c02a5
--- /dev/null
+++ b/scripts/bin/test.sh
@@ -0,0 +1,24 @@
+#! /bin/bash
+
+DIR=$(dirname "$0")
+
+find_script_test() {
+ "$DIR"/../../lib/bats-core/bin/bats "$@"
+}
+
+all_script_tests() {
+ "$DIR"/../../lib/bats-core/bin/bats "$DIR"/../../qa/ -r
+}
+
+main() {
+ case "$1" in
+ --file | -f)
+ find_script_test "${@: 2}"
+ ;;
+ --all | -a | *)
+ all_script_tests
+ ;;
+ esac
+}
+
+main "$@"
\ No newline at end of file
diff --git a/scripts/hooks/branch-name.sh b/scripts/hooks/branch-name.sh
index b7af4cc..68a634f 100755
--- a/scripts/hooks/branch-name.sh
+++ b/scripts/hooks/branch-name.sh
@@ -9,13 +9,13 @@
# set directory for calling other scripts
# NOTE: expect this to be called in this directory
-DIR=`dirname $0`
+DIR=$(dirname "$0")
main() {
# get current branch name
- local branch="$(git rev-parse --abbrev-ref HEAD)"
+ branch="$(git rev-parse --abbrev-ref HEAD)"
# ignore `patch-*` branches
if [[ $branch =~ patch-[0-9]+.[0-9]+.[0-9]+ ]]; then
@@ -23,15 +23,15 @@ main() {
fi
# get prefixes from shared list
- local PREFIXES=`$DIR/prefix-list.sh`
+ PREFIXES=$("$DIR"/prefix-list.sh)
# create regexp for branch names
- local regexp="^($(echo "${PREFIXES[@]}" | sed "s/ /|/g"))\/[A-Za-z0-9._\-]+$"
+ regexp="^(${PREFIXES[*]// /|})\/[A-Za-z0-9._\-]+$"
# check that current branch matches regexp
if [[ ! $branch =~ $regexp ]]; then
# error if not found in list
- return -1
+ return 1
fi
}
diff --git a/scripts/hooks/branch-protections.sh b/scripts/hooks/branch-protections.sh
index fc7983a..a1ee588 100755
--- a/scripts/hooks/branch-protections.sh
+++ b/scripts/hooks/branch-protections.sh
@@ -1,22 +1,24 @@
#! /bin/bash
# Script to check github branch protections and prevent commits to protected branches
-BLOCKED_BRANCH=( main, develop )
+BLOCKED_BRANCH=( main develop )
BLOCKED_PREFIX=( release )
-BRANCH=`git rev-parse --abbrev-ref HEAD`
+BRANCH=$(git rev-parse --abbrev-ref HEAD)
github() {
- local REMOTE=`git status -sb | sed -n "/##/p" | sed "s/.*\.\.\.//" | sed "s/\/.*//"`
+ REMOTE=$(git status -sb | sed -n "/##/p" | sed "s/.*\.\.\.//" | sed "s/\/.*//")
if [[ ! $REMOTE =~ "##" ]]; then
- local URL=`git config --get remote."$REMOTE".url`
+ URL=$(git config --get remote."$REMOTE".url)
+ # shellcheck disable=SC2076
if [[ $URL =~ "github.com" ]]; then
- local SPLIT=(`echo $URL | sed "s/.*://" | sed "s/\.git$//" | sed "s/\// /" `)
- local OWNER=${SPLIT[0]}
- local REPO=${SPLIT[1]}
+ # shellcheck disable=SC2034,SC2207
+ SPLIT=( $(echo "$URL" | sed "s/.*://" | sed "s/\.git$//" | sed "s/\// /" ) )
+ #OWNER=${SPLIT[0]}
+ #REPO=${SPLIT[1]}
#echo $OWNER
#echo $REPO
@@ -41,12 +43,12 @@ main() {
github
# compare against branch name/prefixes defined in here
- if [[ "${BLOCKED_BRANCH[@]}" =~ $BRANCH ]]; then
- return -1
+ if [[ "${BLOCKED_BRANCH[*]}" =~ $BRANCH ]]; then
+ return 1;
fi
for PREFIX in "${BLOCKED_PREFIX[@]}"; do
if [[ $BRANCH == $PREFIX* ]]; then
- return -1
+ return 1;
fi
done
diff --git a/scripts/hooks/commit-msg.sh b/scripts/hooks/commit-msg.sh
index 19705dc..c21f7fd 100755
--- a/scripts/hooks/commit-msg.sh
+++ b/scripts/hooks/commit-msg.sh
@@ -2,23 +2,24 @@
# Script to verify that commit message matches conventions
# set directory for calling other scripts
-DIR=`dirname "$0"`
+DIR=$(dirname "$0")
# if in hook, then prep PATH to find in repo `scripts/hooks/` dir
+# shellcheck disable=SC2076
if [[ $DIR =~ ".git" ]]; then
DIR+="/../../scripts/hooks"
fi
MSG_PREFIXES=( 'wip' )
-OTHER_PREFIXES=`$DIR/prefix-list.sh`
+OTHER_PREFIXES=$("$DIR"/prefix-list.sh)
COMMIT_MSG_ERROR=" ! Invalid commit message "
main() {
- COMMIT_MSG=`cat $1 | sed -n "/^[^#]/p"`
- FIRST_LINE=`echo $COMMIT_MSG | sed -n "/[^\w]*$/p" | sed "s/^ *//" | sed "s/\n//" | head`
+ COMMIT_MSG=$(sed -n "/^[^#]/p" "$1")
+ FIRST_LINE=$(echo "$COMMIT_MSG" | sed -n "/[^\w]*$/p" | sed "s/^ *//" | sed "s/\n//" | head)
# COMMIT_WORD_COUNT=`cat $1 | sed -n "/^[^#]/p" | wc -w | sed "s/\w//"`
# COMMIT_LINE_COUNT=`cat $1 | sed -n "/^[^#]/p" | wc -l | sed "s/\w//"`
@@ -28,17 +29,17 @@ main() {
# create regexp for first line of commit message -- [square brackets] are optional: [(scope)][!]:
# scope provides more details
# ! indicates BREAKING CHANGES
- regexp="^($(echo "${MSG_PREFIXES[@]} ${OTHER_PREFIXES[@]}" | sed "s/ /|/g"))(\([a-zA-Z0-9 \-]*\))?\!?\:[A-Za-z0-9\._\-\s]*"
+ regexp="^($(echo "${MSG_PREFIXES[*]} ${OTHER_PREFIXES[*]}" | sed "s/ /|/g"))(\([a-zA-Z0-9 \-]*\))?\!?\:[A-Za-z0-9\._\-\s]*"
# check that first line of message matches regexp
if [[ ! $FIRST_LINE =~ $regexp ]]; then
echo "$(tput setaf 1)$(tput setab 7)$COMMIT_MSG_ERROR$(tput sgr 0)"
echo " :"
- echo "prefix options: ($OTHER_PREFIXES $MSG_PREFIXES)"
- exit -1
+ echo "prefix options: ($OTHER_PREFIXES ${MSG_PREFIXES[*]})"
+ exit 1
fi
}
-main $1
+main "$1"
diff --git a/scripts/hooks/post-commit.sh b/scripts/hooks/post-commit.sh
index c25f425..7ad753d 100755
--- a/scripts/hooks/post-commit.sh
+++ b/scripts/hooks/post-commit.sh
@@ -10,7 +10,7 @@
DIFF_BRANCH=develop
# find last commit with "(#)" in commit message
-LAST_MERGE=`git log $DIFF_BRANCH..HEAD --pretty=oneline | sed -n "/\(#[0-9]*\)/p" | head -1 | sed "s/ .*//"`
+LAST_MERGE=$(git log $DIFF_BRANCH..HEAD --pretty=oneline | sed -n "/\(#[0-9]*\)/p" | head -1 | sed "s/ .*//")
# if not exists since $DIFF_BRANCH then just use $DIFF_BRANCH
if [ -z "$LAST_MERGE" ]; then
@@ -30,16 +30,16 @@ NEW_BRANCH_CMDS="Remove warning: Create new branch with 'git checkout -b /"
echo "prefix options: ($($DIR/prefix-list.sh))"
- return -1
+ return 1
fi
}
diff --git a/scripts/hooks/pre-push.sh b/scripts/hooks/pre-push.sh
index ba6e2dd..8c0dd84 100755
--- a/scripts/hooks/pre-push.sh
+++ b/scripts/hooks/pre-push.sh
@@ -1,9 +1,10 @@
#! /bin/bash
# set directory for calling other scripts
-DIR=`dirname "$0"`
+DIR=$(dirname "$0")
# if in hook, then prep PATH to find in repo `scripts/hooks/` dir
+# shellcheck disable=SC2076
if [[ $DIR =~ ".git" ]]; then
DIR+="/../../scripts/hooks"
fi
@@ -14,12 +15,11 @@ BRANCH_NAME_ERROR=" ! Branch name does not match conventions "
main() {
# Call branch name script
- $DIR/branch-name.sh
- if [ $? -ne 0 ]; then
+ if ! $DIR/branch-name.sh; then
echo "$(tput setaf 1)$(tput setab 7)$BRANCH_NAME_ERROR$(tput sgr 0)"
echo " /"
echo "prefix options: ($($DIR/prefix-list.sh -o))"
- return -1
+ return 1;
fi
}
diff --git a/scripts/hooks/prefix-list.sh b/scripts/hooks/prefix-list.sh
index 0c3665a..83d0016 100755
--- a/scripts/hooks/prefix-list.sh
+++ b/scripts/hooks/prefix-list.sh
@@ -4,19 +4,28 @@ OTHER_TYPES=( 'feat' 'fix' 'bugfix' 'perf' 'test' )
# set directory for calling other scripts
# NOTE: expect this to be called in this directory
-DIR=`dirname $0`
-
+DIR=$(dirname "$0")
main() {
# get allowed names from labels.yaml
- LABEL_TYPES=( `less $DIR/../../.github/labels.yaml | sed -n "/name/p" | sed "s/- name: \"//" | sed "s/\"//" | sed -n "/^[a-z]*$/p"` )
+ # shellcheck disable=SC2207
+ LABEL_TYPES=( $(less "$DIR"/../../.github/labels.yaml | sed -n "/name/p" | sed "s/- name: \"//" | sed "s/\"//" | sed -n "/^[a-z]*$/p") )
# merge labels.yaml with hardcoded
- local PREFIXES=( "${LABEL_TYPES[@]}" "${OTHER_TYPES[@]}" )
+ local PREFIXES=( "${LABEL_TYPES[*]}" "${OTHER_TYPES[*]}" )
+
+ echo "${PREFIXES[*]}"
- echo "${PREFIXES[@]}"
+}
+## For BATS testing
+mock() {
+ echo "$BATS_PREFIX_LIST"
}
-main
+if [ -z "$BATS_PREFIX_LIST" ]; then
+ main
+else
+ mock
+fi
diff --git a/scripts/release/release-cut-check.sh b/scripts/release/release-cut-check.sh
index 9b755b0..b27c5a1 100755
--- a/scripts/release/release-cut-check.sh
+++ b/scripts/release/release-cut-check.sh
@@ -1,8 +1,7 @@
#! /bin/bash
-git branch -a | grep $RELEASE_BRANCH;
-if [ $? -eq 0 ]; then
+if git branch -a | grep "$RELEASE_BRANCH"; then
echo "::error::Release Branch Already Exists";
exit 1
fi;
\ No newline at end of file
diff --git a/scripts/release/release-prep-upmerge.sh b/scripts/release/release-prep-upmerge.sh
index 07fe0a3..f21810a 100755
--- a/scripts/release/release-prep-upmerge.sh
+++ b/scripts/release/release-prep-upmerge.sh
@@ -3,7 +3,7 @@
git checkout develop;
# Get version in `develop` (We wantt this to be version in the final README)
-VERSION=`less README.md | head -n 3`;
+# VERSION=$(less README.md | head -n 3);
# upmerge from main
git pull;
diff --git a/scripts/release/update-versions.sh b/scripts/release/update-versions.sh
index d17cef6..a312cfc 100755
--- a/scripts/release/update-versions.sh
+++ b/scripts/release/update-versions.sh
@@ -1,9 +1,9 @@
#! /bin/bash
# Open Versioned files in repo and increment version
-if [ -z $1 ]; then
+if [ -z "$1" ]; then
echo "Error: no version number"
- exit -1;
+ exit 1;
fi;
## README
diff --git a/scripts/workflows/collect-wiki.sh b/scripts/workflows/collect-wiki.sh
index 69114e1..6328053 100755
--- a/scripts/workflows/collect-wiki.sh
+++ b/scripts/workflows/collect-wiki.sh
@@ -3,36 +3,44 @@
mkdir wiki
# create `.README` file with Table of Contents to link to each
-echo "These pages are copied from from .md files in the source code. These are defined in the [collect-wiki.sh script file](https://github.com/devlinjunker/example.cii/blob/develop/scripts/workflows/collect-wiki.sh)" > wiki/.README-\(synced\).md
-echo "" >> wiki/.README-\(synced\).md
-echo "Each page name that is synced will have following name syntax: \`__README\` so it will not visible be in the 'Page List' on the right and will only be available linked below. These pages (including this) **should not be modified** because they will be overwritten on each merge to develop." >> wiki/.README-\(synced\).md
-echo "" >> wiki/.README-\(synced\).md
-echo "**Docs**" >> wiki/.README-\(synced\).md
+{
+ echo "These pages are copied from from .md files in the source code. These are defined in the [collect-wiki.sh script file](https://github.com/devlinjunker/example.cii/blob/develop/scripts/workflows/collect-wiki.sh)"
+ echo ""
+ echo "Each page name that is synced will have following name syntax: \`__README\` so it will not visible be in the 'Page List' on the right and will only be available linked below. These pages (including this) **should not be modified** because they will be overwritten on each merge to develop."
+ echo ""
+ echo "**Docs**"
+} > wiki/.README-\(synced\).md
OTHER_FILES=("./CONTRIBUTING.md" "./SECURITY.md")
-for f in "${OTHER_FILES[@]}"
+for f in ${OTHER_FILES[*]}
do
- echo $f;
+ if [ ! -f "$f" ]; then
+ echo "Error: could not find $f"
+ exit 1
+ fi
+ echo "$f";
# rename each to `__README` and place in `wiki/` directory
- wiki_name=$(echo $f | sed "s/^\.\///" | sed "s/^\.//" | sed "s/^/_/" | sed "s/\//_/g" | sed "s/\.md$/_README.md/")
- cp $f wiki/$wiki_name
- link=$(echo $f | sed "s/^\.\///" | sed "s/^\.//" | sed "s/^/_/" | sed "s/\//_/g" | sed "s/\.md$/_README/")
+ wiki_name=$(echo "$f" | sed "s/^\.\///" | sed "s/^\.//" | sed "s/^/_/" | sed "s/\//_/g" | sed "s/\.md$/_README.md/")
+ cp "$f" wiki/"$wiki_name"
+ link=$(echo "$f" | sed "s/^\.\///" | sed "s/^\.//" | sed "s/^/_/" | sed "s/\//_/g" | sed "s/\.md$/_README/")
echo "- [$f]($link)" >> wiki/.README-\(synced\).md
done
# find files in repo with README in name
+# shellcheck disable=SC2035,SC2061
README_FILES=$( find . -name *README* );
-for f in ${README_FILES[@]}
+for f in ${README_FILES[*]}
do
if [ "$f" = "./README.md" ]; then continue; fi
- echo $f;
+ if [[ "$f" =~ wiki/.* ]]; then continue; fi
+ echo "$f";
# rename each to `__README` and place in `wiki/` directory
- wiki_name=$(echo $f | sed "s/^\.\///" | sed "s/^\.//" | sed "s/^/_/" | sed "s/\//_/g")
- cp $f wiki/$wiki_name
+ wiki_name=$(echo "$f" | sed "s/^\.\///" | sed "s/^\.//" | sed "s/^/_/" | sed "s/\//_/g")
+ cp "$f" wiki/"$wiki_name"
- link=$(echo $f | sed "s/^\.\///" | sed "s/^\.//" | sed "s/^/_/" | sed "s/\//_/g" | sed "s/\.md$//")
+ link=$(echo "$f" | sed "s/^\.\///" | sed "s/^\.//" | sed "s/^/_/" | sed "s/\//_/g" | sed "s/\.md$//")
echo "- [$f]($link)" >> wiki/.README-\(synced\).md
done
diff --git a/scripts/workflows/verify-merge.sh b/scripts/workflows/verify-merge.sh
old mode 100644
new mode 100755
index 7c9127e..af87e21
--- a/scripts/workflows/verify-merge.sh
+++ b/scripts/workflows/verify-merge.sh
@@ -5,17 +5,17 @@
if [[ "$BRANCH" =~ "poc/" ]]; then
echo "Not allowed to merge POC branch"
- exit -1
+ exit 1
fi;
# need to do fetch/checkout because action just checks out sparse version of repo
git fetch
-git checkout $BRANCH
+git checkout "$BRANCH"
# get message and verify doesn't start with "wip"
-MSG=`git log $BRANCH -1 --pretty=format:"%s"`
+MSG=$(git log "$BRANCH" -1 --pretty=format:"%s")
if [[ "$MSG" = wip* ]]; then
echo "Not allowed to merge when last commit message starts with 'wip'"
- exit -1
+ exit 1
fi