Commit 304ee1b4 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

feat(publish): auto publish on release tag

parent e928a970
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -302,16 +302,19 @@ It is bound to the `test` stage, and uses the following variables:

### `ng-publish` job

The Angular template features a `ng-publish` job to publish the built project.
This job [publishes](https://docs.npmjs.com/cli/v6/commands/npm-publish) the project packages to a npm registry.

This job is bound to the `publish` stage, and uses the following variable:
This job is bound to the `publish` stage and is disabled by default.
When enabled, it is executed on a Git tag with a semantic version pattern (`v?[0-9]+\.[0-9]+\.[0-9]+`, _configurable_).

It uses the following variables:

| Name                       | description                                                                 | default value                                                    |
|----------------------------|-----------------------------------------------------------------------------|------------------------------------------------------------------|
| `NG_PUBLISH_ENABLED`       | Set variable to `true` to enable the publish job                            | none (disabled)                                                  |
| `NG_PUBLISH_PROJECTS`      | Space separated list of projects to publish                                 | If no project is specified, all workspace projects are published |
| `NG_PUBLISH_ARGS`          | NPM [publish](https://docs.npmjs.com/cli/v6/commands/npm-publish) arguments | `--verbose`                                                      |
| `NPM_PUBLISH_REGISTRY`     | NPM registry to publish to | uses GitLab project npm packages registry      |                                                                  |
| `NPM_PUBLISH_REGISTRY`     | npm registry to publish to | uses GitLab project npm packages registry      |                                                                  |
| :lock: `NPM_PUBLISH_TOKEN` | NPM publication registry authentication token                               | none                                                             |

:warning: When using the gitlab registry (which is the default behavior), your NPM package name must be in the format of `@scope/package-name`:
+2 −2
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@
    {
      "id": "publish",
      "name": "Publish",
      "description": "NPM [publish](https://docs.npmjs.com/cli/v6/commands/npm-publish) your angular project",
      "description": "[publishes](https://docs.npmjs.com/cli/v6/commands/npm-publish) the project packages to a npm registry",
      "enable_with": "NG_PUBLISH_ENABLED",
      "variables": [
        {
@@ -78,7 +78,7 @@
        },
        {
          "name": "NPM_PUBLISH_REGISTRY",
          "description": "NPM registry to publish to. If none is specified, uses GitLab project npm packages registry",
          "description": "npm registry to publish to. If none is specified, uses GitLab project npm packages registry",
          "secret": true
        },
        {
+7 −5
Original line number Diff line number Diff line
@@ -73,6 +73,8 @@ variables:
  PROD_REF: '/^(master|main)$/'
  # default integration ref name (pattern)
  INTEG_REF: '/^develop$/'
  # default release tag name (pattern)
  RELEASE_REF: '/^v?[0-9]+\.[0-9]+\.[0-9]+$/'

  # ==================================================
  # Variables for publication
@@ -346,7 +348,6 @@ stages:
      npm config set "@${CI_PROJECT_ROOT_NAMESPACE}:registry" "https://${CI_SERVER_HOST}/api/v4/packages/npm/"
      npm config set "//${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken" "${CI_JOB_TOKEN}"
    fi

  }

  function npm_publish() {
@@ -414,7 +415,6 @@ stages:
      log_info "Publishing project '${project}' from ${projectOutputDir}"
      npm publish "${projectOutputDir}" "${NG_PUBLISH_ARGS}"
    done

  }

  unscope_variables
@@ -576,6 +576,8 @@ ng-publish:
  script:
    - npm_publish
  rules:
    # on production branche: manual
    - if: '$NG_PUBLISH_ENABLED == "true" && $CI_COMMIT_REF_NAME =~ $PROD_REF'
      when: manual
    # exclude if $NG_PUBLISH_ENABLED not set
    - if: '$NG_PUBLISH_ENABLED != "true"'
      when: never
    # on tag with release pattern: auto
    - if: '$CI_COMMIT_TAG =~ $RELEASE_REF'