Skip to content

Commit

Permalink
dotCMS#28259 Testing publish-npm-sdks action.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcolina committed Jul 17, 2024
1 parent 3170cbd commit d35a4d3
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 6 deletions.
83 changes: 83 additions & 0 deletions .github/actions/publish-npm-sdks/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
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'
node-version:
description: 'Node.js version'
required: false
default: '19'
runs:
using: "composite"
steps:
- name: 'Checkout'
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}

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

- name: 'Install dependencies'
working-directory: ${{ github.workspace }}/core-web
run: npm install
shell: bash

- name: 'Get current version from NPM'
id: current_version
run: |
echo "::group::Get current version"
CURRENT_VERSION=$(npm view @dotcms/client dist-tags --json | jq -r '.alpha')
echo "Current version: $CURRENT_VERSION"
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "::endgroup::"
shell: bash

- name: Calculate next version
id: next_version
env:
CURRENT_VERSION: ${{ steps.current_version.outputs.current_version }}
run: |
echo "::group::Calculate next version"
VERSION_PARTS=(${CURRENT_VERSION//./ })
BASE_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.${VERSION_PARTS[2]}"
ALPHA_PART=${VERSION_PARTS[3]#*-}
ALPHA_NUMBER=${ALPHA_PART#*.}
NEW_ALPHA_NUMBER=$((ALPHA_NUMBER + 1))
NEXT_VERSION="${BASE_VERSION}-alpha.${NEW_ALPHA_NUMBER}"
echo "Next version: $NEXT_VERSION"
echo "next_version::$NEXT_VERSION" >> $GITHUB_OUTPUT
echo "::endgroup::"
shell: bash

- name: 'Printing versions'
working-directory: ${{ github.workspace }}/core-web/libs/sdk/
env:
NEXT_VERSION: ${{ steps.next_version.outputs.next_version }}
CURRENT_VERSION: ${{ steps.current_version.outputs.current_version }}
run: |
echo "::group::Update versions"
echo "Current version: $CURRENT_VERSION"
echo "Next version: $NEXT_VERSION"
echo "::endgroup::"
shell: bash

- name: 'Update versions and dependencies'
working-directory: ${{ github.workspace }}/core-web/libs/sdk/
env:
NEXT_VERSION: ${{ steps.next_version.outputs.next_version }}
run: |
echo "Updating version to $NEXT_VERSION"
# npm version $NEXT_VERSION --no-git-tag-version
SDKS=$(ls -ls core-web/libs/sdk | awk '{ print$10 }' | tr "," "\n")
for dir in $(echo $SDKS);
do
echo "Updating $dir"
(cd $dir && npm version $NEXT_VERSION --no-git-tag-version)
done
npm install
shell: bash
3 changes: 3 additions & 0 deletions .github/filters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ frontend: &frontend
cli: &cli
- 'tools/dotcms-cli/**'

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

jvm_unit_test:
- *backend
- *cli
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/build-test-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ on:
description: 'Run all tests'
type: boolean
default: false
publish-npm-sdks:
description: 'Publish NPM SDKs'
type: boolean
default: false
jobs:
initialize:
name: Initialize
Expand Down Expand Up @@ -74,6 +78,7 @@ jobs:
uses: ./.github/workflows/reusable-deployment.yml
with:
artifact-run-id: ${{ needs.initialize.outputs.artifact-run-id }}
publish-npm-sdks: ${{ inputs.publish-npm-sdks || false }}
environment: trunk
secrets:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/build-test-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ 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
publish-npm-sdks:
type: boolean
description: 'Indicates if the workflow should publish the NPM SDKs on the registry'
default: false
run-all-tests:
description: 'Run all tests'
type: boolean
Expand Down Expand Up @@ -65,7 +69,8 @@ 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' }}
publish-npm-sdks: ${{ inputs.publish-npm-sdks == true }}
reuse-previous-build: ${{ inputs.reuse-previous-build || false }}
secrets:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
Expand Down
17 changes: 14 additions & 3 deletions .github/workflows/reusable-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ on:
reuse-previous-build:
default: false
type: boolean
publish-npm-package:
publish-npm-cli:
default: false
type: boolean
publish-npm-sdks:
default: false
type: boolean
secrets:
Expand Down Expand Up @@ -104,13 +107,21 @@ jobs:

- name: CLI Publish
id: cli_publish
if: inputs.publish-npm-package
if: inputs.publish-npm-cli
uses: ./.github/actions/publish-npm-cli
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
npm-token: ${{ secrets.NPM_ORG_TOKEN }}
cli-artifact-run-id: ${{ github.run_id }} # currently cli artifacts are never from build queue

- name: SDKs Publish
id: sdks_publish
if: inputs.publish-npm-sdks
uses: ./.github/actions/publish-npm-sdks
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
npm-token: ${{ secrets.NPM_ORG_TOKEN }}
sdk-artifact-run-id: ${{ github.run_id }} # currently sdk artifacts are never from build queue

# A Slack notification is sent using the 'slackapi/slack-github-action' action if the repository is 'dotcms/core'.
- name: Slack Notification (Docker image announcement)
Expand All @@ -134,7 +145,7 @@ jobs:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}

- name: Slack Notification (dotCLI announcement)
if: inputs.publish-npm-package
if: inputs.publish-npm-cli
uses: slackapi/[email protected]
with:
channel-id: "log-dotcli"
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/reusable-initialize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ on:
value: ${{ jobs.changes.outputs.jvm_unit_test }}
cli:
value: ${{ jobs.changes.outputs.cli }}
sdk:
value: ${{ jobs.changes.outputs.sdk }}
jobs:
initialize: # This is used as a required check to indicate that the workflow has started and is running
name: Initialize
Expand Down Expand Up @@ -95,6 +97,7 @@ jobs:
frontend: ${{ steps.filter-rewrite.outputs.frontend }}
jvm_unit_test: ${{ steps.filter-rewrite.outputs.jvm_unit_test }}
cli: ${{ steps.filter-rewrite.outputs.cli }}
sdk: ${{ steps.filter-rewrite.outputs.sdk }}
steps:
- uses: actions/checkout@v4
if: ${{ inputs.incremental }}
Expand All @@ -115,6 +118,7 @@ jobs:
backend=${{ steps.filter.outputs.backend || 'true' }}
build=${{ steps.filter.outputs.build || 'true' }}
jvm_unit_test=${{ steps.filter.outputs.jvm_unit_test || 'true' }}
sdk=${{ steps.filter.outputs.sdk || 'false' }}
# Check if the commit is to the master branch
skip_tests=${CICD_SKIP_TESTS:-false} # Use environment variable, default to 'false'
Expand All @@ -133,10 +137,12 @@ jobs:
echo "cli=${cli}"
echo "backend=${backend}"
echo "jvm_unit_test=${jvm_unit_test}"
echo "sdk=${sdk}"
# Export the outcomes as GitHub Actions outputs
echo "frontend=${frontend}" >> $GITHUB_OUTPUT
echo "cli=${cli}" >> $GITHUB_OUTPUT
echo "backend=${backend}" >> $GITHUB_OUTPUT
echo "build=${build}" >> $GITHUB_OUTPUT
echo "jvm_unit_test=${jvm_unit_test}" >> $GITHUB_OUTPUT
echo "jvm_unit_test=${jvm_unit_test}" >> $GITHUB_OUTPUT
echo "sdk=${sdk}" >> $GITHUB_OUTPUT

0 comments on commit d35a4d3

Please sign in to comment.