diff --git a/README.md b/README.md index 972363c27702a5a5510b0bcb361d65d9bf2df29a..1ae3c61bb1974c34f5e34984f58cdd0c33aca00d 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,36 @@ This project implements a GitLab CI/CD template to test and analyse your shell c ## Usage -In order to include this template in your project, add the following to your `.gitlab-ci.yml`: +This template can be used both as a [CI/CD component](https://docs.gitlab.com/ee/ci/components/#use-a-component-in-a-cicd-configuration) +or using the legacy [`include:project`](https://docs.gitlab.com/ee/ci/yaml/index.html#includeproject) syntax. + +### Use as a CI/CD component + +Add the following to your `gitlab-ci.yml`: ```yaml include: + # 1: include the component + - component: gitlab.com/to-be-continuous/bash/gitlab-ci-bash@3.3.0 + # 2: set/override component inputs + inputs: + bats-enabled: true # ⚠ this is only an example +``` + +### Use as a CI/CD template (legacy) + +Add the following to your `gitlab-ci.yml`: + +```yaml +include: + # 1: include the template - project: 'to-be-continuous/bash' ref: '3.3.0' file: '/templates/gitlab-ci-bash.yml' + +variables: + # 2: set/override template variables + BASH_BATS_ENABLED: "true" # ⚠ this is only an example ``` ## Jobs @@ -19,12 +42,12 @@ include: This job performs a static analysis of your shell scripts using [ShellCheck](https://github.com/koalaman/shellcheck). -| Name | Description | Default value | +| Input / Variable | Description | Default value | | ----------------------- | -------------------------------------- | ----------------- | -| `BASH_SHELLCHECK_DISABLED` | Set to `true` to disable ShellCheck | _none_ (enabled) | -| `BASH_SHELLCHECK_IMAGE` | The Docker image used to run [ShellCheck](https://github.com/koalaman/shellcheck) | `registry.hub.docker.com/koalaman/shellcheck-alpine:stable` | -| `BASH_SHELLCHECK_FILES` | Shell file(s) pattern to analyse | `**/*.sh` | -| `BASH_SHELLCHECK_OPTS` | ShellCheck [options](https://github.com/koalaman/shellcheck/blob/master/shellcheck.1.md) | _none_ | +| `shellcheck-disabled` / `BASH_SHELLCHECK_DISABLED` | Set to `true` to disable ShellCheck | _none_ (enabled) | +| `shellcheck-image` / `BASH_SHELLCHECK_IMAGE` | The Docker image used to run [ShellCheck](https://github.com/koalaman/shellcheck) | `registry.hub.docker.com/koalaman/shellcheck-alpine:stable` | +| `shellcheck-files` / `BASH_SHELLCHECK_FILES` | Shell file(s) pattern to analyse | `**/*.sh` | +| `shellcheck-opts` / `BASH_SHELLCHECK_OPTS` | ShellCheck [options](https://github.com/koalaman/shellcheck/blob/master/shellcheck.1.md) | _none_ | ### `bash-bats` job @@ -32,13 +55,13 @@ This job performs unit tests based on [Bats](https://bats-core.readthedocs.io/) The job uses the following variables: -| Name | Description | Default value | +| Input / Variable | Description | Default value | | ----------------------- | -------------------------------------- | ----------------- | -| `BASH_BATS_ENABLED` | Set to `true` to enable bats tests | _none_ (disabled) | -| `BASH_BATS_IMAGE` | The Docker image used to run [Bats](https://hub.docker.com/r/bats/bats) | `registry.hub.docker.com/bats/bats:latest` | -| `BASH_BATS_TESTS` | The path to a Bats test file, or the path to a directory containing Bats test files | `tests` | -| `BASH_BATS_OPTS` | Bats [options](https://bats-core.readthedocs.io/en/stable/usage.html) | _none_ | -| `BASH_BATS_LIBRARIES` | Coma separated list of Bats [libraries and add-ons](https://bats-core.readthedocs.io/en/stable/writing-tests.html#libraries-and-add-ons) (formatted as `lib_name_1@archive_url_1 lib_name_2@archive_url_2 ...`) | _none_ | +| `bats-enabled` / `BASH_BATS_ENABLED` | Set to `true` to enable bats tests | _none_ (disabled) | +| `bats-image` / `BASH_BATS_IMAGE` | The Docker image used to run [Bats](https://hub.docker.com/r/bats/bats) | `registry.hub.docker.com/bats/bats:latest` | +| `bats-tests` / `BASH_BATS_TESTS` | The path to a Bats test file, or the path to a directory containing Bats test files | `tests` | +| `bats-opts` / `BASH_BATS_OPTS` | Bats [options](https://bats-core.readthedocs.io/en/stable/usage.html) | _none_ | +| `bats-libraries` / `BASH_BATS_LIBRARIES` | Coma separated list of Bats [libraries and add-ons](https://bats-core.readthedocs.io/en/stable/writing-tests.html#libraries-and-add-ons) (formatted as `lib_name_1@archive_url_1 lib_name_2@archive_url_2 ...`) | _none_ | In addition to a textual report in the console, this job produces the following reports, kept for one day: diff --git a/bumpversion.sh b/bumpversion.sh index f06829a406ca8da98e570e8ad7d8bb22367b668d..ed44d7b68b0e09f6d2cf557f7a15e52553246341 100755 --- a/bumpversion.sh +++ b/bumpversion.sh @@ -27,13 +27,13 @@ if [[ "$curVer" ]]; then log_info "Bump version from \\e[33;1m${curVer}\\e[0m to \\e[33;1m${nextVer}\\e[0m (release type: $relType)..." # replace in README - sed -e "s/ref: '$curVer'/ref: '$nextVer'/" README.md > README.md.next + sed -e "s/ref: *'$curVer'/ref: '$nextVer'/" -e "s/ref: *\"$curVer\”/ref: \”$nextVer\”/" -e "s/component: *\(.*\)@$curVer/component: \1@$nextVer/" README.md > README.md.next mv -f README.md.next README.md # replace in template and variants for tmpl in templates/*.yml do - sed -e "s/\"$curVer\"/\"$nextVer\"/" "$tmpl" > "$tmpl.next" + sed -e "s/command: *\[\"--service\", \"\(.*\)\", \"$curVer\"\]/command: [\"--service\", \"\1\", \"$nextVer\"]/" "$tmpl" > "$tmpl.next" mv -f "$tmpl.next" "$tmpl" done else diff --git a/kicker.json b/kicker.json index 7457b75a5c7675c4c0aca61d94d50c6b35aa51e6..fcb04595070c259753a45936c539accc51a501dd 100644 --- a/kicker.json +++ b/kicker.json @@ -3,6 +3,8 @@ "description": "Test and analyse your shell code", "template_path": "templates/gitlab-ci-bash.yml", "kind": "build", + "prefix": "bash", + "is_component": true, "features": [ { "id": "shellcheck", diff --git a/logo.png b/logo.png index abbd377dd0e3755ab918cc71cb5402551a8a156a..626db6146c3eed4930dff68bb537f68e5f4c7c64 100644 Binary files a/logo.png and b/logo.png differ diff --git a/templates/gitlab-ci-bash.yml b/templates/gitlab-ci-bash.yml index b130e4eb59701bf97b8a6b4182bc76829ba3c771..d7c751f07da6f0601147bdb57db76add49bf12c3 100644 --- a/templates/gitlab-ci-bash.yml +++ b/templates/gitlab-ci-bash.yml @@ -13,6 +13,43 @@ # program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth # Floor, Boston, MA 02110-1301, USA. # ========================================================================================= +spec: + inputs: + shellcheck-disabled: + description: Disable ShellCheck + type: boolean + default: false + shellcheck-image: + description: The Docker image used to run [ShellCheck](https://github.com/koalaman/shellcheck) + default: registry.hub.docker.com/koalaman/shellcheck-alpine:stable + shellcheck-files: + description: Shell file(s) pattern to analyse + default: '**/*.sh' + shellcheck-opts: + description: ShellCheck [options](https://github.com/koalaman/shellcheck/blob/master/shellcheck.1.md) + default: '' + bats-enabled: + description: Enable Bats + type: boolean + default: false + bats-image: + description: The Docker image used to run [Bats](https://hub.docker.com/r/bats/bats) + default: registry.hub.docker.com/bats/bats:latest + bats-tests: + description: The path to a Bats test file, or the path to a directory containing Bats test files + default: tests + bats-opts: + description: Bats [options](https://bats-core.readthedocs.io/en/stable/usage.html) + default: '' + bats-libraries: + description: |- + Coma separated list of Bats [libraries and add-ons](https://bats-core.readthedocs.io/en/stable/writing-tests.html#libraries-and-add-ons) + + Formatted as: `lib_name_1@archive_url_1 lib_name_2@archive_url_2 ...` + + Example: `bats-support@https://github.com/bats-core/bats-support/archive/v0.3.0.zip bats-assert@https://github.com/bats-core/bats-assert/archive/v2.0.0.zip` + default: '' +--- # default workflow rules: Merge Request pipelines workflow: rules: @@ -56,19 +93,25 @@ workflow: variables: # variabilized tracking image - TBC_TRACKING_IMAGE: "registry.gitlab.com/to-be-continuous/tools/tracking:master" + TBC_TRACKING_IMAGE: registry.gitlab.com/to-be-continuous/tools/tracking:master - BASH_BATS_IMAGE: "registry.hub.docker.com/bats/bats:latest" - BASH_BATS_TESTS: "tests" + BASH_BATS_IMAGE: $[[ inputs.bats-image ]] + BASH_BATS_TESTS: $[[ inputs.bats-tests ]] - BASH_SHELLCHECK_IMAGE: "registry.hub.docker.com/koalaman/shellcheck-alpine:stable" - BASH_SHELLCHECK_FILES: "**/*.sh" + BASH_SHELLCHECK_IMAGE: $[[ inputs.shellcheck-image ]] + BASH_SHELLCHECK_FILES: $[[ inputs.shellcheck-files ]] # default production ref name (pattern) PROD_REF: '/^(master|main)$/' # default integration ref name (pattern) INTEG_REF: '/^develop$/' + BASH_SHELLCHECK_DISABLED: $[[ inputs.shellcheck-disabled ]] + BASH_SHELLCHECK_OPTS: $[[ inputs.shellcheck-opts ]] + BASH_BATS_ENABLED: $[[ inputs.bats-enabled ]] + BASH_BATS_OPTS: $[[ inputs.bats-opts ]] + BASH_BATS_LIBRARIES: $[[ inputs.bats-libraries ]] + stages: - build - test