Commit 34cea735 authored by Thomas Boni's avatar Thomas Boni
Browse files

Merge branch '605-new-job-pnpm-install' into 'latest'

Resolve "[New job] - Pnpm install"

Closes #605

See merge request r2devops/hub!374
parents a03d0d0e 44a69cfa
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
# Changelog
All notable changes to this job will be documented in this file.

## [0.1.0] - 2022-07-06
* Initial version
 No newline at end of file
+46 −0
Original line number Diff line number Diff line
## Objective

This job will install pnpm packages based on pnpm-lock.yaml file. Here the [doc of pnpm install](https://pnpm.io/cli/install). `pnpm` is so crazy faster than `npm` or `yarn`. You can check the [benchmark here](https://pnpm.io/benchmarks).

## How to use it

!!! warning
    You should have `pnpm-lock.yaml` otherwise you have to create and fulfill the `.npmrc` with the following content:
    ``` 
    auto-install-peers=true
    strict-peer-dependencies=false
    ```

1. Ensure that your project has `pnpm-lock.yaml` file and up to date with `package.json`.
2. Copy the job URL located in the `Install` part of the right panel and add it inside the `include` list of your `.gitlab-ci.yml` file (see the [quick setup](/use-the-hub/#quick-setup)). You can specify [a fixed version](#changelog) instead of `latest`.
3. If you need to customize the job (stage, variables, ...) 👉 check the [jobs
   customization](/use-the-hub/#jobs-customization)
4. Well done, your job is ready to work ! 😀

### Variables

| Name | Description | Default |
| ---- | ----------- | ------- |
| `PROJECT_ROOT` | Relative path to the directory containing `pnpm-lock.yaml` and `package.json` (**see warning below**)  | `.` |
| `PNPM_INSTALL_OPTIONS` | Additional options for `pnpm install` | ` ` |
| `IMAGE_TAG` | The default tag for the docker image | `18-buster`  |

!!! warning
    In the case you are updating `PROJECT_ROOT` and you want to have a properly working cache,
    consider making this variable a global variable in the root of your `.gitlab-ci.yml`. Learn how
    easy it is [here](https://docs.gitlab.com/ee/ci/variables/#create-a-custom-cicd-variable-in-the-gitlab-ciyml-file).

### Cache

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

* Each branch has its own version
* Cached directory is `$PROJECT_ROOT/node_modules`
* If `package.json` or `pnpm-lock.yaml` is edited, the cache is updated

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

### Author
This resource is an **[official job](https://docs.r2devops.io/faq-labels/)** added in [**R2Devops repository**](https://gitlab.com/r2devops/hub) by [@DjNaGuRo](https://gitlab.com/DjNaGuRo)
 No newline at end of file
+28 −0
Original line number Diff line number Diff line
# Job from R2Devops hub --> r2devops.io

default:
  cache:
    key:
      files:
        - ${CI_PROJECT_DIR}/${PROJECT_ROOT}/pnpm-lock.yaml
      prefix: "pnpm-${CI_COMMIT_REF_SLUG}"
    paths:
      - ${CI_PROJECT_DIR}/${PROJECT_ROOT}/.pnpm-store

pnpm_install:
  stage: .pre
  image: node:${IMAGE_TAG}
  variables:
    IMAGE_TAG: "18-buster"
    PNPM_INSTALL_OPTIONS: ""
    PROJECT_ROOT: "."
  before_script:
      - curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm@7
      - pnpm config set store-dir ${CI_PROJECT_DIR}/${PROJECT_ROOT}/.pnpm-store
      
  script:
    - |
      cd ${PROJECT_ROOT}
      if [ -f "pnpm-lock.yaml" ]; then
        pnpm install ${PNPM_INSTALL_OPRIONS}
      fi
 No newline at end of file
+0 −0

Empty file added.