Commit d4693755 authored by totara-thib's avatar totara-thib
Browse files

ci(job): fix pnpm job name

parent 4db9b66c
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-27
* Initial version
+55 −0
Original line number Diff line number Diff line
## Objective

This job will run one or many scripts contained in the package.json through pnpm package manager

## How to use it

1. Make sure that your project has `package.json` file which contains predefined command in the scripts object
2. If you want the job to run scripts make sure to add them inside the variable `PNPM_SCRIPTS` and separate every command with `;`
3. 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`.
4. If you need to customize the job (stage, variables, ...) 👉 check the [jobs
   customization](/use-the-hub/#jobs-customization)
5. Well done, your job is ready to work ! 😀

### Variables

| Name | Description | Default |
| ---- | ----------- | ------- |
| `PROJECT_ROOT` | Path to the directory containing `package.json`  | `.` |
| `PNPM_INSTALL_OPTIONS` | Additional options for `pnpm install` | ` ` |
| `PNPM_SCRIPTS` | The names of multiple scripts specified in `package.json` that can be separated by `;` | ` ` |
| `PNPM_OUTPUT` | Path to the output send by script specified in `package.json` | ` ` |
| `IMAGE_TAG` | The default tag for the docker image | `18-buster`  |

### Example to use several scripts

Following example of `.gitlab-ci.yml` file describes how to use `pnpm_scripts` job.
deployment using this job:

#### Scripts in Package.json

```yaml
  "scripts": {
    "build": "ng build",
    "lint": "ng lint"
  }
```

#### .gitlab-ci.yml

```yaml
stages:
  - others

include:
  - remote: 'https://api.r2devops.io/job/r/r2devops-bot/pnpm_scripts.yml'

pnpm_scripts:
  variables:
    PNPM_SCRIPTS: "build;lint"
    PNPM_OUTPUT: "dist"
```

### 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
+41 −0
Original line number Diff line number Diff line
# Job from R2Devops hub --> r2devops.io

stages:
  - others

pnpm_scripts:
  stage: others
  image:
    name: node:${IMAGE_TAG}
    entrypoint: [""]
  variables:
    PROJECT_ROOT: "."
    PNPM_INSTALL_OPTIONS: ""
    PNPM_SCRIPTS: ""
    PNPM_OUTPUT: ""
    IMAGE_TAG: "18-buster"
  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:
    # Working directory
    - cd $PROJECT_ROOT
    # install project dependencies
    - pnpm install $PNPM_INSTALL_OPTIONS
    # Save default IFS
    - oldIFS=$IFS
    # Modifying IFS
    - export IFS=";"
    # Loop for launching any script specified in $PNPM_SCRIPTS separated by ;
    - for script in $PNPM_SCRIPTS; do
        # Restore to default IFS
    -   IFS=$oldIFS
        # Run the script
    -   pnpm run $script
        # Modifying IFS for the next loop iteration
    -   export IFS=";"
    - done
  artifacts:
    paths:
      # Output directory
      - $PNPM_OUTPUT