Skip to content
Snippets Groups Projects
Commit 304ee1b4 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

feat(publish): auto publish on release tag

parent e928a970
No related branches found
No related tags found
No related merge requests found
...@@ -302,16 +302,19 @@ It is bound to the `test` stage, and uses the following variables: ...@@ -302,16 +302,19 @@ It is bound to the `test` stage, and uses the following variables:
### `ng-publish` job ### `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 | | Name | description | default value |
|----------------------------|-----------------------------------------------------------------------------|------------------------------------------------------------------| |----------------------------|-----------------------------------------------------------------------------|------------------------------------------------------------------|
| `NG_PUBLISH_ENABLED` | Set variable to `true` to enable the publish job | none (disabled) | | `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_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` | | `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 | | :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`: :warning: When using the gitlab registry (which is the default behavior), your NPM package name must be in the format of `@scope/package-name`:
......
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
{ {
"id": "publish", "id": "publish",
"name": "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", "enable_with": "NG_PUBLISH_ENABLED",
"variables": [ "variables": [
{ {
...@@ -78,7 +78,7 @@ ...@@ -78,7 +78,7 @@
}, },
{ {
"name": "NPM_PUBLISH_REGISTRY", "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 "secret": true
}, },
{ {
......
...@@ -73,6 +73,8 @@ variables: ...@@ -73,6 +73,8 @@ variables:
PROD_REF: '/^(master|main)$/' PROD_REF: '/^(master|main)$/'
# default integration ref name (pattern) # default integration ref name (pattern)
INTEG_REF: '/^develop$/' INTEG_REF: '/^develop$/'
# default release tag name (pattern)
RELEASE_REF: '/^v?[0-9]+\.[0-9]+\.[0-9]+$/'
# ================================================== # ==================================================
# Variables for publication # Variables for publication
...@@ -346,7 +348,6 @@ stages: ...@@ -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_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}" npm config set "//${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken" "${CI_JOB_TOKEN}"
fi fi
} }
function npm_publish() { function npm_publish() {
...@@ -414,7 +415,6 @@ stages: ...@@ -414,7 +415,6 @@ stages:
log_info "Publishing project '${project}' from ${projectOutputDir}" log_info "Publishing project '${project}' from ${projectOutputDir}"
npm publish "${projectOutputDir}" "${NG_PUBLISH_ARGS}" npm publish "${projectOutputDir}" "${NG_PUBLISH_ARGS}"
done done
} }
unscope_variables unscope_variables
...@@ -576,6 +576,8 @@ ng-publish: ...@@ -576,6 +576,8 @@ ng-publish:
script: script:
- npm_publish - npm_publish
rules: rules:
# on production branche: manual # exclude if $NG_PUBLISH_ENABLED not set
- if: '$NG_PUBLISH_ENABLED == "true" && $CI_COMMIT_REF_NAME =~ $PROD_REF' - if: '$NG_PUBLISH_ENABLED != "true"'
when: manual when: never
# on tag with release pattern: auto
- if: '$CI_COMMIT_TAG =~ $RELEASE_REF'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment