This GitHub Action is designed to automate the process of publishing dotCMS SDK libraries to the NPM registry. It performs the following tasks:
- Checks out the specified branch of the repository.
- Sets up the required Node.js environment.
- Retrieves the next version of the SDK from the package.json file.
- Validates the version number against the existing version in the NPM registry.
- Publishes the SDK libraries to the NPM registry if validation passes.
| Name | Description | Required | Default |
|---|---|---|---|
ref |
Branch to build from | No | main |
npm-token |
NPM token | Yes | |
npm-package-tag |
Package tag | No | alpha |
node-version |
Node.js version | No | 19 |
github-token |
GitHub Token | Yes |
| Name | Description |
|---|---|
npm-package-version |
SDK libs - NPM package version |
- Checkout: Checks out the specified branch of the repository.
- Set up Node.js: Sets up the Node.js environment based on the provided version.
- Get Next Version: Retrieves the next version from the
package.jsonfile of the SDK. - Validate Version: Validates whether the next version is correct and whether it should be published.
- Publish SDK into NPM Registry: Publishes the SDK libraries to NPM if the version is validated.
-
Checkout
The action usesactions/checkout@v5to check out the specified branch, allowing the workflow to access the repository's contents. -
Set Up Node.js
actions/setup-node@v5sets up the Node.js environment, crucial for running scripts and managing dependencies. -
Get Next Version
This step retrieves the next version of the SDK by reading thepackage.jsonfile from the specified directory. -
Validate Version
The version retrieved in the previous step is compared to the current version in the NPM registry. The workflow checks if the version is already published or if it follows the expected versioning scheme. -
Publish SDK into NPM Registry
If the validation passes, the SDK libraries are published to the NPM registry. The libraries are iterated over, and each is published using the provided NPM token and tag.
- The versions of the SDK libraries will be incremented in the NPM registry, but they will not be updated in the codebase itself through this process. This simplification avoids automatic pull requests and all the considerations necessary due to protections on the main branch, as well as the lengthy execution process that would be required to ultimately publish the libraries.
- This is a temporary solution until we determine the most appropriate pattern to handle the lifecycle of each module that needs to be released individually (e.g., dotCLI and the SDKs).
- Additionally, the example projects should point to the 'latest' tag to ensure that version updates do not impact their functionality due to version inconsistency.
- Ensure that the NPM token provided has the correct permissions to publish packages.
- The action assumes that the
package.jsonfiles are located undercore-web/libs/sdk/client.
Below is an example of how to use this GitHub Action in your workflow file:
name: 'Publish SDK Libraries'
on:
push:
branches:
- main
workflow_dispatch:
jobs:
publish-sdk:
runs-on: ubuntu-${{ vars.UBUNTU_RUNNER_VERSION || '24.04' }}
steps:
- name: Publish to NPM
uses: ./.github/actions/core-cicd/deployment/deploy-javascript-sdk
with:
ref: 'main'
npm-token: ${{ secrets.NPM_TOKEN }}
npm-package-tag: 'latest'
node-version: '18'
github-token: ${{ secrets.GITHUB_TOKEN }}