Commit a9580df3 authored by Cédric OLIVIER's avatar Cédric OLIVIER
Browse files

Merge branch 'feat/component' into 'master'

feat: migrate to CI/CD component

See merge request to-be-continuous/mkdocs!47
parents 4b4649b8 c69b1e8b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ include:
    file: '/templates/validation.yml'
  - project: 'to-be-continuous/bash'
    ref: '3.3'
    file: 'templates/gitlab-ci-bash.yml'
    file: '/templates/gitlab-ci-bash.yml'
  - project: 'to-be-continuous/semantic-release'
    ref: '3.7'
    file: '/templates/gitlab-ci-semrel.yml'    
+41 −22
Original line number Diff line number Diff line
@@ -4,29 +4,52 @@ This project implements a GitLab CI/CD template to build your static website wit

## 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/mkdocs/gitlab-ci-mkdocs@2.3.1
    # 2: set/override component inputs
    inputs:
      site-dir: "build" # ⚠ 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/mkdocs'
    ref: '2.3.1'
    file: '/templates/gitlab-ci-mkdocs.yml'

variables:
  # 2: set/override template variables
  MKD_SITE_DIR: "build" # ⚠ this is only an example
```

## Global configuration

The MkDocs template uses some global configuration used throughout all jobs.

| Name                    | Description                            | Default value     |
| Input / Variable | Description                            | Default value     |
| ----------------------- | -------------------------------------- | ----------------- |
| `MKD_IMAGE`             | The Docker image used to run MkDocs    | `registry.hub.docker.com/polinux/mkdocs:latest` |
| `MKD_WORKSPACE_DIR`     | MkDocs sources directory | `.` |
| `MKD_REQUIREMENTS_FILE` | Requirements file. If the file is not found in the repository, requirements are read from the `MKD_REQUIREMENTS` variable | `requirements.txt` |
| `MKD_REQUIREMENTS`      | Space separated requirements (ignored if a requirement file is found) | `mkdocs` |
| `MKD_SITE_DIR`          | MkDocs generated site directory (relative to `$MKD_WORKSPACE_DIR`), the path will be declared as artifact | `site` |
| `MKD_PREBUILD_SCRIPT`   | Pre-build hook script | `mkdocs-pre-build.sh` |
| `image` / `MKD_IMAGE` | The Docker image used to run MkDocs    | `registry.hub.docker.com/polinux/mkdocs:latest` |
| `workspace-dir` / `MKD_WORKSPACE_DIR` | MkDocs sources directory | `.` |
| `requirements-file` / `MKD_REQUIREMENTS_FILE` | Requirements file. If the file is not found in the repository, requirements are read from the `MKD_REQUIREMENTS` variable | `requirements.txt` |
| `requirements` / `MKD_REQUIREMENTS` | Space separated requirements (ignored if a requirement file is found) | `mkdocs` |
| `site-dir`/ `MKD_SITE_DIR`          | MkDocs generated site directory (relative to `$MKD_WORKSPACE_DIR`), the path will be declared as artifact | `site` |
| `prebuild-script` / `MKD_PREBUILD_SCRIPT` | Pre-build hook script | `mkdocs-pre-build.sh` |
| `PIP_INDEX_URL` | Python repository url | _none_ |
| `PIP_OPTS`              | pip extra [options](https://pip.pypa.io/en/stable/cli/pip/#general-options) | _none_ |
| `pip-opts` / `PIP_OPTS` | pip extra [options](https://pip.pypa.io/en/stable/cli/pip/#general-options) | _none_ |

## Jobs

@@ -34,9 +57,9 @@ The MkDocs template uses some global configuration used throughout all jobs.

This job performs MkDocs **build**. It uses the following variable:

| Name                    | Description                                       | Default value     |
| Input / Variable | Description                                       | Default value     |
| ----------------------- | ------------------------------------------------- | ----------------- |
| `MKD_BUILD_ARGS`        | Arguments used by the build job                   | _none_ |
| `build-args` / `MKD_BUILD_ARGS` | Arguments used by the build job                   | _none_ |

:warning: The built documentation is generated in the `${MKD_WORKSPACE_DIR}/${MKD_SITE_DIR}` folder.
Be sure to update `MKD_SITE_DIR` if you change the output directory (via the `MKD_BUILD_ARGS` variable or the `mkdocs.yml` file).
@@ -45,11 +68,11 @@ Be sure to update `MKD_SITE_DIR` if you change the output directory (via the `MK

This job checks links with [lychee](https://github.com/lycheeverse/lychee). It uses the following variable:

| Name                    | Description                                       | Default value     |
| Input / Variable | Description                                       | Default value     |
| ----------------------- | ------------------------------------------------- | ----------------- |
| `MKD_LYCHEE_ENABLED`    | Set to `true` to enable this job                  | _none_ (disabled) |
| `MKD_LYCHEE_IMAGE`      | The Docker image used to run [lychee](https://github.com/lycheeverse/lychee) | `registry.hub.docker.com/lycheeverse/lychee:latest` |
| `MKD_LYCHEE_ARGS`       | [lychee arguments](https://github.com/lycheeverse/lychee#commandline-parameters) to execute | `docs/` |
| `lychee-enabled` / `MKD_LYCHEE_ENABLED` | Set to `true` to enable this job                  | _none_ (disabled) |
| `lychee-image` / `MKD_LYCHEE_IMAGE` | The Docker image used to run [lychee](https://github.com/lycheeverse/lychee) | `registry.hub.docker.com/lycheeverse/lychee:latest` |
| `lychee-args` / `MKD_LYCHEE_ARGS` | [lychee arguments](https://github.com/lycheeverse/lychee#commandline-parameters) to execute | `docs/` |

## Publishing

@@ -68,11 +91,7 @@ If you wish to use it, add the following to your `gitlab-ci.yml`:
```yaml
include:
  # main template
  - project: 'to-be-continuous/mkdocs'
    ref: '2.3.1'
    file: '/templates/gitlab-ci-mkdocs.yml'
  - component: gitlab.com/to-be-continuous/mkdocs/gitlab-ci-mkdocs@2.3.1
  # GitLab pages variant
  - project: 'to-be-continuous/mkdocs'
    ref: '2.3.1'
    file: '/templates/gitlab-ci-mkdocs-pages.yml'
  - component: gitlab.com/to-be-continuous/mkdocs/gitlab-ci-mkdocs-pages@2.3.1
```
+2 −2
Original line number Diff line number Diff line
@@ -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
+8 −5
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@
  "description": "Build your static website with [MkDocs](https://www.mkdocs.org/)",
  "template_path": "templates/gitlab-ci-mkdocs.yml",
  "kind": "build",
  "prefix": "mkd",
  "is_component": true,
  "variables": [
    {
      "name": "MKD_IMAGE",
@@ -20,6 +22,12 @@
      "default": ".",
      "advanced": true
    },
    {
      "name": "MKD_SITE_DIR",
      "description": "MkDocs generated site directory (relative to `$MKD_WORKSPACE_DIR`)",
      "default": "site",
      "advanced": true
    },
    {
      "name": "MKD_REQUIREMENTS_FILE",
      "description": "Requirements file. If the file is not found in the repository, requirements are read from the `MKD_REQUIREMENTS` variable",
@@ -38,11 +46,6 @@
      "default": "mkdocs-pre-build.sh",
      "advanced": true
    },
    {
      "name": "PIP_INDEX_URL",
      "description": "Python repository url",
      "advanced": true
    },
    {
      "name": "PIP_OPTS",
      "description": "pip extra [options](https://pip.pypa.io/en/stable/cli/pip/#general-options)",
+26.6 KiB (28.4 KiB)
Loading image diff...
Loading