From d35a4d33d4679e70cc9ae6a45d8a1df02360d590 Mon Sep 17 00:00:00 2001 From: Daniel Colina Date: Wed, 17 Jul 2024 19:58:51 +0200 Subject: [PATCH] #28259 Testing publish-npm-sdks action. --- .github/actions/publish-npm-sdks/action.yml | 83 +++++++++++++++++++++ .github/filters.yaml | 3 + .github/workflows/build-test-master.yml | 5 ++ .github/workflows/build-test-nightly.yml | 9 ++- .github/workflows/reusable-deployment.yml | 17 ++++- .github/workflows/reusable-initialize.yml | 8 +- 6 files changed, 119 insertions(+), 6 deletions(-) create mode 100644 .github/actions/publish-npm-sdks/action.yml diff --git a/.github/actions/publish-npm-sdks/action.yml b/.github/actions/publish-npm-sdks/action.yml new file mode 100644 index 000000000000..43435e96021a --- /dev/null +++ b/.github/actions/publish-npm-sdks/action.yml @@ -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 \ No newline at end of file diff --git a/.github/filters.yaml b/.github/filters.yaml index 2c17e6f376a9..24d1a8272cad 100644 --- a/.github/filters.yaml +++ b/.github/filters.yaml @@ -22,6 +22,9 @@ frontend: &frontend cli: &cli - 'tools/dotcms-cli/**' +sdk: + - 'core-web/libs/sdk/**' + jvm_unit_test: - *backend - *cli diff --git a/.github/workflows/build-test-master.yml b/.github/workflows/build-test-master.yml index 74e23804c3f3..8ff3ee554cb9 100644 --- a/.github/workflows/build-test-master.yml +++ b/.github/workflows/build-test-master.yml @@ -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 @@ -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 }} diff --git a/.github/workflows/build-test-nightly.yml b/.github/workflows/build-test-nightly.yml index d65b49fb3f75..77df77133859 100644 --- a/.github/workflows/build-test-nightly.yml +++ b/.github/workflows/build-test-nightly.yml @@ -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 @@ -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 }} diff --git a/.github/workflows/reusable-deployment.yml b/.github/workflows/reusable-deployment.yml index 154116e563ff..0fd7977b8db5 100644 --- a/.github/workflows/reusable-deployment.yml +++ b/.github/workflows/reusable-deployment.yml @@ -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: @@ -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) @@ -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/slack-github-action@v1.26.0 with: channel-id: "log-dotcli" diff --git a/.github/workflows/reusable-initialize.yml b/.github/workflows/reusable-initialize.yml index cdded4b198f3..73eda30b6c57 100644 --- a/.github/workflows/reusable-initialize.yml +++ b/.github/workflows/reusable-initialize.yml @@ -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 @@ -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 }} @@ -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' @@ -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 \ No newline at end of file + echo "jvm_unit_test=${jvm_unit_test}" >> $GITHUB_OUTPUT + echo "sdk=${sdk}" >> $GITHUB_OUTPUT \ No newline at end of file