Commit 0843bb1d authored by coconux's avatar coconux
Browse files

First version of gulp job

parent 1ed72a1b
Loading
Loading
Loading
Loading

jobs/gulp/README.md

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

This job installs `npm` dependencies listed in your `package.json` and installs
also gulp to run your tasks.
It exposes `node_modules` as cache to other jobs of your pipeline. It allows you to run
`npm install` only once in your pipeline.

## 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"} 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 ! 😀


## Job details

!!! info
    On Gitlab, this job will run `npm_install` in the default first stage of your
    pipeline: [`.pre`](https://docs.gitlab.com/ee/ci/yaml/#pre-and-post)


* Job name: `gulp`
* Default stage: [`others`](https://docs.gitlab.com/ee/ci/yaml/#pre-and-post)
* 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` | Path to the directory containing `package.json`  | `.` |
| `NPM_INSTALL_OPTIONS` | Additional options for `npm install` | ` ` |
| `GULPFILE_PATH` | Path (from `PROJECT_ROOT`) to your  gulpfile `gulpfile.js` or `gulpfile.ts` or `gulpfile.babel.js`| ` ` |
| `GULP_TASKS` | List of your tasks to run with `gulp` (separated by ; ). *Ex: "minify-css; minify-js;"* | ` ` |



### Cache

This job creates a global cache configuration. Regarding the configuration
applied, cache behavior is the following:

* Shared between all jobs and pipelines on the same branch
* Contains folder `$PROJECT_ROOT/node_modules`
* If `npm install` produces different result than the cached content

More information on Gitlab caching mechanism in [Gitlab CI/CD caching
documentation](https://docs.gitlab.com/ee/ci/caching/index.html).

jobs/gulp/gulp.yml

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

cache:
  key:
    files:
      - "${PROJECT_ROOT}/package.json"
    prefix: "npm-${CI_COMMIT_REF_SLUG}"
  paths:
    - "${PROJECT_ROOT}/node_modules"
  when: "on_success"

gulp:
  image:
    name: node:15.7-buster
    entrypoint: [""]
  stage: others
  variables:
    PROJECT_ROOT: "."
    NPM_INSTALL_OPTIONS: ""
    GULPFILE_PATH: "."
    GULP_TASKS: ""
    OUTPUT_FOLDER: "./build/"

    # Deploy on GitLab pages
    GITLAB_PAGES_DEPLOY: "true"
    GITLAB_PAGES_OUTPUT: "./website_build"


  script:
    # Working directory
    - cd $PROJECT_ROOT
    # Run npm install
    - npm install $NPM_INSTALL_OPTIONS
    # Install gulp
    - npm install -g gulp-cli
    # Install alternative of gulpfile.js .ts .babel.js
    - npm install -D ts-node typescript @types/gulp
    # 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 GitLab pages
    - if [ "$GITLAB_PAGES_DEPLOY" == "true" ]; then
    - mkdir $GITLAB_PAGES_OUTPUT
    - cp -Rp $OUTPUT_FOLDER $GITLAB_PAGES_OUTPUT
    - fi

  artifacts:
    when: always
    expose_as: "gulp artefact"
    paths:
    - "$OUTPUT_FOLDER"
    # To deploy on GitLab pages
    - "$GITLAB_PAGES_OUTPUT"

jobs/gulp/job.yml

0 → 100644
+10 −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
  - Optimization
  - Utilities
+0 −0

Empty file added.

+1 −0
Original line number Diff line number Diff line
* Initial version