Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added NPM publish workflow for ADS package #37787

Closed
wants to merge 10 commits into from
68 changes: 68 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: NPM Publish Release Workflow

on:
KelvinOm marked this conversation as resolved.
Show resolved Hide resolved
push:
paths:
- "app/client/packages/design-system/ads/**"
branches:
- "release"

jobs:
release:
name: Release
runs-on: ubuntu-latest
defaults:
run:
working-directory: app/client
steps:
# Get yarn cache directory and set it in a variable
- name: Get yarn cache path
id: yarn-cache-path
run: echo "::set-output name=dir::$(yarn cache dir)"

KelvinOm marked this conversation as resolved.
Show resolved Hide resolved
# Checkout branch or head commit
- name: Checkout branch
uses: actions/checkout@v4
with:
fetch-depth: 0

# Set up node version
- name: Setup Node js version
uses: actions/setup-node@v4
with:
node-version-file: app/client/package.json

# Load yarn cache
- name: Load Yarn cache
uses: actions/cache@v4
with:
path: ${{ steps.yarn-cache-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

# Install the dependencies
- name: Install dependencies
run: yarn install --immutable

# Set git config -> changelog
- name: Set git config to github-actions
run: |
git config user.name github-actions
git config user.email github-actions@github.com

# Build packages, add packages build script inside workspace scripts.build
- name: Build packages
run: yarn workspace @design-system/ads build

# Create PR & publish to NPM
- name: Create release Pull Request or publish to NPM
id: changesets
uses: changesets/action@v1
with:
publish: yarn release
commit: "ci(changesets): version packages"
title: "ci(changesets): version packages"
Comment on lines +58 to +65
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add version validation before publishing.

Add a step to validate package version before publishing to prevent accidental releases:

- name: Validate version
  run: |
    CURRENT_VERSION=$(node -p "require('./app/client/packages/design-system/ads/package.json').version")
    NPM_VERSION=$(npm view @design-system/ads version 2>/dev/null || echo "0.0.0")
    if [ "$(printf '%s\n' "$NPM_VERSION" "$CURRENT_VERSION" | sort -V | head -n1)" = "$CURRENT_VERSION" ]; then
      echo "Error: New version ($CURRENT_VERSION) must be greater than published version ($NPM_VERSION)"
      exit 1
    fi

env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be APPSMITH_NPM_PUBLISH_KEY or NPM_TOKEN? Because in npm config you've used APPSMITH_NPM_PUBLISH_KEY. If both exist, then just pick a single key for consistence.

GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Comment on lines +58 to +68
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add retry mechanism for npm publish

NPM registry operations can be flaky. Consider adding retry mechanism:

       - name: Create release Pull Request or publish to NPM
         id: changesets
         uses: changesets/action@v1
         with:
-          publish: yarn release
+          publish: npx --no-install retry-cli@0.7.0 -- yarn release
           commit: "ci(changesets): version packages"
           title: "ci(changesets): version packages"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Create PR & publish to NPM
- name: Create release Pull Request or publish to NPM
id: changesets
uses: changesets/action@v1
with:
publish: yarn release
commit: "ci(changesets): version packages"
title: "ci(changesets): version packages"
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Create PR & publish to NPM
- name: Create release Pull Request or publish to NPM
id: changesets
uses: changesets/action@v1
with:
publish: npx --no-install retry-cli@0.7.0 -- yarn release
commit: "ci(changesets): version packages"
title: "ci(changesets): version packages"
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
🧰 Tools
🪛 yamllint (1.35.1)

[error] 68-68: no new line character at the end of file

(new-line-at-end-of-file)

Loading