0

I have this Angular library uploaded to a package registry that I created on Gitlab. I've already been able to upload my library successfully to this registry using the CI. I now want to implement semantic versionning to this library, but I'm not quite sure how to do it... The version of my library does not seem to update. Here is my current Gitlab CI config :

default:
  image: node:16
  before_script:
    - npm ci --cache node_modules --prefer-offline
  cache:
    key: ${CI_COMMIT_REF_SLUG}
    paths:
      - node_modules/

stages:
  - build
  - semver-check
  - deploy

build:
  only:
    - main
  stage: build
  script:
    - npm install
    - npm run build-lib
  artifacts:
    paths:
      - dist/

semver-check:
  stage: semver-check
  only:
    refs:
    - main
    - alpha
    - /^(([0-9]+)\.)?([0-9]+)\.x/
    - /^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/
  script:
    - cd $CI_PROJECT_DIR/dist/my-compiled-lib
    - cat package.json
    - npm install @semantic-release/gitlab
    - npx semantic-release
    - cat package.json

deploy:
  only:
    - main
  stage: deploy
  script:
    - cd $CI_PROJECT_DIR/dist/my-compiled-lib
    - cat package.json
    - echo "@my-group:registry https://${CI_SERVER_HOST}/api/v4/packages/npm/">.npmrc
    - echo "//${CI_SERVER_HOST}/api/v4/packages/npm/:_authToken=${CI_JOB_TOKEN}">>.npmrc
    - echo "//${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=${CI_JOB_TOKEN}">>.npmrc
    - npm publish
  dependencies:
    - build

Library package.json

{
  "name": "@my-group/angular-lib",
  "version": "1.0.6",
  "publishConfig": {
    "@my-group:registry": "https://gitlab.com/api/v4/projects/XXXXXXX/packages/npm/"
  },
  "scripts": {
    "build-lib": "ng build lib-angular",
    "semantic-release": "semantic-release"
  },
  "peerDependencies": {
    "@angular/cdk": "^13.0.0",
    "@angular/common": "^13.1.0",
    "@angular/core": "^13.1.0",
    "@angular/material": "^13.2.0",
    "ngx-bootstrap": "^8.0.0",
    "rxjs": "~7.4.0"
  },
  "dependencies": {
    "tslib": "^2.3.0"
  },
  "devDependencies": {
    "@semantic-release/gitlab": "^7.0.4",
    "semantic-release": "^19.0.2"
  }
}

.releaserc.yml

{
  "branches": ["main"],
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    [
      "@semantic-release/gitlab",
      {
        "gitlabUrl": "https://gitlab.com",
        "gitlabApiPathPrefix": "/api/v4",
        "verifyConditions": []
      }
    ],
    ["@semantic-release/npm", {
      "npmPublish": false,
      "tarballDir": "dist"
    }],
    [
      "@semantic-release/git",
      {
        "assets": ["dist/my-compiled-lib/package.json"],
        "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
      }
    ]
  ]
}
gabhar
  • 187
  • 1
  • 4
  • 14
  • You get some errors perhaps? Also is your releaserc.yml complete? It seems that you are missing the assets tag under the gitlab plugin (see: https://github.com/semantic-release/gitlab). – Bram Feb 09 '22 at 16:53
  • I do not get any errors on the semantic-release part. Yes, the releaserc.yml is complete. Concerning the assets tags, what should I put in it, considering I want to push my entire package ? – gabhar Feb 09 '22 at 18:31
  • Maybe `'.'` for the entire repo? – Bram Feb 09 '22 at 20:05

1 Answers1

0

The problem was that I was not triggering a release with my commit messages. Once that was sorted out, the package.json updated normally.

gabhar
  • 187
  • 1
  • 4
  • 14