diff --git a/.github/workflows/release-github.yml b/.github/workflows/release-github.yml index 8f0af68c9..383976ab3 100644 --- a/.github/workflows/release-github.yml +++ b/.github/workflows/release-github.yml @@ -3,11 +3,15 @@ on: workflow_dispatch: push: branches: + - 'main' - 'next' + - 'next-major' + - 'proposed' pull_request: types: [opened, synchronize] branches: - 'next' + - 'proposed' env: HUSKY: 0 jobs: @@ -19,13 +23,13 @@ jobs: steps: # Checkout/install project - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 0 repo-token: ${{ secrets.SEMANTIC_RELEASE_BOT_PAT }} persist-credentials: false - name: Setup Node.js - uses: actions/setup-node@v2 + uses: actions/setup-node@v4 with: node-version: 'lts/*' - name: Set up NPM token @@ -36,6 +40,21 @@ jobs: run: npm ci # Set NPM_DIST_TAGS and DOCS_TAG if applicable based on branch + - name: Set main tags + if: github.ref_name == 'main' && github.event_name != 'pull_request' + run: | + echo "NPM_DIST_TAG=latest" >> $GITHUB_ENV + echo "DOCS_TAG=latest" >> $GITHUB_ENV + - name: Set next tags + if: github.ref_name == 'next' && github.event_name != 'pull_request' + run: | + echo "NPM_DIST_TAG=next" >> $GITHUB_ENV + echo "DOCS_TAG=next" >> $GITHUB_ENV + - name: Set next-major tags + if: github.ref_name == 'next-major' && github.event_name != 'pull_request' + run: | + echo "NPM_DIST_TAG=next-major" >> $GITHUB_ENV + echo "DOCS_TAGE=next-major" >> $GITHUB_ENV - name: Set feature branch tags if: github.ref_name != 'main' && github.ref_name != 'next' && github.ref_name != 'next-major' && github.event_name != 'pull_request' run: | @@ -47,12 +66,24 @@ jobs: echo "NPM_DIST_TAG=test" >> $GITHUB_ENV echo "DOCS_TAG=pr-$(node ./src/js/version.mjs branch-to-prerelease ${{ github.head_ref }})" >> $GITHUB_ENV echo "FEATURE_BRANCH=${{ github.head_ref }}" >> $GITHUB_ENV - - name: Set file permissions run: | chmod -R 755 ./ chown -R $(id -u):$(id -g) ./ - + # Perform real (When not a PR) or dry-run (When PR) semantic-release + - name: Release mono-artifact to GitHub + if: (github.ref_name != 'main' && github.event_name != 'pull_request') || github.event_name == 'workflow_dispatch' + env: + GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_BOT_PAT }} # <-- Allows semantic-release-bot to push changes to protected branches + DEBUG: semantic-release:* + run: | + git config --global --add safe.directory /__w/firebolt-apis/firebolt-apis + npx semantic-release + - name: Dry-run mono-artifact + if: (github.ref_name == 'main' && github.event_name != 'workflow_dispatch') || github.event_name == 'pull_request' + env: + GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_BOT_PAT }} # <-- Allows semantic-release-bot to push changes to protected branches + run: npx semantic-release --dry-run - name: Build artifacts for feature branches if: github.ref_name != 'main' && github.ref_name != 'next' && github.ref_name != 'next-major' run: | @@ -61,33 +92,29 @@ jobs: npm version prerelease --preid $PRERELEASE --git-tag-version false npm version prerelease --preid $PRERELEASE --workspaces --git-tag-version false npm run dist - - name: Check if semantic-release created a build id: check_build - uses: andstor/file-existence-action@v2 + uses: andstor/file-existence-action@v3 with: files: './src/sdks/core/dist/lib/firebolt.mjs' - - name: Get version from package.json run: | RELEASE_VERSION=$(node -p "require('./package.json').version") echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV echo "build_cpp_source=true" >> $GITHUB_ENV - - name: Set cpp build source Condition if: steps.check_build.outputs.files_exists == 'false' || (github.ref_name == 'main' && github.event_name != 'pull_request' && github.event_name != 'workflow_dispatch') run: echo "build_cpp_source=false" >> $GITHUB_ENV + - name: Generate native sdk source + if: env.build_cpp_source == 'true' + run: | + .github/workflows/utils.sh generateSource - name: Clone and Install Thunder if: env.build_cpp_source == 'true' id: install_thunder run: | .github/workflows/utils.sh cloneAndInstallThunder - - - name: Generate native sdk source - if: env.build_cpp_source == 'true' - run: | - .github/workflows/utils.sh generateSource - name: Build Core SDK CPP if: env.build_cpp_source == 'true' id: build_core_cpp @@ -103,3 +130,36 @@ jobs: # id: build_discovery_cpp # run: | # .github/workflows/utils.sh buildDiscoveryCPPSDK $RELEASE_VERSION + + - name: Release Firebolt SDKs to NPM + if: steps.check_build.outputs.files_exists == 'true' && github.event_name != 'pull_request' && (github.ref_name != 'main' || github.event_name == 'workflow_dispatch') + env: + NPM_TOKEN: ${{ secrets.SEMANTIC_RELEASE_NPM_TOKEN }} # <-- Allows semantic-release to publish to npm without 2 factor auth. + run: | + npm --version + echo "NPM DIST TAG ::: " $NPM_DIST_TAG + npm publish --tag $NPM_DIST_TAG --workspaces + - name: Dry-run Firebolt SDKs to NPM + if: steps.check_build.outputs.files_exists == 'true' && (github.ref_name == 'main' && github.event_name != 'workflow_dispatch') + env: + NPM_TOKEN: ${{ secrets.SEMANTIC_RELEASE_NPM_TOKEN }} # <-- Allows semantic-release to publish to npm without 2 factor auth. + run: npm publish --tag $NPM_DIST_TAG --workspaces --dry-run + - name: Checkout firebolt GitHub.io repository + if: steps.check_build.outputs.files_exists == 'true' + env: + GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_BOT_PAT }} # <-- Allows semantic-release-bot to push changes to protected branches + run: | + cd /tmp + git clone https://rdkcentral:$GITHUB_TOKEN@github.com/rdkcentral/firebolt.git ./firebolt-docs + - name: Release docs to GitHub.io + if: steps.check_build.outputs.files_exists == 'true' && (github.ref_name == 'main' || github.ref_name == 'next' || github.ref_name == 'next-major' || github.event_name == 'pull_request') + env: + GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_BOT_PAT }} # <-- Allows semantic-release-bot to push changes to protected branches + run: | + npm run publish:docs /tmp/firebolt-docs $DOCS_TAG + cd /tmp/firebolt-docs + git config --global user.email "you@example.com" + git config --global user.name "Your Name" + git add --all + git diff-index --quiet HEAD || git commit -m "chore: Publish $DOCS_TAG" + git push diff --git a/package-lock.json b/package-lock.json index f7f527e79..1d717468e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "devDependencies": { "@commitlint/cli": "^17.0.3", "@commitlint/config-conventional": "^17.0.3", - "@firebolt-js/openrpc": "3.0.0-next.8", + "@firebolt-js/openrpc": "3.0.0-next.7", "@firebolt-js/schemas": "2.0.0", "@saithodev/semantic-release-backmerge": "^3.2.0", "@semantic-release/changelog": "^6.0.1", @@ -1075,9 +1075,9 @@ "link": true }, "node_modules/@firebolt-js/openrpc": { - "version": "3.0.0-next.8", - "resolved": "https://registry.npmjs.org/@firebolt-js/openrpc/-/openrpc-3.0.0-next.8.tgz", - "integrity": "sha512-u2tkFmFmNjoEVUeAxUGM675RRVInJNE5dwfUlEM38zXrI4mY/kRU1Y+s8PO4XF1abo2lZkgpkh1YkWqfSLwXPg==", + "version": "3.0.0-next.7", + "resolved": "https://registry.npmjs.org/@firebolt-js/openrpc/-/openrpc-3.0.0-next.7.tgz", + "integrity": "sha512-rw5prHLcf0ZXi85vcwxbFyNLNuucP0p7ccWNgrTU9mFQNwFvoIb3bRNzfi1DkorwgAEfTIIDyGNOurYMux4vTQ==", "dev": true, "dependencies": { "ajv": "^8.12.0", diff --git a/package.json b/package.json index b1ee21cc6..19da08177 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "devDependencies": { "@commitlint/cli": "^17.0.3", "@commitlint/config-conventional": "^17.0.3", - "@firebolt-js/openrpc": "3.0.0-next.8", + "@firebolt-js/openrpc": "3.0.0-next.7", "@firebolt-js/schemas": "2.0.0", "@saithodev/semantic-release-backmerge": "^3.2.0", "@semantic-release/changelog": "^6.0.1",