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

feat: initial release

parents
No related branches found
No related tags found
No related merge requests found
Pipeline #84869 failed
include:
- project: 'Orange-OpenSource/tbc/tools/gitlab-ci'
ref: 'master'
file: '/templates/validation.yml'
- project: 'Orange-OpenSource/tbc/kicker'
ref: 'master'
file: '/templates/validation.yml'
- project: 'Orange-OpenSource/tbc/bash'
ref: '1.0.0'
file: 'templates/gitlab-ci-bash.yml'
stages:
- build
- publish
variables:
GITLAB_CI_FILES: "templates/gitlab-ci-angular.yml"
BASH_SHELLCHECK_FILES: "*.sh"
extract-script:
stage: .pre
script:
- echo "#!/bin/bash" > script.sh
- sed -n '/BEGSCRIPT/,/ENDSCRIPT/p' "$GITLAB_CI_FILES" | sed 's/^ //' >> script.sh
- export LC_ALL=C.UTF-8
artifacts:
when: always
name: extracted template script
expire_in: 1h
paths:
- script.sh
release:
image: node:12
stage: publish
before_script:
- npm install -g semantic-release @semantic-release/gitlab @semantic-release/exec @semantic-release/git
script:
- semantic-release
only:
refs:
- master
variables:
- $TMPL_RELEASE_ENABLED
## Describe the bug
(Describe the problem clearly and concisely.)
## Expected behavior
(Describe the expected behavior clearly and concisely.)
## Actual behavior
(Describe the actual behavior clearly and concisely.)
## Logs and/or screenshots
(Join any relevant logs and/or screenshot. Please use code blocks (```) to format console output, logs, and code.)
## Context & Configuration
Link to a project, pipeline or job facing the bug: (please provide one if possible)
The issue was reproduced using:
* Version of the template: (type in the version)
* GitLab server(s): (Was it gitlab.com? A self-managed server? Which version? CE / EE? Which license?)
* GitLab runner(s): (type in any relevant information about the GitLab runner(s) you used)
Here is the `.gitlab-ci.yml` file:
```yaml
# Add your .gitlab-ci.yml here, if applicable and useful.
```
(If useful, list configured GitLab CI project and/or group variables.)
Configured GitLab CI project or group variables:
* `VARIABLE_1`
* `VARIABLE_2`
* ...
(Finally add any possible additional useful context info here.)
/label ~kind/bug ~status/needs-investigation
## Description
(Describe the feature clearly and concisely.)
## Implementation ideas
(If you have any implementation ideas, they can go here.)
(Any design change proposal could be also discussed on the _to be continuous_ Google Group: https://groups.google.com/g/tbc-dev.)
/label ~kind/enhancement ~status/needs-investigation
## Presentation
(Necessarily link to an issue. If it doesn't exist, please create one.)
Fixes #999
## Checklist
* Documented:
* [ ] `README.md` reflects any job, variable or whichever visible change
* [ ] `kicker.json` reflects any job, variable or whichever visible change
* Tested & examplified:
* [ ] (url to a project sample successfully proving the merge request fixes the issue)
/label ~kind/fix
## Presentation
(Necessarily link to an issue. If it doesn't exist, please create one.)
Closes #999
## Checklist
* General:
* [ ] use [rules](https://docs.gitlab.com/ee/ci/yaml/#rules) instead of [only/except](https://docs.gitlab.com/ee/ci/yaml/#onlyexcept-advanced)
* [ ] optimized [cache](https://docs.gitlab.com/ee/ci/caching/) configuration (wherever applicable)
* Publicly usable:
* [ ] untagged runners
* [ ] no proxy configuration but support `http_proxy`/`https_proxy`/`no_proxy`
* [ ] no custom CA certificate(s) but supports `$CUSTOM_CA_CERTS` or `$DEFAULT_CA_CERTS` to declare custom CA certificate(s)
* [ ] internet hostnames/urls only
* Used Docker images:
* [ ] **public** images
* [ ] **official** images (when possible)
* [ ] `latest` tag (when possible)
* Documented:
* [ ] `README.md` documents the new feature
* [ ] `kicker.json` describes the new feature
* Tested & examplified:
* [ ] (url to a project sample successfully using the new feature)
/label ~kind/enhancement
plugins: [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/gitlab",
[
"@semantic-release/exec",
{
"prepareCmd": "./bumpversion.sh \"${lastRelease.version}\" \"${nextRelease.version}\" \"${nextRelease.type}\""
}
],
[
"@semantic-release/git",
{
"assets": ["*.md", "templates/*.yml"]
}
]
]
branches:
- "master"
tagFormat: "${version}"
\ No newline at end of file
# Contributors guide
**Want to contribute? Great!**
We try to make it easy, and all contributions, even the smaller ones, are more than welcome.
This includes bug reports, fixes, documentation, examples...
But first, read this page (including the small print at the end).
## Legal
All original contributions to _to be continuous_ are licensed under the
[GNU Lesser General Public License](https://www.gnu.org/licenses/lgpl-3.0.html),
version 3.0 or later.
All contributions are subject to the [Developer Certificate of Origin](https://developercertificate.org/) (DCO).
The DCO is a lightweight way for contributors to certify that they wrote or otherwise have the right to submit the code they are contributing to the project.
The DCO text is also included verbatim in the [DCO.txt](DCO.txt) file in the root directory of the repository.
Contributors **must** _sign-off_ that they adhere to these requirements by adding a `Signed-off-by` line to commit messages, as shown below:
```text
This is the commit message
Signed-off-by: John Dev <john.dev@developer.example.org>
```
Git has a handy [`-s` command line option](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---signoff) to append this automatically to your commit message:
```bash
$ git commit -s -m 'This is the commit message'
```
## Reporting an issue
This project uses GitLab issues to manage the issues.
Before creating an issue:
1. upgrade your project to the latest released template version, and check whether your bug is still present,
2. have a look in the opened issues if your problem is already known/tracked, and possibly contribute to the thread with your own information.
If none of the above was met, open an issue directly in GitLab, select the appropriate issue template and fill-in each section when applicable.
## Submitting a code change
### Git Setup
Before contributing, make sure you have set up your Git authorship correctly:
```bash
git config --global user.name "Your Full Name"
git config --global user.email your.email@example.com
```
### Workflow
All submissions, including submissions by project members, need to be reviewed before being merged.
To contribute:
1. Create an issue describing the bug or enhancement you want to propose (select the right issue template).
2. Make sure the issue has been reviewed and agreed.
3. Create a Merge Request, from your **own** fork (see [forking workflow](https://docs.gitlab.com/ee/user/project/repository/forking_workflow.html) documentation).
Don't hesitate to mark your MR as `Draft` as long as you think it's not ready to be reviewed.
### Git Commit Conventions
In addition to being signed-off according the [Developer Certificate of Origin](https://developercertificate.org/) (see above),
Git commits in _to be continuous_ shall be:
1. **atomic** (1 commit `=` 1 and only 1 _thing_),
2. **semantic** (using [semantic-release commit message syntax](https://semantic-release.gitbook.io/semantic-release/#commit-message-format)).
You'll find extensive information about Git commit conventions on the [reference documentation website](https://orange-opensource.gitlab.io/tbc/doc/dev/workflow/#git-commit-guidelines).
### Coding Guidelines
The extensive _to be continuous_ coding guidelines can be found on the [reference documentation website](https://orange-opensource.gitlab.io/tbc/doc/dev/guidelines/).
DCO.txt 0 → 100644
Developer Certificate of Origin
Version 1.1
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129
Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.
Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
\ No newline at end of file
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
\ No newline at end of file
README.md 0 → 100644
# GitLab CI template for Angular
This project implements a generic GitLab CI template [Angular](https://angular.io/) based projects.
It provides several features, usable in different modes (by configuration).
## Usage
In order to include this template in your project, add the following to your `gitlab-ci.yml`:
```yaml
include:
- project: 'Orange-OpenSource/tbc/angular'
ref: '1.0.0'
file: '/templates/gitlab-ci-angular.yml'
```
## Global configuration
The Angular template uses some global configuration used throughout all jobs.
| Name | description | default value |
|----------------|-----------------------------------------------|:--------------------------------------------------------------------------|
| `NG_CLI_IMAGE` | The Docker image used to run Angular-CLI (ng). **It is highly recommended to set the specific version your project needs** | `trion/ng-cli-karma:latest` |
| `NPM_CONFIG_REGISTRY` | NPM [registry](https://docs.npmjs.com/configuring-your-registry-settings-as-an-npm-enterprise-user) | _none_ (defaults to `https://registry.npmjs.org`) |
| `NG_WORKSPACE_DIR` | Angular workspace directory | `.` |
## Jobs
### `ng-lint` job
The Angular template features a job `ng-lint` that performs Angular source code **lint**.
It is bound to the `check` stage, and uses the following variable:
| Name | description | default value |
|----------------|----------------------------------------------------------|---------------|
| `NG_LINT_ARGS` | Angular [ng lint](https://angular.io/cli/lint) arguments | `lint` |
### `ng-build` job
The Angular template features a job `ng-build` that performs **build and tests** all at once.
Those stages are performed in a single job for **optimization** purpose (it saves time) and also
for jobs dependency reasons (some jobs such as SONAR analysis have a dependency on test results).
Those stage are bound to the `build` stage, and uses the following variable:
| Name | description | default value |
|-----------------|------------------------------------------------------------|------------------------------------------|
| `NG_TEST_ARGS` | Angular [ng test](https://angular.io/cli/test) arguments | `test --code-coverage --reporters progress,junit` |
| `NG_BUILD_ARGS` | Angular [ng build](https://angular.io/cli/build) arguments | `build --prod` |
| `NG_JUNIT_TEST_REPORT_PATH` | Path to JUnit report | `reports/junit_test_report.xml` |
### `ng-e2e` job
The Angular template features a job `ng-e2e` that performs **protractor tests**
This stage is bound to the `test` stage and uses the following variables :
| Name | description | default value |
|----------------------|------------------------------------------------------------|------------------------------------------|
| `NG_E2E_ARGS` | Angular [ng e2e](https://angular.io/cli/e2e) arguments | `e2e` |
| `NG_E2E_REPORT_PATH` | path where e2e reports are stored | `reports/e2e` |
| `NG_E2E_ENABLED` | enable or not the e2e tests execution | *none (disabled by default)* |
Implementation rely on the official [Angular CLI](https://cli.angular.io/) tool (`ng build` and `ng test` commands).
To enable JUnit reporting on this job, you'll need to add [jasmine-reporters](https://www.npmjs.com/package/jasmine-reporters) dependency to your project and add the following snippet to your protractor config file :
```js
const { JUnitXmlReporter } = require('jasmine-reporters');
exports.config = {
...
onPrepare() {
jasmine.getEnv().addReporter(new JUnitXmlReporter({
consolidateAll: true,
savePath: 'reports/e2e'
}));
}
...
}
````
### `ng-publish` job
The Angular template features a `ng-publish` job to publish the built project.
This job is bound to the `publish` stage, and uses the following variable:
| Name | description | default value |
|-----------------|------------------------------------------------------------|------------------------------------------|
| `NG_PUBLISH_ENABLED` | Variable to enable the publish job | none (disabled) |
| `NG_PUBLISH_PROJECTS` | Space separated list of projects to publish | If no project is specified, the value of _angular.json_ `defaultProject` property is used |
| `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 |
| :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`.
* The `@scope` is the root namespace of the GitLab project. It must match exactly, including the case.
* The `package-name` can be whatever you want.
For example, if your project is `https://gitlab.example.com/my-org/engineering-group/team-amazing/analytics`, the root namespace is `my-org`. When you publish a package, it must have `my-org` as the scope.
For more details see [Package naming convention](https://docs.gitlab.com/ee/user/packages/npm_registry/#package-naming-convention).
:warning: Don't forget to specify the publication registry in the **project(s)** to publish `package.json` file (not the workspace top-level one).
```json
{
"name": "@my-org/hello-world",
"version": "0.0.6",
"peerDependencies": {
"@angular/common": "^10.1.6",
"@angular/core": "^10.1.6"
},
"dependencies": {
"tslib": "^2.0.0"
},
"publishConfig": {
"@my-org:registry": "https://<publication-registry-url>"
}
}
```
:information_source: When using the GitLab registry, the registry publication url looks like `https://<gitlab-host>/api/v4/projects/<your_project_id>/packages/npm/`, with:
* `<gitlab-host>` is your GitLab host domain name.
* `<your_project_id>` is your project ID, **found on the project’s home page**.
#### Unit testing with Karma
##### Use an headless browser
To be able to launch unit tests with Angular CLI, the Angular template requires a headless browser within the Docker
image `NG_CLI_IMAGE` (it is the case with the default image, [docker-ng-cli-karma](https://github.com/trion-development/docker-ng-cli-karma)).
#### Code Coverage
In order to be able to compute code coverage, the Angular template expects the following in your `karma.conf.js`
(this is done by default if your project was generated with [`ng new`](https://angular.io/cli/new) command).
Add the plugin:
```js
require('karma-coverage-istanbul-reporter')
```
Add the config section:
```js
coverageIstanbulReporter: {
dir: require('path').resolve('reports'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
}
```
#### JUnit report
In order to be able to [integrate your test reports to GitLab](https://docs.gitlab.com/ee/ci/junit_test_reports.html),
the Angular template expects the following in your `karma.conf.js`.
Add the add [karma-junit-reporter](https://github.com/karma-runner/karma-junit-reporter) as dev dependency:
```shell
npm install --save-dev karma-junit-reporter
```
In your `karma.conf.js`, add the plugin:
Add the plugin:
```js
require('karma-junit-reporter')
```
Add the config section:
```js
junitReporter: {
outputDir: require('path').resolve('reports'),
outputFile: 'junit_test_report.xml',
useBrowserName: false,
...
}
```
#### SonarQube report
In order to generate a test report [compatible with SonarQube](https://docs.sonarqube.org/latest/analysis/generic-test/),
the Angular template expects the following.
By default Angular CLI do not allow to generate test report compatible with Sonar to do so need to add [karma-sonarqube-execution-reporter](https://github.com/lisrec/karma-sonarqube-execution-reporter) to your project.
Add the add [karma-sonarqube-execution-reporter](https://github.com/lisrec/karma-sonarqube-execution-reporter) as dev dependency:
```shell
npm install --save-dev karma-sonarqube-execution-reporter
```
In your `karma.conf.js`, add the plugin:
```js
require('karma-sonarqube-execution-reporter')
```
Add the config section:
```js
sonarQubeExecutionReporter: {
outputDir: require('path').resolve('reports'),
outputFile: 'sonar_test_report.xml',
...
}
```
Finally add the sonarqubeUnit reporter in the reporters parameter of the `NG_TEST_ARGS` variable :
```yaml
NG_TEST_ARGS: test --reporters junit,sonarqubeUnit`
```
## SonarQube analysis
:warning: From version `1.1.0`, the SonarQube job is no longer part of the Angular template as it is now a standalone template.
If you're using the SonarQube template to analyse your Angular code, here is a sample `sonar-project.properties` file:
```properties
# see: https://docs.sonarqube.org/latest/analysis/languages/typescript/
# set your source directory(ies) here (relative to the sonar-project.properties file)
sonar.sources=app
# exclude unwanted directories and files from being analysed
sonar.exclusions=node_modules/**,dist/**,**/*.spec.ts
# set your tests directory(ies) here (relative to the sonar-project.properties file)
sonar.tests=app
sonar.test.inclusions=**/*.spec.ts
# tests report: generic format
# set the path configured with karma-sonarqube-execution-reporter
sonar.testExecutionReportPaths=reports/sonar_test_report.xml
# lint report: TSLint JSON
sonar.typescript.tslint.reportPaths=reports/tslint-report.json
# coverage report: LCOV format
# set the path configured with karma-coverage-istanbul-reporter
sonar.typescript.lcov.reportPaths=reports/lcov.info
```
More info:
* [TypeScript language support](https://docs.sonarqube.org/latest/analysis/languages/typescript/)
* [test coverage & execution parameters](https://docs.sonarqube.org/latest/analysis/coverage/)
* [third-party issues](https://docs.sonarqube.org/latest/analysis/external-issues/)
#!/usr/bin/env bash
function log_info() {
>&2 echo -e "[\\e[1;94mINFO\\e[0m] $*"
}
function log_warn() {
>&2 echo -e "[\\e[1;93mWARN\\e[0m] $*"
}
function log_error() {
>&2 echo -e "[\\e[1;91mERROR\\e[0m] $*"
}
# check number of arguments
if [[ "$#" -le 2 ]]; then
log_error "Missing arguments"
log_error "Usage: $0 <current version> <next version>"
exit 1
fi
curVer=$1
nextVer=$2
relType=$3
if [[ "$curVer" ]]; then
log_info "Bump version from \\e[33;1m${curVer}\\e[0m to \\e[33;1m${nextVer}\\e[0m (release type: $relType)..."
# replace in README
sed -e "s/ref: '$curVer'/ref: '$nextVer'/" README.md > README.md.next
mv -f README.md.next README.md
# replace in template and variants
for tmpl in templates/*.yml
do
sed -e "s/\"$curVer\"/\"$nextVer\"/" "$tmpl" > "$tmpl.next"
mv -f "$tmpl.next" "$tmpl"
done
else
log_info "Bump version to \\e[33;1m${nextVer}\\e[0m (release type: $relType): this is the first release (skip)..."
fi
{
"name": "Angular",
"description": "Build and test with [Angular](https://angular.io/)",
"template_path": "templates/gitlab-ci-angular.yml",
"kind": "build",
"variables": [
{
"name": "NG_CLI_IMAGE",
"description": "The Docker image used to run Angular-CLI (`ng`)",
"default": "trion/ng-cli-karma:latest"
},
{
"name": "NPM_CONFIG_REGISTRY",
"description": "NPM [registry](https://docs.npmjs.com/configuring-your-registry-settings-as-an-npm-enterprise-user)",
"type": "url",
"advanced": true
},
{
"name": "NG_WORKSPACE_DIR",
"description": "Angular workspace directory",
"default": ".",
"advanced": true
},
{
"name": "NG_BUILD_ARGS",
"description": "Angular [ng build](https://angular.io/cli/build) arguments",
"default": "build --prod",
"advanced": true
},
{
"name": "NG_TEST_ARGS",
"description": "Angular [ng test](https://angular.io/cli/test) arguments",
"default": "test --code-coverage --reporters progress,junit",
"advanced": true
},
{
"name": "NG_LINT_ARGS",
"description": "Angular [ng lint](https://angular.io/cli/lint) arguments",
"default": "lint",
"advanced": true
}
],
"features": [
{
"id": "publish",
"name": "Publish",
"description": "NPM [publish](https://docs.npmjs.com/cli/v6/commands/npm-publish) your angular project",
"enable_with": "NG_PUBLISH_ENABLED",
"variables": [
{
"name": "NG_PUBLISH_ARGS",
"description": "npm [publish](https://docs.npmjs.com/cli/v6/commands/npm-publish) arguments",
"default": "--verbose",
"advanced": true
},
{
"name": "NG_PUBLISH_PROJECTS",
"description": "Space separated list of projects to publish. If no project is specified, the value of _angular.json_ `defaultProject` property is used",
"advanced": true
},
{
"name": "NPM_PUBLISH_REGISTRY",
"description": "NPM registry to publish to. If none is specified, uses GitLab project npm packages registry",
"secret": true
},
{
"name": "NPM_PUBLISH_TOKEN",
"description": "NPM publication registry authentication token",
"secret": true
}
]
},
{
"id": "e2e-test",
"name": "e2e-test",
"description": "Run your [e2e tests](https://angular.io/cli/e2e) on your angular project",
"enable_with": "NG_E2E_ENABLED",
"variables": [
{
"name": "NG_E2E_ARGS",
"description": "ng [e2e](https://angular.io/cli/e2e) arguments",
"default": "e2e",
"advanced": true
},
{
"name": "NG_E2E_REPORT_PATH",
"description": "path where e2e reports are stored",
"default": "reports/e2e",
"advanced": true
}
]
}
]
}
logo.png 0 → 100644
logo.png

8.1 KiB

# =========================================================================================
# Copyright (C) 2021 Orange
#
# This program is free software; you can redistribute it and/or modify it under the terms
# of the GNU Lesser General Public License as published by the Free Software Foundation;
# either version 3 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along with this
# program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
# Floor, Boston, MA 02110-1301, USA.
# =========================================================================================
variables:
# Default ng workspace
NG_WORKSPACE_DIR: .
# Default Docker image for ANGULAR CLI (can be overriden)
NG_CLI_IMAGE: trion/ng-cli-karma:latest
# JUnit test report
NG_JUNIT_TEST_REPORT_PATH: "reports/junit_test_report.xml"
NG_E2E_REPORT_PATH: "reports/e2e"
# Angular lint
NG_LINT_ARGS: "lint"
# Angular test
NG_TEST_ARGS: >-
test
--code-coverage
--reporters progress,junit
NG_E2E_ARGS: >-
e2e
# Angular Build
NG_BUILD_ARGS: "build --prod"
# default production ref name (pattern)
PROD_REF: '/^master$/'
# default integration ref name (pattern)
INTEG_REF: '/^develop$/'
# ==================================================
# Variables for publication
# ==================================================
# NG_PUBLISH_ENABLED
# List of projects to publish, use space (" ") for separation
# ex: NG_PUBLISH_PROJECTS: "Project1 Project2 myLib"
# By default, NG_PUBLISH_PROJECTS is the value of angular.json, "defaultProject" property
# Set some args of `npm publish` command
# ex: NG_PUBLISH_ARGS: "--dry-run"
NG_PUBLISH_ARGS: '--verbose'
# ==================================================
# Stages definition
# ==================================================
stages:
- build
- test
- publish
###############################################################################################
# Script definition #
###############################################################################################
.ng-cli-scripts: &ng-cli-scripts |
# BEGSCRIPT
set -e
function log_debug() {
if [[ -n "$TRACE" ]]
then
echo -e "[\\e[1;36mTRACE\\e[0m] $*"
fi
}
function log_info() {
echo -e "[\\e[1;94mINFO\\e[0m] $*"
}
function log_warn() {
echo -e "[\\e[1;93mWARN\\e[0m] $*"
}
function log_error() {
echo -e "[\\e[1;91mERROR\\e[0m] $*"
}
function assert_defined() {
if [[ -z "$1" ]]
then
log_error "$2"
exit 1
fi
}
function sonar_lint_report() {
if [[ -n "$SONAR_URL" ]]
then
mkdir -p reports
# generate ts lint report in json for SONARqube
# shellcheck disable=SC2086
ng $NG_LINT_ARGS --format=json --force > reports/tslint-report.json
fi
}
function install_ca_certs() {
certs=$1
if [[ -z "$certs" ]]
then
return
fi
# import in system
if echo "$certs" >> /etc/ssl/certs/ca-certificates.crt
then
log_info "CA certificates imported in \\e[33;1m/etc/ssl/certs/ca-certificates.crt\\e[0m"
fi
if echo "$certs" >> /etc/ssl/cert.pem
then
log_info "CA certificates imported in \\e[33;1m/etc/ssl/cert.pem\\e[0m"
fi
# import in Java keystore (if keytool command found)
if command -v keytool > /dev/null
then
# shellcheck disable=SC2046
javahome=${JAVA_HOME:-$(dirname $(readlink -f $(command -v java)))/..}
# shellcheck disable=SC2086
keystore=${JAVA_KEYSTORE_PATH:-$(ls -1 $javahome/jre/lib/security/cacerts 2>/dev/null || ls -1 $javahome/lib/security/cacerts 2>/dev/null || echo "")}
if [[ -f "$keystore" ]]
then
storepass=${JAVA_KEYSTORE_PASSWORD:-changeit}
nb_certs=$(echo "$certs" | grep -c 'END CERTIFICATE')
log_info "importing $nb_certs certificates in Java keystore \\e[33;1m$keystore\\e[0m..."
for idx in $(seq 0 $((nb_certs - 1)))
do
# TODO: use keytool option -trustcacerts ?
if echo "$certs" | awk "n==$idx { print }; /END CERTIFICATE/ { n++ }" | keytool -noprompt -import -alias "imported CA Cert $idx" -keystore "$keystore" -storepass "$storepass"
then
log_info "... CA certificate [$idx] successfully imported"
else
log_warn "... Failed importing CA certificate [$idx]: abort"
return
fi
done
else
log_warn "Java keystore \\e[33;1m$keystore\\e[0m not found: could not import CA certificates"
fi
fi
}
function get_latest_template_version() {
tag_json=$(wget -T 5 -q -O - "$CI_API_V4_URL/projects/Orange-OpenSource%2Ftbc%2F$1/repository/tags?per_page=1" || echo "")
echo "$tag_json" | sed -rn 's/^.*"name":"([^"]*)".*$/\1/p'
}
function check_for_update() {
template="$1"
actual="$2"
latest=$(get_latest_template_version "$template")
if [[ -n "$latest" ]] && [[ "$latest" != "$actual" ]]
then
log_warn "\\e[1;93m=======================================================================================================\\e[0m"
log_warn "\\e[93mThe template \\e[32m$template\\e[93m:\\e[33m$actual\\e[93m you're using is not up-to-date: consider upgrading to version \\e[32m$latest\\e[0m"
log_warn "\\e[93m(set \$TEMPLATE_CHECK_UPDATE_DISABLED to disable this message)\\e[0m"
log_warn "\\e[1;93m=======================================================================================================\\e[0m"
fi
}
function read_default_project() {
# current directory should be ${NG_WORKSPACE_DIR}
angular_json=./angular.json
default_project=$(node -pe "require('${angular_json}').defaultProject")
default_project_type=$(node -pe "require('${angular_json}').projects['${default_project}'].projectType")
}
function run_ng_build() {
read_default_project
case ${default_project_type} in
library)
# shellcheck disable=SC2086
ng $NG_BUILD_ARGS
;;
*)
# shellcheck disable=SC2086
ng $NG_BUILD_ARGS --no-progress
;;
esac
}
function run_ng_build_libs() {
# current directory should be ${NG_WORKSPACE_DIR}
angular_json=./angular.json
libs=$(node -pe "Object.entries(require('${angular_json}').projects).filter(entry => entry[1].projectType === 'library').map(entry => entry[0]).join(' ')")
log_debug "parsed libs: ${libs}"
if [ -n "${libs}" ]; then
log_info "libs detected: ${libs}"
for lib in ${libs}; do
log_debug "building lib ${lib}"
ng build "${lib}"
done
fi
}
function configure_gitlab_instance_level_npm_registry_auth() {
npm config set "//${CI_SERVER_HOST}/api/v4/packages/npm/:_authToken" "${CI_JOB_TOKEN}"
}
function compute_gitlab_registry_url() {
gitlab_registry_url="https://${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm"
}
function configure_npm_publish_registry_auth() {
publish_registry=${NPM_PUBLISH_REGISTRY}
if [[ "${publish_registry}" ]]; then
log_info "configured publish registry: ${publish_registry}"
if [[ "$NPM_PUBLISH_TOKEN" ]]; then
shopt -s extglob
npm_publish_registry_host_and_path=${publish_registry/#http?(s):/}
shopt -u extglob
npm config set "${npm_publish_registry_host_and_path}:_authToken" "${NPM_PUBLISH_TOKEN}"
fi
else
compute_gitlab_registry_url
log_info "No defined publication registry, falling back to GitLab packages ${gitlab_registry_url}"
publish_registry=${gitlab_registry_url}
log_info "be sure to have your projects name starting with @${CI_PROJECT_ROOT_NAMESPACE}/"
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() {
projects_to_publish=${NG_PUBLISH_PROJECTS}
if [ -z "${projects_to_publish}" ]; then
read_default_project
log_info "No projects specified, falling back to default project: \\e[33;1m${default_project}\\e[0m."
projects_to_publish=${default_project}
fi
log_info "Publishing the following projects: ${projects_to_publish}..."
# current directory should be ${NG_WORKSPACE_DIR}
angular_json=./angular.json
package_json=./package.json
# first we check all specified projects exist
for project in ${projects_to_publish}; do
if ! projectRoot=$(node -pe "require('${angular_json}').projects['${project}'].root"); then
log_error "unknown project: ${project}";
exit 1;
fi
done
for project in ${projects_to_publish}; do
projectTypeSelector="projects['${project}'].projectType"
projectType=$(node -pe "require('${angular_json}').${projectTypeSelector}")
case ${projectType} in
library)
# output dir for library is defined in ng-package.json
projectRoot=$(node -pe "require('${angular_json}').projects['${project}'].root")
projectRelativeOutputDir=$(node -pe "require('./${projectRoot}/ng-package.json').dest")
projectOutputDir=${projectRoot}/${projectRelativeOutputDir}
;;
*)
# other output dir is defined in angular.json
projectOutputDir=$(node -pe "require('${angular_json}').projects['${project}'].architect.build.options.outputPath")
log_warn "It is not recommended to publish a project with '${projectType}' type as npm package."
log_warn "Please consider using another packaging solution as this support might be limited."
# WORKAROUND:
# as application type projects don't generate a package.json which is required for publishing
# we generate one with the global package.json version
if [ ! -f "${projectOutputDir}/package.json" ]; then
global_version=$(node -pe "require('${package_json}').version")
cat > "${projectOutputDir}"/package.json <<- EOF
{
"name": "${project}",
"version": "${global_version}"
}
EOF
fi
;;
esac
projectOutputDir=$(realpath "${projectOutputDir}")
if [ ! -d "${projectOutputDir}" ]; then
log_error "'${project}' project output folder '${projectOutputDir}' not found"
log_error "please check that module '${project}' has been built"
exit 1
fi
log_info "Publishing project '${project}' from ${projectOutputDir}"
npm publish "${projectOutputDir}" "${NG_PUBLISH_ARGS}"
done
}
if [[ -z "$TEMPLATE_CHECK_UPDATE_DISABLED" ]]; then check_for_update angular "1.0.0"; fi
# ENDSCRIPT
###############################################################################################
# Generic job definition #
###############################################################################################
.ng-cli-base:
image: $NG_CLI_IMAGE
services:
- name: "$CI_REGISTRY/orange-opensource/tbc/tools/tracking:master"
command: ["--service", "angular", "1.0.0"]
# cache configuration
cache:
key: "$CI_COMMIT_REF_SLUG-angular"
paths:
- ${NG_WORKSPACE_DIR}/.npm/
before_script:
- *ng-cli-scripts
- cd ${NG_WORKSPACE_DIR}
- install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}"
# NPM_CONFIG_REGISTRY is not supported by old npm versions: force with cli
- if [[ "$NPM_CONFIG_REGISTRY" ]]; then npm config set registry $NPM_CONFIG_REGISTRY; fi
- configure_gitlab_instance_level_npm_registry_auth
- npm ci --cache .npm --prefer-offline
###############################################################################################
# check stage: #
# - ng-lint #
###############################################################################################
ng-lint:
extends: .ng-cli-base
stage: build
script:
# generate lint report for sonar
- sonar_lint_report
# display ng lint result for job console
- ng $NG_LINT_ARGS
artifacts:
when: always # save artifact even if test failed
name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
paths:
- $NG_WORKSPACE_DIR/reports
expire_in: 1 day
rules:
# exclude merge requests
- if: $CI_MERGE_REQUEST_ID
when: never
# on production or integration branches: auto
- if: '$CI_COMMIT_REF_NAME =~ $PROD_REF || $CI_COMMIT_REF_NAME =~ $INTEG_REF'
# else (development branches): auto & non-blocking
- allow_failure: true
###############################################################################################
# build stage: #
# - ng-build #
###############################################################################################
ng-build:
extends: .ng-cli-base
stage: build
script:
# build libs so they are available for other projects tests
- run_ng_build_libs
# launch unit test and code coverage
- ng $NG_TEST_ARGS --watch=false --no-progress
# build production artifact
- run_ng_build
coverage: '/^Statements\s*:\s*([^%]+)/'
artifacts:
reports:
junit: $NG_WORKSPACE_DIR/$NG_JUNIT_TEST_REPORT_PATH
when: always # save artifact even if test failed
name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
paths:
- $NG_WORKSPACE_DIR/coverage
- $NG_WORKSPACE_DIR/dist
- $NG_WORKSPACE_DIR/reports
expire_in: 1 day
rules:
# exclude merge requests
- if: '$CI_MERGE_REQUEST_ID == null'
###############################################################################################
# test stage: #
# - ng-e2e #
###############################################################################################
ng-e2e:
extends: .ng-cli-base
stage: test
script:
- ng $NG_E2E_ARGS
artifacts:
reports:
junit: $NG_WORKSPACE_DIR/$NG_WORKSPACE_DIR/$NG_E2E_REPORT_PATH/junit*.xml
when: always # save artifact even if test failed
name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
paths:
- $NG_WORKSPACE_DIR/$NG_E2E_REPORT_PATH
expire_in: 1 day
rules:
# exclude merge requests
- if: $CI_MERGE_REQUEST_ID
when: never
# only run if feature is enabled
- if: '$NG_E2E_ENABLED'
###############################################################################################
# publish stage: #
# - npm-publish #
###############################################################################################
npm-publish:
extends: .ng-cli-base
stage: publish
before_script:
- *ng-cli-scripts
- cd ${NG_WORKSPACE_DIR}
- install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}"
- configure_gitlab_instance_level_npm_registry_auth
- configure_npm_publish_registry_auth
- npm ci --cache .npm --prefer-offline
script:
- npm_publish
rules:
# exclude merge requests
- if: $CI_MERGE_REQUEST_ID
when: never
# on production branche: manual
- if: '$NG_PUBLISH_ENABLED && $CI_COMMIT_REF_NAME =~ $PROD_REF'
when: manual
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