Skip to content
Snippets Groups Projects
Commit c85e02f0 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

feat: migrate to GitLab CI/CD component

:warning: requires GitLab 16.6 or later
parent e9caacb5
Branches
Tags
No related merge requests found
...@@ -4,13 +4,36 @@ This project implements a GitLab CI/CD template to test and analyse your shell c ...@@ -4,13 +4,36 @@ This project implements a GitLab CI/CD template to test and analyse your shell c
## Usage ## 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 ```yaml
include: 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' - project: 'to-be-continuous/bash'
ref: '3.3.0' ref: '3.3.0'
file: '/templates/gitlab-ci-bash.yml' file: '/templates/gitlab-ci-bash.yml'
variables:
# 2: set/override template variables
BASH_BATS_ENABLED: "true" # ⚠ this is only an example
``` ```
## Jobs ## Jobs
...@@ -19,12 +42,12 @@ include: ...@@ -19,12 +42,12 @@ include:
This job performs a static analysis of your shell scripts using [ShellCheck](https://github.com/koalaman/shellcheck). 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) | | `shellcheck-disabled` / `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` | | `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` |
| `BASH_SHELLCHECK_FILES` | Shell file(s) pattern to analyse | `**/*.sh` | | `shellcheck-files` / `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-opts` / `BASH_SHELLCHECK_OPTS` | ShellCheck [options](https://github.com/koalaman/shellcheck/blob/master/shellcheck.1.md) | _none_ |
### `bash-bats` job ### `bash-bats` job
...@@ -32,13 +55,13 @@ This job performs unit tests based on [Bats](https://bats-core.readthedocs.io/) ...@@ -32,13 +55,13 @@ This job performs unit tests based on [Bats](https://bats-core.readthedocs.io/)
The job uses the following variables: 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) | | `bats-enabled` / `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` | | `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` |
| `BASH_BATS_TESTS` | The path to a Bats test file, or the path to a directory containing Bats test files | `tests` | | `bats-tests` / `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_ | | `bats-opts` / `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-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: In addition to a textual report in the console, this job produces the following reports, kept for one day:
......
...@@ -27,13 +27,13 @@ if [[ "$curVer" ]]; then ...@@ -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)..." log_info "Bump version from \\e[33;1m${curVer}\\e[0m to \\e[33;1m${nextVer}\\e[0m (release type: $relType)..."
# replace in README # 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 mv -f README.md.next README.md
# replace in template and variants # replace in template and variants
for tmpl in templates/*.yml for tmpl in templates/*.yml
do 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" mv -f "$tmpl.next" "$tmpl"
done done
else else
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
"description": "Test and analyse your shell code", "description": "Test and analyse your shell code",
"template_path": "templates/gitlab-ci-bash.yml", "template_path": "templates/gitlab-ci-bash.yml",
"kind": "build", "kind": "build",
"prefix": "bash",
"is_component": true,
"features": [ "features": [
{ {
"id": "shellcheck", "id": "shellcheck",
......
logo.png

19.3 KiB | W: | H:

logo.png

14.9 KiB | W: | H:

logo.png
logo.png
logo.png
logo.png
  • 2-up
  • Swipe
  • Onion skin
...@@ -13,6 +13,43 @@ ...@@ -13,6 +13,43 @@
# program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth # program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
# Floor, Boston, MA 02110-1301, USA. # 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 # default workflow rules: Merge Request pipelines
workflow: workflow:
rules: rules:
...@@ -56,19 +93,25 @@ workflow: ...@@ -56,19 +93,25 @@ workflow:
variables: variables:
# variabilized tracking image # 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_IMAGE: $[[ inputs.bats-image ]]
BASH_BATS_TESTS: "tests" BASH_BATS_TESTS: $[[ inputs.bats-tests ]]
BASH_SHELLCHECK_IMAGE: "registry.hub.docker.com/koalaman/shellcheck-alpine:stable" BASH_SHELLCHECK_IMAGE: $[[ inputs.shellcheck-image ]]
BASH_SHELLCHECK_FILES: "**/*.sh" BASH_SHELLCHECK_FILES: $[[ inputs.shellcheck-files ]]
# default production ref name (pattern) # default production ref name (pattern)
PROD_REF: '/^(master|main)$/' PROD_REF: '/^(master|main)$/'
# default integration ref name (pattern) # default integration ref name (pattern)
INTEG_REF: '/^develop$/' 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: stages:
- build - build
- test - test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment