-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into issue-29148-Modifying-the-Template-breaks-…
…pages-on-the-receiver
- Loading branch information
Showing
15 changed files
with
733 additions
and
248 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
.github/actions/core-cicd/deployment/deploy-sdk-npm/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
105
.github/actions/core-cicd/deployment/deploy-sdk-npm/action.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
47
.github/actions/core-cicd/notification/notify-slack/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
34
.github/actions/core-cicd/notification/notify-slack/action.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.