diff --git a/.github/workflows/auto-label.yaml b/.github/workflows/auto-label.yaml index c10d00f..7d91193 100644 --- a/.github/workflows/auto-label.yaml +++ b/.github/workflows/auto-label.yaml @@ -30,7 +30,7 @@ jobs: - name: Remove WIP Status Label if: github.event.action == 'closed' - uses: actions-ecosystem/action-remove-labels@v1.1.0 + uses: actions-ecosystem/action-remove-labels@v1.1.1 continue-on-error: true with: github_token: ${{ secrets.github_token }} @@ -38,7 +38,7 @@ jobs: - name: Remove Blocked Status Label if: github.event.action == 'closed' - uses: actions-ecosystem/action-remove-labels@v1.1.0 + uses: actions-ecosystem/action-remove-labels@v1.1.1 continue-on-error: true with: github_token: ${{ secrets.github_token }} diff --git a/.github/workflows/release-on-merge.yaml b/.github/workflows/release-on-merge.yaml index d3affde..0a5b637 100644 --- a/.github/workflows/release-on-merge.yaml +++ b/.github/workflows/release-on-merge.yaml @@ -9,6 +9,8 @@ on: push: branches: - release-* + paths-ignore: + - 'README.md' # ignore changes to README as we edit this when creating release branch jobs: create-release-tag: diff --git a/README.md b/README.md index 0e2e79d..11371ec 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ --- -Version: 0.4.0 +Version: 0.5.0 --- # Example - CII 100% diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 0000000..03014fd --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,14 @@ +# Script Files +This directory contains script files to help with developer workflows, for now these are shell scripts. But if desired, we could replace these with node or python scripts instead. + +## Conventions + - Add `set -eu` to top of shell scripts when possible + - `set -e` causes the script to exit if any errors occur + - `set -u` causes the script to error if any undeclared variables are encountered + - Linting with [Shellcheck] for ideal formatting to prevent errors + - Unit Testing with [BATS] (Bash Automatic Testing System) + - Ideally wrap code in `main` method and then invoke at the end of script + + +[ShellCheck]: https://www.shellcheck.net/ +[BATS]: https://bats-core.readthedocs.io/ \ No newline at end of file diff --git a/scripts/bin/lint.sh b/scripts/bin/lint.sh index 5d6aa32..3a524d9 100755 --- a/scripts/bin/lint.sh +++ b/scripts/bin/lint.sh @@ -1,5 +1,10 @@ #! /bin/bash +# cannot `set -u` here because `if [[ -z "$BATS_TMPDIR" ]];` errors +## if we enforce bash version 4.2 then we can use `if [ -v BATS_TMPDIR ]` to check +## and then can `set -u` here +set -e + DIR=$(dirname "$0") lint_scripts() { diff --git a/scripts/bin/test.sh b/scripts/bin/test.sh index 44463dc..8c0b167 100755 --- a/scripts/bin/test.sh +++ b/scripts/bin/test.sh @@ -1,5 +1,10 @@ #! /bin/bash +# cannot `set -u` here because `if [[ -z "$BATS_TMPDIR" ]];` errors +## if we enforce bash version 4.2 then we can use `if [ -v BATS_TMPDIR ]` to check +## and then can `set -u` here +set -e + DIR=$(dirname "$0") find_script_test() { diff --git a/scripts/hooks/commit-msg.sh b/scripts/hooks/commit-msg.sh index 92d4329..5963fb2 100755 --- a/scripts/hooks/commit-msg.sh +++ b/scripts/hooks/commit-msg.sh @@ -1,6 +1,8 @@ #! /bin/bash # Script to verify that commit message matches conventions +set -eu + # set directory for calling other scripts DIR=$(dirname "${BASH_SOURCE[0]}") # if in hook, then prep PATH to find in repo `scripts/hooks/` dir diff --git a/scripts/hooks/internal/branch-name.sh b/scripts/hooks/internal/branch-name.sh index 2fb6c97..b5fc132 100755 --- a/scripts/hooks/internal/branch-name.sh +++ b/scripts/hooks/internal/branch-name.sh @@ -6,6 +6,7 @@ # # based on https://itnext.io/using-git-hooks-to-enforce-branch-naming-policy-ffd81fa01e5e +set -eu # set directory for calling other scripts # NOTE: expect this to be called in this directory diff --git a/scripts/hooks/internal/branch-protections.sh b/scripts/hooks/internal/branch-protections.sh index a1ee588..fdaaccd 100755 --- a/scripts/hooks/internal/branch-protections.sh +++ b/scripts/hooks/internal/branch-protections.sh @@ -1,6 +1,8 @@ #! /bin/bash # Script to check github branch protections and prevent commits to protected branches +set -eu + BLOCKED_BRANCH=( main develop ) BLOCKED_PREFIX=( release ) @@ -39,9 +41,9 @@ github() { main() { - # check github branch protections - github - + # TODO: check github branch protections (skipping for now as it errors during testing) + # github + # compare against branch name/prefixes defined in here if [[ "${BLOCKED_BRANCH[*]}" =~ $BRANCH ]]; then return 1; diff --git a/scripts/hooks/internal/prefix-list.sh b/scripts/hooks/internal/prefix-list.sh index 659f9e5..5321cdc 100755 --- a/scripts/hooks/internal/prefix-list.sh +++ b/scripts/hooks/internal/prefix-list.sh @@ -1,5 +1,10 @@ #! /bin/bash +# cannot `set -u` here because `if [ -z "$BATS_PREFIX_LIST" ];` errors +## if we enforce bash version 4.2 then we can use `if [ -v BATS_PREFIX_LIST ]` to check +## and then can `set -u` here +set -e + OTHER_TYPES=( 'feat' 'fix' 'bugfix' 'perf' 'test' ) # set directory for calling other scripts diff --git a/scripts/hooks/post-commit.sh b/scripts/hooks/post-commit.sh index 7f7d086..e3b6d8f 100755 --- a/scripts/hooks/post-commit.sh +++ b/scripts/hooks/post-commit.sh @@ -1,6 +1,7 @@ #! /bin/bash # Checks that the git diff is not getting to big and warns if it is +set -eu # TODO: better way to determine the branch/commit we want to check against? # for now look back until DIFF_BRANCH and find other merge commits -- those with (#..) in the commit message diff --git a/scripts/hooks/pre-commit.sh b/scripts/hooks/pre-commit.sh index 97b3064..ac41d2e 100755 --- a/scripts/hooks/pre-commit.sh +++ b/scripts/hooks/pre-commit.sh @@ -2,6 +2,8 @@ # Pre-commit githook to run before every commit to validate it locally # 1. Check that branch name matches conventions (branch-name.sh) +set -eu + # set directory for calling other scripts DIR=$(dirname "${BASH_SOURCE[0]}") diff --git a/scripts/hooks/pre-push.sh b/scripts/hooks/pre-push.sh index 946ed5e..5b7ffcd 100755 --- a/scripts/hooks/pre-push.sh +++ b/scripts/hooks/pre-push.sh @@ -1,5 +1,7 @@ #! /bin/bash +set -eu + # set directory for calling other scripts DIR=$(dirname "${BASH_SOURCE[0]}") diff --git a/scripts/release/patch-cut-check.sh b/scripts/release/patch-cut-check.sh index 8a0997e..4786dc5 100755 --- a/scripts/release/patch-cut-check.sh +++ b/scripts/release/patch-cut-check.sh @@ -1,5 +1,7 @@ #! /bin/bash +set -eu + if [[ "$1" != "main" && "$1" != "release-"* ]]; then echo "::error::Cannot Cut Patch off of non 'release-*' or 'main' branch"; exit 1 diff --git a/scripts/release/release-cut-check.sh b/scripts/release/release-cut-check.sh index b27c5a1..cd43378 100755 --- a/scripts/release/release-cut-check.sh +++ b/scripts/release/release-cut-check.sh @@ -1,5 +1,6 @@ #! /bin/bash +set -eu if git branch -a | grep "$RELEASE_BRANCH"; then echo "::error::Release Branch Already Exists"; diff --git a/scripts/release/release-prep-upmerge.sh b/scripts/release/release-prep-upmerge.sh index 68b0e2c..d0629a1 100755 --- a/scripts/release/release-prep-upmerge.sh +++ b/scripts/release/release-prep-upmerge.sh @@ -1,5 +1,7 @@ #! /bin/bash +set -eu + git checkout develop; # Get version in `develop` (We wantt this to be version in the final README) @@ -7,7 +9,7 @@ git checkout develop; # upmerge from branch input git pull; -git merge "$1"; +git merge "$1" 2>/dev/null; # ignore error we expect here # TODO: Resolve conflicts better (maybe https://github.com/jakub-g/git-resolve-conflict) git reset README.md; diff --git a/scripts/release/update-versions.sh b/scripts/release/update-versions.sh index a312cfc..afe6f10 100755 --- a/scripts/release/update-versions.sh +++ b/scripts/release/update-versions.sh @@ -1,7 +1,10 @@ #! /bin/bash # Open Versioned files in repo and increment version -if [ -z "$1" ]; then +set -eu + +# check number of arguments first so we don't access unset variable and error with set -u +if [[ $# == 0 || -z "$1" ]]; then echo "Error: no version number" exit 1; fi; diff --git a/scripts/workflows/branch-match.sh b/scripts/workflows/branch-match.sh index 3d54d14..f2458ac 100755 --- a/scripts/workflows/branch-match.sh +++ b/scripts/workflows/branch-match.sh @@ -1,4 +1,7 @@ #! /bin/bash + +set -eu + ## Verify that BRANCH matches regexp, else error if [[ ! $BRANCH =~ $REGEXP ]]; then exit 1; diff --git a/scripts/workflows/collect-wiki.sh b/scripts/workflows/collect-wiki.sh index 3da5e1a..d5537b0 100755 --- a/scripts/workflows/collect-wiki.sh +++ b/scripts/workflows/collect-wiki.sh @@ -1,5 +1,7 @@ #! /bin/bash +set -eu + mkdir wiki # create `.README` file with Table of Contents to link to each diff --git a/scripts/workflows/verify-merge.sh b/scripts/workflows/verify-merge.sh index af87e21..19b6cfc 100755 --- a/scripts/workflows/verify-merge.sh +++ b/scripts/workflows/verify-merge.sh @@ -1,6 +1,8 @@ #! /bin/bash # Verify that a branch can be merged +set -eu + # check branch type prefix != "poc" if [[ "$BRANCH" =~ "poc/" ]]; then