diff --git a/.github/scripts/release-apps.js b/.github/scripts/release-apps.js index a54c8fc86f..c0b87dceb5 100755 --- a/.github/scripts/release-apps.js +++ b/.github/scripts/release-apps.js @@ -7,7 +7,9 @@ const semver = require('semver'); // Maps a package name to the config key in defaults.json const CONFIG_KEYS = { - '@tryghost/portal': 'portal' + '@tryghost/portal': 'portal', + '@tryghost/sodo-search': 'sodoSearch', + '@tryghost/comments-ui': 'comments' }; const CURRENT_DIR = process.cwd(); diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 381f955493..5539f77138 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1138,3 +1138,138 @@ jobs: with: url: | https://cdn.jsdelivr.net/ghost/portal@~{{ env.current_minor }}/umd/portal.min.js + + publish_search: + needs: [ + job_setup, + job_lint, + job_unit-tests + ] + name: Publish @tryghost/sodo-search + runs-on: ubuntu-latest + if: always() && needs.job_setup.result == 'success' && needs.job_lint.result == 'success' && needs.job_unit-tests.result == 'success' && needs.job_setup.outputs.is_main == 'true' + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + + - name: Restore caches + uses: ./.github/actions/restore-cache + env: + DEPENDENCY_CACHE_KEY: ${{ needs.job_setup.outputs.dependency_cache_key }} + + - name: Check if version changed + id: version_check + working-directory: apps/sodo-search + run: | + CURRENT_VERSION=$(cat package.json | jq -r .version) + PUBLISHED_VERSION=$(npm show @tryghost/sodo-search version || echo "0.0.0") + echo "Current version: $CURRENT_VERSION" + echo "Published version: $PUBLISHED_VERSION" + + CURRENT_MINOR=$(cat package.json | jq -r .version | awk -F. '{print $1"."$2}') + echo "current_minor=$CURRENT_MINOR" >> $GITHUB_ENV + + if [ "$CURRENT_VERSION" = "$PUBLISHED_VERSION" ]; then + echo "Version is unchanged." + echo "version_changed=false" >> $GITHUB_ENV + else + echo "Version has changed." + echo "version_changed=true" >> $GITHUB_ENV + fi + + - name: Build the package + if: env.version_changed == 'true' + run: yarn run nx build @tryghost/sodo-search + + - name: Configure .npmrc + if: env.version_changed == 'true' + run: | + echo "@tryghost:registry=https://registry.npmjs.org/" >> ~/.npmrc + echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc + + - name: Publish to npm + if: env.version_changed == 'true' + working-directory: apps/sodo-search + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: npm publish --access public + + - name: Purge jsdelivr cache + if: env.version_changed == 'true' + uses: gacts/purge-jsdelivr-cache@v1 + with: + url: | + https://cdn.jsdelivr.net/ghost/sodo-search@~{{ env.current_minor }}/umd/sodo-search.min.js + https://cdn.jsdelivr.net/ghost/sodo-search@~{{ env.current_minor }}/umd/main.css + + publish_comments: + needs: [ + job_setup, + job_lint, + job_unit-tests + ] + name: Publish @tryghost/comments-ui + runs-on: ubuntu-latest + if: always() && needs.job_setup.result == 'success' && needs.job_lint.result == 'success' && needs.job_unit-tests.result == 'success' && needs.job_setup.outputs.is_main == 'true' + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + + - name: Restore caches + uses: ./.github/actions/restore-cache + env: + DEPENDENCY_CACHE_KEY: ${{ needs.job_setup.outputs.dependency_cache_key }} + + - name: Check if version changed + id: version_check + working-directory: apps/comments-ui + run: | + CURRENT_VERSION=$(cat package.json | jq -r .version) + PUBLISHED_VERSION=$(npm show @tryghost/comments-ui version || echo "0.0.0") + echo "Current version: $CURRENT_VERSION" + echo "Published version: $PUBLISHED_VERSION" + + CURRENT_MINOR=$(cat package.json | jq -r .version | awk -F. '{print $1"."$2}') + echo "current_minor=$CURRENT_MINOR" >> $GITHUB_ENV + + if [ "$CURRENT_VERSION" = "$PUBLISHED_VERSION" ]; then + echo "Version is unchanged." + echo "version_changed=false" >> $GITHUB_ENV + else + echo "Version has changed." + echo "version_changed=true" >> $GITHUB_ENV + fi + + - name: Build the package + if: env.version_changed == 'true' + run: yarn run nx build @tryghost/comments-ui + + - name: Configure .npmrc + if: env.version_changed == 'true' + run: | + echo "@tryghost:registry=https://registry.npmjs.org/" >> ~/.npmrc + echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc + + - name: Publish to npm + if: env.version_changed == 'true' + working-directory: apps/comments-ui + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: npm publish --access public + + - name: Purge jsdelivr cache + if: env.version_changed == 'true' + uses: gacts/purge-jsdelivr-cache@v1 + with: + url: | + https://cdn.jsdelivr.net/ghost/comments-ui@~{{ env.current_minor }}/umd/comments-ui.min.js diff --git a/apps/comments-ui/README.md b/apps/comments-ui/README.md index a1a4d15805..0b8dd4033b 100644 --- a/apps/comments-ui/README.md +++ b/apps/comments-ui/README.md @@ -19,15 +19,18 @@ A patch release can be rolled out instantly in production, whereas a minor/major ### Patch release 1. Run `yarn ship` and select a patch version when prompted -2. (Optional) Clear JsDelivr cache to get the new version out instantly ([docs](https://www.notion.so/ghost/How-to-clear-jsDelivr-CDN-cache-2930bdbac02946eca07ac23ab3199bfa?pvs=4)). Typically, you'll need to open `https://purge.jsdelivr.net/ghost/comments-ui@~${COMMENTS_UI_VERSION}/umd/comments-ui.min.js` and -`https://purge.jsdelivr.net/ghost/comments-ui@~${COMMENTS_UI_VERSION}/umd/main.css` in your browser, where `COMMENTS_UI_VERSION` is the latest minor version in `ghost/core/core/shared/config/defaults.json` ([code](https://github.com/TryGhost/Ghost/blob/0aef3d3beeebcd79a4bfd3ad27e0ac67554b5744/ghost/core/core/shared/config/defaults.json#L198)) +2. Merge the release commit to `main` ### Minor / major release 1. Run `yarn ship` and select a minor or major version when prompted -2. Update the Comments UI version in `ghost/core/core/shared/config/defaults.json` to the new minor or major version ([code](https://github.com/TryGhost/Ghost/blob/0aef3d3beeebcd79a4bfd3ad27e0ac67554b5744/ghost/core/core/shared/config/defaults.json#L198)) +2. Merge the release commit to `main` 3. Wait until a new version of Ghost is released +### JsDelivr cache +If the CI doesn't clear JsDelivr cache to get the new version out instantly, you may want to do it yourself manually ([docs](https://www.notion.so/ghost/How-to-clear-jsDelivr-CDN-cache-2930bdbac02946eca07ac23ab3199bfa?pvs=4)). Typically, you'll need to open `https://purge.jsdelivr.net/ghost/comments-ui@~${COMMENTS_UI_VERSION}/umd/comments-ui.min.js` and +`https://purge.jsdelivr.net/ghost/comments-ui@~${COMMENTS_UI_VERSION}/umd/main.css` in your browser, where `COMMENTS_UI_VERSION` is the latest minor version in `ghost/core/core/shared/config/defaults.json` ([code](https://github.com/TryGhost/Ghost/blob/0aef3d3beeebcd79a4bfd3ad27e0ac67554b5744/ghost/core/core/shared/config/defaults.json#L198)) + # Copyright & License Copyright (c) 2013-2025 Ghost Foundation - Released under the [MIT license](LICENSE). diff --git a/apps/comments-ui/package.json b/apps/comments-ui/package.json index c07ddc79fb..1d5e192929 100644 --- a/apps/comments-ui/package.json +++ b/apps/comments-ui/package.json @@ -27,8 +27,7 @@ "test:e2e:full": "ALL_BROWSERS=1 yarn test:e2e", "lint": "eslint src --ext .js,.ts,.jsx,.tsx --cache", "preship": "yarn lint", - "ship": "STATUS=$(git status --porcelain .); echo $STATUS; if [ -z \"$STATUS\" ]; then yarn version; else echo \"Uncommitted changes found.\" && exit 1; fi", - "postship": "git push ${GHOST_UPSTREAM:-origin} --follow-tags && npm publish", + "ship": "node ../../.github/scripts/release-apps.js", "prepublishOnly": "yarn build" }, "browserslist": { diff --git a/apps/sodo-search/package.json b/apps/sodo-search/package.json index 4e6741ed2f..418d6df738 100644 --- a/apps/sodo-search/package.json +++ b/apps/sodo-search/package.json @@ -33,8 +33,7 @@ "test:unit": "yarn test:ci", "lint": "eslint src --ext .js --cache", "preship": "yarn lint", - "ship": "STATUS=$(git status --porcelain .); echo $STATUS; if [ -z \"$STATUS\" ]; then yarn version; else echo \"Uncommitted changes found.\" && exit 1; fi", - "postship": "git push ${GHOST_UPSTREAM:-origin} --follow-tags && npm publish", + "ship": "node ../../.github/scripts/release-apps.js", "prepublishOnly": "yarn build" }, "eslintConfig": {