diff --git a/.env-default b/.env-default new file mode 100644 index 0000000..e69de29 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8794543..f812e7a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,4 +23,5 @@ jobs: CHANGELOG_FILE: CHANGELOG.md BASH_ENV: ./lib.sh DRY_RUN: false + TAGS_FILE: tags.txt run: ./workflows/release/tag.sh diff --git a/.github/workflows/release_pr.yml b/.github/workflows/release_pr.yml index deddb4c..e2a8a9f 100644 --- a/.github/workflows/release_pr.yml +++ b/.github/workflows/release_pr.yml @@ -43,6 +43,7 @@ jobs: env: CHANGELOG_FILE: CHANGELOG.md BASH_ENV: ./lib.sh + TAGS_FILE: tags.txt run: ./workflows/release/changelog.sh "${{ inputs.url }}" "${{ inputs.title }}" "${{ inputs.tag_prefix }}" - name: Open PR diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f47a33d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,23 @@ +{ + // - - - - - - - - YAML - - - - - - - - - + "prettier.configPath": ".prettierrc.yml", + "[yaml]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + // - - - - - - - - BASH - - - - - - - - - + "shellformat.flag": "-i 2 -ln bash", + "[shellscript]": { + "editor.defaultFormatter": "foxundermoon.shell-format" + }, + "shellcheck.customArgs": ["-x"], + // - - - - - - - - OSX - - - - - - - - - + "terminal.integrated.defaultProfile.osx": "bash", + // - - - - - - - - CSPELL - - - - - - - - - + "cSpell.maxDuplicateProblems": 2, + "cSpell.showAutocompleteSuggestions": false, + "cSpell.enableFiletypes": ["shellscript"], + // "cSpell.spellCheckDelayMs": 2000, // needs to be set in user settings json + // - - - - - - - - MISC - - - - - - - - - + // https://github.com/github/vscode-github-actions/issues/222 + "github-actions.use-enterprise": true +} diff --git a/go/generate_mocks.sh b/go/generate_mocks.sh index e24fc81..e5005b0 100755 --- a/go/generate_mocks.sh +++ b/go/generate_mocks.sh @@ -48,6 +48,12 @@ rename_expect() { ### script ### ############## +if [ ! "${LIB_LOADED:-}" ]; then + echo -e "INFO ($0:$LINENO) BASH_ENV=${BASH_ENV:-}" >&2 + echo -e "FATAL ($0:$LINENO) lib.sh not found. use 'export BASH_ENV=' or 'BASH_ENV= $0'" >&2 + exit 1 +fi + if requested_help "$*"; then usage exit 1 diff --git a/go/lint_fix.sh b/go/lint_fix.sh index 20691df..427307a 100755 --- a/go/lint_fix.sh +++ b/go/lint_fix.sh @@ -76,6 +76,12 @@ lint() { ### script ### ############## +if [ ! "${LIB_LOADED:-}" ]; then + echo -e "INFO ($0:$LINENO) BASH_ENV=${BASH_ENV:-}" >&2 + echo -e "FATAL ($0:$LINENO) lib.sh not found. use 'export BASH_ENV=' or 'BASH_ENV= $0'" >&2 + exit 1 +fi + if requested_help "$*"; then usage exit 1 diff --git a/migration.sh b/migration.sh index 165c62c..8a89587 100755 --- a/migration.sh +++ b/migration.sh @@ -22,7 +22,7 @@ EOF } # Description: Validates user input -# Globals : MIGRATIONS_DIR (github workflow or .env) +# Globals : MIGRATIONS_DIR (github workflow) # Args : $@ # STDERR : Might print errors # Returns : 1 if fail @@ -31,10 +31,8 @@ validate() { local name=${1-} if [ ! "${MIGRATIONS_DIR:-}" ]; then - if ! source .env; then - err $LINENO "missing MIGRATIONS_DIR env variable" - return 1 - fi + err $LINENO "missing MIGRATIONS_DIR env variable" + return 1 fi if [ ! "$name" ]; then @@ -45,7 +43,7 @@ validate() { } # Description: Create a new timestamped migration file -# Globals : MIGRATIONS_DIR (github workflow or .env) +# Globals : MIGRATIONS_DIR (github workflow) # Args : 1=(up | down) 2=name # STDOUT : Path to the new file # Sideeffects: Creates a new file diff --git a/workflows/main/commit_lint.sh b/workflows/main/commit_lint.sh index d9b705a..7febbb2 100755 --- a/workflows/main/commit_lint.sh +++ b/workflows/main/commit_lint.sh @@ -122,6 +122,12 @@ EOF ### script ### ############## +if [ ! "${LIB_LOADED:-}" ]; then + echo -e "INFO ($0:$LINENO) BASH_ENV=${BASH_ENV:-}" >&2 + echo -e "FATAL ($0:$LINENO) lib.sh not found. use 'export BASH_ENV=' or 'BASH_ENV= $0'" >&2 + exit 1 +fi + validate lint_title lint_log diff --git a/workflows/release/changelog.sh b/workflows/release/changelog.sh index 105bb1d..7c02f16 100755 --- a/workflows/release/changelog.sh +++ b/workflows/release/changelog.sh @@ -16,15 +16,13 @@ trap 'err $LINENO' ERR ########################## # Description: Validates user input -# Globals : CHANGELOG_FILE (github workflow or .env) +# Globals : CHANGELOG_FILE (github workflow) # Returns : 1 if fail # Example : validate validate() { if [ ! "${CHANGELOG_FILE-}" ]; then - if ! source .env; then - err $LINENO "missing CHANGELOG_FILE env variable" - return 1 - fi + err $LINENO "missing CHANGELOG_FILE env variable" + return 1 fi if [ ! -f "$CHANGELOG_FILE" ]; then @@ -34,7 +32,7 @@ validate() { } # Description: Calls changelog tool and updates CHANGELOG_FILE -# Globals : CHANGELOG_FILE, TAGS_FILE (github workflow or .env) +# Globals : CHANGELOG_FILE, TAGS_FILE (github workflow) # Args : 1=url 2=title 3=prefixes # STDERR : Might print errors # Returns : 1 if fail @@ -64,5 +62,11 @@ update_changelog() { ### script ### ############## +if [ ! "${LIB_LOADED:-}" ]; then + echo -e "INFO ($0:$LINENO) BASH_ENV=${BASH_ENV:-}" >&2 + echo -e "FATAL ($0:$LINENO) lib.sh not found. use 'export BASH_ENV=' or 'BASH_ENV= $0'" >&2 + exit 1 +fi + validate update_changelog "$@" diff --git a/workflows/release/tag.sh b/workflows/release/tag.sh index ad058e3..412ba43 100755 --- a/workflows/release/tag.sh +++ b/workflows/release/tag.sh @@ -15,19 +15,25 @@ trap 'err $LINENO' ERR ########################## # Description: Exit the script if main head is doesn't match a release commit -# Globals : CHANGELOG_FILE (github workflow or .env) +# Globals : CHANGELOG_FILE, TAGS_FILE, DRY_RUN (github workflow) # STDERR : Logs -# Returns : 1 if fail -# Sideeffects: Might exit the script with success +# Sideeffects: Might exit the script with success or failure # Example : validate validate() { - local main_head release_re="chore:[[:blank:]]+release" + local main_head release_re="^chore:[[:blank:]]+release" - if [ ! "${CHANGELOG_FILE-}" ]; then - if ! source .env; then - err $LINENO "missing CHANGELOG_FILE env variable" - return 1 - fi + if [ "${DRY_RUN:-}" == "true" ]; then + DRY_RUN="echo" + else + DRY_RUN="" + fi + + if [ ! "${CHANGELOG_FILE:-}" ]; then + fatal $LINENO "missing CHANGELOG_FILE env variable" + fi + + if [ ! "${TAGS_FILE:-}" ]; then + fatal $LINENO "missing TAGS_FILE env variable" fi while read -r commit_line; do @@ -43,39 +49,22 @@ validate() { fi } -# Description: Parses tags from changelog -# Globals : CHANGELOG_FILE (github workflow or .env) +# Description: Parses tags from TAGS_FILE +# Globals : TAGS_FILE (github workflow) # STDOUT : Parsed tags # Returns : Parsed tags -# Example : tags="$(parse_changelog_tags)" -parse_changelog_tags() { - local tags=() newest_date tag date - # https://regex101.com/r/67rzeb/6 - local changelog_h1_re="#[[:blank:]]+([a-zA-Z0-9 !%&*()-+]+:)?[[:blank:]]*([a-zA-Z0-9\/.]+)[[:blank:]]+[*_]\(([[:digit:]]+-[[:digit:]]+-[[:digit:]]+)" +# Example : tags="$(parse_tags)" +parse_tags() { + local tags=() line while read -r line; do - if ! [[ "$line" =~ $changelog_h1_re ]]; then - # want only release lines, h1 in md - # one or more lines with tags + if [[ "$line" =~ ^# ]]; then + # skip doc lines continue fi - tag="${BASH_REMATCH[2]}" - date="${BASH_REMATCH[3]}" - - if [ ! "${newest_date:-}" ]; then - # want to push tags for the newest release only - # which will be in the top of the changelog - newest_date=$date - fi - - if [ "$date" != "$newest_date" ]; then - # newest release is over - break - fi - - tags+=("$tag") - done <"$CHANGELOG_FILE" + tags+=("$line") + done <"$TAGS_FILE" printf %s "${tags[*]}" } @@ -101,19 +90,13 @@ validate_tags() { } # Description: Creates and pushes git tags -# Globals : DRY_RUN bool +# Globals : DRY_RUN (github workflow) # Args : words separated by spaces # STDOUT : Prints each tag created, plus git output # STDERR : Git might output # Sideeffects: Pushes git tags -# Example : tag_and_push foo/v1.1.1. bar/v1.2.3 +# Example : tag_and_push v1.1.1. foo/v1.2.3 tag_and_push() { - if [ "${DRY_RUN:-}" == "true" ]; then - DRY_RUN="echo" - else - DRY_RUN="" - fi - for tag in "$@"; do msgln "$tag" $DRY_RUN git tag "$tag" HEAD @@ -126,9 +109,15 @@ tag_and_push() { ### script ### ############## +if [ ! "${LIB_LOADED:-}" ]; then + echo -e "INFO ($0:$LINENO) BASH_ENV=${BASH_ENV:-}" >&2 + echo -e "FATAL ($0:$LINENO) lib.sh not found. use 'export BASH_ENV=' or 'BASH_ENV= $0'" >&2 + exit 1 +fi + validate -parsed_tags="$(parse_changelog_tags)" +parsed_tags="$(parse_tags)" # shellcheck disable=SC2068 # intentional splitting validate_tags ${parsed_tags[@]} # shellcheck disable=SC2068 # intentional splitting