Skip to content

Commit

Permalink
Merge branch 'master' into issue-29148-Modifying-the-Template-breaks-…
Browse files Browse the repository at this point in the history
…pages-on-the-receiver
  • Loading branch information
freddyDOTCMS authored Aug 29, 2024
2 parents b5a1836 + acbd281 commit dfd46cf
Show file tree
Hide file tree
Showing 15 changed files with 733 additions and 248 deletions.
81 changes: 81 additions & 0 deletions .github/actions/core-cicd/deployment/deploy-sdk-npm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# GitHub Action: SDK Publish NPM Packages

This GitHub Action is designed to automate the process of publishing dotCMS SDK libraries to the NPM registry. It performs the following tasks:

1. **Checks out the specified branch of the repository**.
2. **Sets up the required Node.js environment**.
3. **Retrieves the next version of the SDK from the package.json file**.
4. **Validates the version number against the existing version in the NPM registry**.
5. **Publishes the SDK libraries to the NPM registry if validation passes**.

## Inputs

| Name | Description | Required | Default |
|------------------|-----------------------------------|----------|---------|
| `ref` | Branch to build from | No | `master`|
| `npm-token` | NPM token | Yes | |
| `npm-package-tag`| Package tag | No | `alpha` |
| `node-version` | Node.js version | No | `19` |
| `github-token` | GitHub Token | Yes | |

## Outputs

| Name | Description |
|----------------------|---------------------------------------|
| `npm-package-version`| SDK libs - NPM package version |

## Steps Overview

1. **Checkout**: Checks out the specified branch of the repository.
2. **Set up Node.js**: Sets up the Node.js environment based on the provided version.
3. **Get Next Version**: Retrieves the next version from the `package.json` file of the SDK.
4. **Validate Version**: Validates whether the next version is correct and whether it should be published.
5. **Publish SDK into NPM Registry**: Publishes the SDK libraries to NPM if the version is validated.

## Detailed Steps
1. **Checkout**
The action uses `actions/checkout@v4` to check out the specified branch, allowing the workflow to access the repository's contents.

2. **Set Up Node.js**
`actions/setup-node@v4` sets up the Node.js environment, crucial for running scripts and managing dependencies.

3. **Get Next Version**
This step retrieves the next version of the SDK by reading the `package.json` file from the specified directory.

4. **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.

5. **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.

### Notes

- Ensure that the NPM token provided has the correct permissions to publish packages.
- The action assumes that the `package.json` files are located under `core-web/libs/sdk/client`.
- The publish step only runs if the version validation passes, ensuring that no duplicate versions are published.

## Usage Example

Below is an example of how to use this GitHub Action in your workflow file:

```yaml
name: 'Publish SDK Libraries'
on:
push:
branches:
- master
workflow_dispatch:

jobs:
publish-sdk:
runs-on: ubuntu-latest
steps:
- name: Publish to NPM
uses: ./path-to-this-action
with:
ref: 'master'
npm-token: ${{ secrets.NPM_TOKEN }}
npm-package-tag: 'latest'
node-version: '18'
github-token: ${{ secrets.GITHUB_TOKEN }}
```
105 changes: 105 additions & 0 deletions .github/actions/core-cicd/deployment/deploy-sdk-npm/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: 'SDK Publish NPM Packages'
description: 'Publish the dotCMS SDK libs on NPM registry.'
inputs:
ref:
description: 'Branch to build from'
required: false
default: 'master'
npm-token:
description: 'NPM token'
required: true
npm-package-tag:
description: 'Package tag'
required: false
default: 'alpha'
node-version:
description: 'Node.js version'
required: false
default: '19'
github-token:
description: 'GitHub Token'
required: true
outputs:
npm-package-version:
description: 'SDK libs - NPM package version'
value: ${{ steps.next_version.outputs.next_version }}
published:
description: 'SDK libs - Published'
value: ${{ steps.next_version.outputs.publish }}
runs:
using: "composite"
steps:
- name: 'Checkout'
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
token: ${{ inputs.github-token }}

- name: 'Set up Node.js'
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}

- name: 'Get next version'
id: next_version
run: |
next_version=$(node -p "require('./core-web/libs/sdk/client/package.json').version")
echo "next_version=${next_version}" >> $GITHUB_OUTPUT
shell: bash

- name: 'Valitate version'
id: validate_version
run: |
echo "::group::Validating version"
publish=false
NPM_INFO=$(npm view '@dotcms/client' --json)
VERSIONS=$(echo "$NPM_INFO" | jq '.versions')
CURRENT_VERSION=$(echo "$NPM_INFO" | jq -r '.version')
NEXT_VERSION=${{ steps.next_version.outputs.next_version }}
base_number=$(echo "$CURRENT_VERSION" | grep -oE '[0-9]+$')
next_number=$((base_number + 1))
prefix=$(echo "$CURRENT_VERSION" | sed -E 's/[0-9]+$//')
EXPECTED_VERSION="$prefix$next_number"
NEXT_VERSION_EXISTS=$(echo "$VERSIONS" | jq --arg item "$NEXT_VERSION" -r '.[] | select(. == $item)')
echo "::notice::EXPECTED VERSION: $EXPECTED_VERSION"
echo "::notice::NEXT VERSION: $NEXT_VERSION"
if [ -n "$NEXT_VERSION_EXISTS" ]; then
echo "Version $NEXT_VERSION already exists in NPM registry"
elif [[ "$NEXT_VERSION" != "$EXPECTED_VERSION" ]]; then
echo "Version $NEXT_VERSION is not the expected version."
else
publish=true
fi
echo "::notice::PUBLISH: $publish"
echo "publish=$publish" >> $GITHUB_OUTPUT
echo "::endgroup::"
shell: bash

- name: 'Publishing sdk into NPM registry'
if: ${{ steps.validate_version.outputs.publish == 'true' }}
working-directory: ${{ github.workspace }}/core-web/libs/sdk/
env:
NEXT_VERSION: ${{ steps.next_version.outputs.next_version }}
NPM_AUTH_TOKEN: ${{ inputs.npm-token }}
NPM_TAG: ${{ inputs.npm-package-tag }}
run: |
echo "::group::Publishing SDK packages"
sdks=$(ls)
for sdk in $sdks; do
echo "Publishing SDK lib [${sdk}]"
cd $sdk && echo "$(pwd)"
echo "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}" > ~/.npmrc
npm publish --access public --tag $NPM_TAG
npm dist-tag $NEXT_VERSION latest
cd ..
done
echo "::endgroup::"
shell: bash

47 changes: 47 additions & 0 deletions .github/actions/core-cicd/notification/notify-slack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Slack Notification GitHub Action

This GitHub Action sends a notification to a specified Slack channel using a provided payload in Markdown format. It's particularly useful for sending custom messages from your CI/CD pipelines directly to your Slack channels.

## Inputs

| Name | Description | Required | Default |
| ---------------- | ----------------------------------------------- | -------- | ------- |
| `channel-id` | The ID of the Slack channel to send the message to. | `true` | |
| `payload` | The message payload in Markdown format. | `true` | |
| `slack-bot-token`| The Slack Bot Token used for authentication. | `true` | |

## Example Usage

Here is an example of how to use this action in your GitHub workflow file:

```yaml
name: Notify Slack on Success

on:
push:
branches:
- main

jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Send Slack Notification
uses: ./
with:
channel-id: 'C12345678'
payload: |
"Build succeeded! :tada:
*Branch:* ${{ github.ref_name }}
*Commit:* ${{ github.sha }}
*Author:* ${{ github.actor }}"
slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
```
## Inputs Description
**channel-id**: The Slack channel ID where the notification will be posted. Make sure to use the correct ID (e.g., C12345678 for public channels or G12345678 for private channels).
**payload**: The content of the message, written in Markdown format. You can use standard Slack markdown for formatting.
**slack-bot-token**: Your Slack bot token, which should be stored as a secret in your GitHub repository for security purposes.
### Note
> Ensure that your Slack Bot Token has the necessary permissions to post messages to the specified channel. If you encounter any issues with permissions, review your Slack app's OAuth scopes.
34 changes: 34 additions & 0 deletions .github/actions/core-cicd/notification/notify-slack/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: 'Slack notification'
description: 'Send a notification to Slack'
inputs:
channel-id:
description: 'Channel ID to send the notification to'
required: true
payload:
description: 'Payload to send to Slack in MARKDOWN format'
required: true
slack-bot-token:
description: 'Slack Bot Token'
required: true

runs:
using: "composite"
steps:
- name: Slack Notification
uses: slackapi/[email protected]
with:
channel-id: ${{ inputs.channel-id }}
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "${{ inputs.payload }}"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ inputs.slack-bot-token }}
3 changes: 3 additions & 0 deletions .github/filters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ cli: &cli
- *full_build_test
- *backend

sdk_libs: &sdk_libs
- 'core-web/libs/sdk/**'

jvm_unit_test:
- *backend
- *cli
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cicd_1-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
name: Initialize
uses: ./.github/workflows/cicd_comp_initialize-phase.yml
with:
incremental: true
validation-level: 'full'

# Build job - only runs if no artifacts were found during initialization
build:
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/cicd_3-trunk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ on:
description: 'Run all tests'
type: boolean
default: false
publish-npm-sdk-libs:
description: 'Publish NPM SDKs'
type: boolean
default: false

jobs:
# Initialize the trunk check process
Expand All @@ -39,6 +43,8 @@ jobs:
with:
reuse-previous-build: ${{ inputs.reuse-previous-build || github.event_name != 'workflow_dispatch' }}
build-on-missing-artifacts: ${{ inputs.build-on-missing-artifacts || github.event_name != 'workflow_dispatch' }}
validation-level: 'custom'
custom-modules: 'sdk_libs'

# Build job - only runs if no artifacts were found during initialization
build:
Expand Down Expand Up @@ -95,6 +101,7 @@ jobs:
uses: ./.github/workflows/cicd_comp_deployment-phase.yml
with:
artifact-run-id: ${{ needs.initialize.outputs.artifact-run-id }}
publish-npm-sdk-libs: ${{ needs.initialize.outputs.sdk_libs != 'false' && github.event_name != 'workflow_dispatch' }}
environment: trunk
secrets:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/cicd_4-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ on:
type: boolean
description: 'Indicates if the workflow should build on missing artifacts'
default: true
publish-npm-package:
publish-npm-cli:
type: boolean
description: 'Indicates if the workflow should publish the NPM package on the registry'
default: false
Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:
artifact-run-id: ${{ needs.initialize.outputs.artifact-run-id }}
environment: nightly
deploy-dev-image: true
publish-npm-package: ${{ ( github.event_name == 'workflow_dispatch' && inputs.publish-npm-package == true ) || github.event_name == 'schedule' }}
publish-npm-cli: ${{ ( github.event_name == 'workflow_dispatch' && inputs.publish-npm-cli == true ) || github.event_name == 'schedule' }}
reuse-previous-build: ${{ inputs.reuse-previous-build || false }}
secrets:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
Expand Down
Loading

0 comments on commit dfd46cf

Please sign in to comment.