Commit c7081b13 authored by Thomas Boni's avatar Thomas Boni
Browse files

Merge branch '280-new-job-gulp' into 'latest'

Resolve "[New job] - Gulp"

Closes #280

See merge request r2devops/hub!148
parents a0071443 a647d842
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -152,6 +152,20 @@ trivy_image:
    TRIVY_SEVERITY: "CRITICAL"
```

### ✏ Change the default stage of job

If you want to use your own stage name it's possible to do so when including
your job.

```yaml
include:
  - remote: 'https://jobs.r2devops.io/trivy_image.yml'

trivy_image:
  stage: security
```


### 🐳 Advanced: `services`

You may want one of your job to interact with a container instance (API,

jobs/gulp/README.md

0 → 100644
+71 −0
Original line number Diff line number Diff line
## Objective

This job installs `npm` or `yarn` dependencies listed in your `package.json` and installs
 gulp to run your tasks.

## How to use it

1. Ensure that your project have
   [`package.json`](https://docs.npmjs.com/cli/v6/configuring-npm/package-json){:target="_blank"}
   file which contains the requirements
1. Ensure that your project have
   [`gulpfile.js`](https://gulpjs.com/docs/en/getting-started/javascript-and-gulpfiles/#gulpfile-explained){:target="_blank"}
   or
   [`gulpfile.ts`](https://gulpjs.com/docs/en/getting-started/javascript-and-gulpfiles/#transpilation){:target="_blank"}
   file which contains your tasks
1. Add the corresponding URL to your `.gitlab-ci.yml` file (see [Getting
   started](/use-the-hub)). Example:

    ```yaml
    include:
      - remote: 'https://jobs.r2devops.io/gulp.yml'
    ```

1. If you need to customize the job (stage, variables, ...) 👉 check the [jobs
customization](/use-the-hub/#jobs-customization)
1. Well done, your job is ready to work ! 😀


### Example of `.gitlab-ci.yml` file

If you want to [change the default stage](/use-the-hub/#change-the-default-stage-of-job), or [customize your job](/use-the-hub/#global) have a look ont the example below 👇🏽

```yaml
stages:
  - prepare-frontend

include:
  - remote: 'https://jobs.r2devops.io/gulp.yml'

gulp:
  stage: prepare-frontend
  variables:
    PROJECT_ROOT: "frontend/"
    GULP_TASKS: "generate-fonts; minify-css; minify-js; "
    GULPFILE_PATH: "config/gulpfile.js"
```

## Job details

* Job name: `gulp`
* Default stage: `others`
* Docker image: [`node:15.7-buster`](https://hub.docker.com/_/node){:target="_blank"}
* When: `always`


### Variables

!!! note
    All paths defined in variables are relative and starts from the root of your
    repository.

| Name | Description | Default |
| ---- | ----------- | ------- |
| `PROJECT_ROOT` <img width=105/>| Path to the directory containing `package.json`  | `.` |
| `PACKAGE_MANAGER` | Package manager to install your dependencies `npm` or `yarn`  | `npm` |
| `INSTALL_OPTIONS` | Additional options for the installation of `PACKAGE_MANAGER` <br/> *Ex: For npm `--save-dev`*  | ` ` |
| `GULPFILE_PATH` | Path (from `PROJECT_ROOT`) to your  gulpfile `gulpfile.js` or `gulpfile.ts`| ` ` |
| `GULP_TASKS` | List of your tasks to run with `gulp` (separated by ; ). <br/> *Ex: "minify-css; minify-js;"* | ` ` |
| `GULP_OUTPUT_FOLDER` | If needed, path to the output produced by your scripts (path relative from the `PROJECT_ROOT`) | `build` |
| `PAGES_DEPLOY` | If enabled, prepare your build result to be deployed on pages (require [pages job](jobs/deploy/pages/)) | `false` |
| `PAGES_FOLDER` | Path where to copy the output to be exposed for deployment on [pages](jobs/deploy/pages/) (path relative from the root of the repository) | `./website_build` |

jobs/gulp/gulp.yml

0 → 100644
+56 −0
Original line number Diff line number Diff line
#Job from R2Devops hub --> r2devops.io

stages:
  - others

gulp:
  stage: others
  image:
    name: node:15.7-buster
    entrypoint: [""]
  variables:
    PROJECT_ROOT: "."
    PACKAGE_MANAGER: "npm"
    INSTALL_OPTIONS: ""
    GULPFILE_PATH: "."
    GULP_TASKS: ""
    GULP_OUTPUT_FOLDER: "./build/"
    # Deploy on pages
    PAGES_DEPLOY: "false"
    PAGES_FOLDER: "./website_build"
  script:
    # Working directory
    - cd $PROJECT_ROOT
    # Run npm or yarn install
    - $PACKAGE_MANAGER install $INSTALL_OPTIONS

    # Install global gulp for npm
    - if [ $PACKAGE_MANAGER == "npm" ]; then
    -   $PACKAGE_MANAGER add --global gulp-cli
    - fi

    # Install global gulp for yarn
    - if [ $PACKAGE_MANAGER == "yarn" ]; then
    -   $PACKAGE_MANAGER global add gulp-cli
    - fi

    # Get and run all the tasks
    - echo "Begin run tasks"
    - TASKS_LIST=$(echo $GULP_TASKS | tr ";" "\n")
    - for TASK in $TASKS_LIST; do
    -   echo "Running \"$TASK\" "
    -   gulp -f "$GULPFILE_PATH" "$TASK"
    - done

    # To deploy on pages
    - if [ "$PAGES_DEPLOY" == "true" ]; then
        # Pages folder must to be at the root of the repo
    -   cd $CI_PROJECT_DIR
    -   cp -r ${PROJECT_ROOT}/${GULP_OUTPUT_FOLDER} ${CI_PROJECT_DIR}/${PAGES_FOLDER}
    - fi
  artifacts:
    expose_as: "gulp artifact"
    paths:
      - "${PROJECT_ROOT}/${GULP_OUTPUT_FOLDER}"
      # To deploy on pages
      - "${PAGES_FOLDER}"

jobs/gulp/job.yml

0 → 100644
+9 −0
Original line number Diff line number Diff line
name: gulp
description: A ready to use `gulp` job that runs your tasks
default_stage: others
icon: 💡
maintainer: coconux
license: MIT
labels:
  - GitLab
  - Utilities
+0 −0

Empty file added.

Loading