1.3.1 • Published 1 year ago

@pubgcorp/semantic-release-gitlabmonorepo v1.3.1

Weekly downloads
-
License
-
Repository
github
Last release
1 year ago

StepDescription
verifyConditionsVerify the presence of some requirements environment and config variable.
publishPush a Git Assets for the package.

Install

npm install -D @pubgcorp/semantic-release-gitlabmonorepo

Usage

The plugin can be used by adding it to the plugins field in the release configuration of your package.json.

.releaserc

{
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    [
      "@semantic-release/changelog",
      {
        "changelogFile": "CHANGELOG.md"
      }
    ],
    "@semantic-release/npm",
    [
      "@pubgcorp/semantic-release-gitlabmonorepo",
      {
        "gitlabUrl": "https://gitlab.tythonic.com",
        "assets": [
          {
            "path": "CHANGELOG.md"
          },
          {
            "path": "package.json"
          }
        ]
      }
    ]
  ]
}

Root CI configuration:

stages:
  - publish

.publish:
  stage: publish
  before_script:
    - npm ci
  script:
    - cd ${PACKAGE_PATH}
    - npx semantic-release
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      changes:
        paths:
          - $PACKAGE_PATH/**/*

include:
  - local: "**/.gitlab-ci.yml"

Each package CI configuration:

my-package.publish:
  extends: .publish
  variables:
    PACKAGE_PATH: my-package

With this configurations, the plugin will push the CHANGELOG.md and package.json files to the GitLab repository.

Configuration

Gitlab authentication

The GitLab authentication is done using the GITLAB_TOKEN or GITLAB_ACCESS_TOKEN environment variable. The token must have the api scope.

Environment variables

VariableDescription
GITLAB_TOKEN or GITLAB_ACCESS_TOKENRequired. The token used to authenticate with GitLab.
CI_SERVER_URLOptional. The gitlab endpoint.
CI_PROJECT_ID or CI_PROJECT_PATHOptional. The project identifier.

The above environment variables are automatically set by GitLab CI/CD.

If you are using this plugin on GitLab CI/CD, you don't need to set any environment variables.

GitLab Monorepo Plugin Options

OptionDescriptionDefault
gitlabUrlOptional. The GitLab URL.CI_SERVER_URL environment variable or https://gitlab.com
projectIdOptional. The GitLab project ID.CI_PROJECT_ID or CI_PROJECT_PATH environment variable or read from git origin url.
commitTitleOptional. The commit title message to pushed assets.chore(release): ${nextRelease.name} [skip ci]
branchNameOptional. The branch name to merge each assets.assets/${commit.short}
assetsOptional. The assets to be pushed.[]
ignorePrereleaseOptional. Ignore prerelease version.true

commitTitle and branchName template

The commitTitle and branchName options support the following template variables:

VariableDescription
nextRelease.nameThe release version.
nextRelease.typeThe release type.
nextRelease.notesThe release notes.
lastRelease.versionThe release version.
lastRelease.gitTagThe release git tag.
lastRelease.channelsThe release channels.
lastRelease.gitHeadThe release git head.
lastRelease.nameThe release name.
branchThe branch name.
commit.fullThe full commit hash.
commit.shortThe short commit hash.

Example Monorepo Pipeline

With this plugin, you can run multiple semantic-release in a single pipeline like below.

img_1.png

Add a merge-published-assets stage at the end of the Gitlab CI to merge the releases of each package.

merge-published-assets:
  stage: merge-published-assets
  when: on_success
  variables:
  script:
    - npm install --global @pubgcorp/semantic-release-gitlabmonorepo
    - export SHORT_COMMIT_HASH=$(git rev-parse --short HEAD)
    - set -x
    - semantic-release-gitlabmonorepo-helper create --project-id $CI_PROJECT_ID --source-branch "assets/${SHORT_COMMIT_HASH}" --target-branch $CI_COMMIT_BRANCH --title "chore(release): Merge published assets from ${CI_COMMIT_MESSAGE} [skip ci]"
    - export MERGE_REQUEST_IID=$(gitbeaker merge-requests create --project-id $CI_PROJECT_ID --source-branch "assets/${SHORT_COMMIT_HASH}" --target-branch $CI_COMMIT_BRANCH --title "Merge published assets from ${CI_COMMIT_MESSAGE} [skip ci]" | jq -r '.iid')
    - sleep 5
    - semantic-release-gitlabmonorepo-helper merge --project-id $CI_PROJECT_ID --merge-request-iid $MERGE_REQUEST_IID
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
1.3.1

1 year ago

1.3.0

1 year ago

1.2.7

1 year ago

1.2.6

1 year ago

1.2.5

1 year ago

1.2.4

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago