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
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
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)"

# 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 [email protected]

# 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 [email protected] -- 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 [email protected] -- 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)

8 changes: 8 additions & 0 deletions app/client/.changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
24 changes: 24 additions & 0 deletions app/client/.changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": [
"@shared/ast",
"@appsmith/ads-old",
"@appsmith/wds-headless",
"@appsmith/wds-theming",
"@appsmith/wds",
"@design-system/widgets-old",
"@shared/dsl",
"@appsmith/eslint-plugin",
"appsmith-icons",
"appsmith-rts",
"@design-system/storybook",
"@appsmith/utils"
]
}
1 change: 1 addition & 0 deletions app/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"@blueprintjs/icons": "3.22.0",
"@blueprintjs/popover2": "^0.5.0",
"@blueprintjs/select": "^3.10.0",
"@changesets/cli": "^2.27.10",
"@design-system/widgets-old": "workspace:^",
"@floating-ui/dom": "^1.6.4",
"@floating-ui/react": "^0.26.24",
Expand Down
1 change: 1 addition & 0 deletions app/client/packages/design-system/ads-old/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "This is the package for the Appsmith design system components",
"main": "src/index.ts",
"sideEffects": false,
"private": true,
"scripts": {
"lint": "yarn g:lint",
"prettier": "yarn g:prettier"
Expand Down
13 changes: 13 additions & 0 deletions app/client/packages/design-system/ads/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
src
.editorconfig
.eslintrc.json
.prettierignore
.prettierrc
rollup.config.js
tsconfig.json
.yarn-error.log
.storybook
story_template.txt
alpha-release.sh
create_story.sh
typings
7 changes: 7 additions & 0 deletions app/client/packages/design-system/ads/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @appsmith/ads

## 2.1.44

### Patch Changes

- Latest updates
21 changes: 18 additions & 3 deletions app/client/packages/design-system/ads/package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
{
"name": "@appsmith/ads",
"version": "2.1.43",
"version": "2.1.44-alpha.4",
"description": "This is the package for the design system that powers the Appsmith platform",
"main": "src/index.ts",
"sideEffects": false,
"scripts": {
"generate:component": "plop component",
"lint": "yarn g:lint",
"prettier": "yarn g:prettier",
"test:unit": "yarn g:jest"
"test:unit": "yarn g:jest",
"build": "rm -rf build && rollup -c --bundleConfigAsCjs"
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems that bundleConfigAsCjs flag contradicts what is specified in the config. Please check it out.

},
"files": [
"build"
],
"author": "",
"license": "ISC",
"devDependencies": {
"@react-aria/focus": "^3.10.1",
"@types/react-datepicker": "^4.10.0"
"@rollup/plugin-commonjs": "^28.0.1",
"@rollup/plugin-image": "^3.0.3",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^12.1.1",
"@rollup/plugin-url": "^8.0.2",
"@svgr/rollup": "^8.1.0",
"@types/react-datepicker": "^4.10.0",
"browserslist": "latest",
"rollup": "^4.28.1",
"rollup-plugin-copy": "^3.5.0",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-postcss": "^4.0.2"
},
"dependencies": {
"@radix-ui/react-dialog": "^1.0.2",
Expand Down
47 changes: 47 additions & 0 deletions app/client/packages/design-system/ads/rollup.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import peerDepsExternal from "rollup-plugin-peer-deps-external";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "@rollup/plugin-typescript";
import url from "@rollup/plugin-url";
import postcss from "rollup-plugin-postcss";
import path from "path";
import postcssImport from "postcss-import";
import terser from "@rollup/plugin-terser";
import image from "@rollup/plugin-image";
import copy from "rollup-plugin-copy";

export default {
input: path.resolve(__dirname, "src/index.ts"),
output: [
{
dir: path.resolve(__dirname, "build"), // Output directory
format: "esm", // ES module output
sourcemap: true,
preserveModules: false,
},
],
external: (id) =>
!id.startsWith(".") && !id.startsWith("/") && !id.includes("src"),

plugins: [
peerDepsExternal(), // Automatically exclude peer dependencies
url(), // Handle asset imports
commonjs(), // Convert CommonJS modules to ES6
postcss({
minimize: true,
sourceMap: true,
plugins: [postcssImport()],
extract: path.resolve("build/css/design-system.css"),
}),
typescript({
tsconfig: "./tsconfig.json",
declaration: true, // Generate .d.ts files
declarationDir: path.resolve("build/types"), // Align with Rollup output dir
outDir: "./build", // Align JS output directory
}),
image(), // Handle image imports
copy({
targets: [{ src: "src/__assets__/fonts/*", dest: "build/css" }],
}),
terser(), // Minify JS output
],
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { List, ListItem, Icon } from "@appsmith/ads";
import type { StoryObj } from "@storybook/react";
import type { ListItemProps, ListProps } from "@appsmith/ads";
import { List, ListItem, type ListItemProps, type ListProps } from ".";
import { Icon } from "../Icon";

export default {
title: "ADS/Components/List",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type MenuContentProps = _MenuContentProps &
export type MenuSubContentProps = _MenuContentProps &
RadixMenu.DropdownMenuSubContentProps;

interface _MenuItemProps {
export interface _MenuItemProps {
/** (try not to) pass addition classes here */
className?: string;
/** startIcon */
Expand Down
1 change: 1 addition & 0 deletions app/client/packages/design-system/headless/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@appsmith/wds-headless",
"version": "1.0.0",
"private": true,
"main": "src/index.ts",
"author": "Valera Melnikov <[email protected]>, Pawan Kumar <[email protected]>",
"license": "MIT",
Expand Down
1 change: 1 addition & 0 deletions app/client/packages/design-system/theming/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@appsmith/wds-theming",
"version": "1.0.0",
"main": "src/index.ts",
"private": true,
"author": "Valera Melnikov <[email protected]>, Pawan Kumar <[email protected]>",
"license": "MIT",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions app/client/packages/design-system/widgets-old/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.1.3",
"description": "This is the package for the Appsmith design system components",
"main": "src/index.ts",
"private": true,
"author": "Valera Melnikov <[email protected]>, Pawan Kumar <[email protected]>",
"license": "Apache-2.0",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions app/client/packages/design-system/widgets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@appsmith/wds",
"version": "1.0.0",
"main": "src/index.ts",
"private": true,
"author": "Valera Melnikov <[email protected]>, Pawan Kumar <[email protected]>",
"license": "MIT",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions app/client/packages/icons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"author": "Valera Melnikov <[email protected]>, Pawan Kumar <[email protected]>",
"license": "MIT",
"private": true,
"main": "src/index.ts",
"scripts": {
"build": "yarn cleanup && figmagic && yarn optimize-icons && yarn generate-components && yarn generate-index && yarn generate-stories && yarn prettier . --write --log-level=silent",
Expand Down
1 change: 1 addition & 0 deletions app/client/packages/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"main": "src/index.ts",
"author": "Valera Melnikov <[email protected]>, Pawan Kumar <[email protected]>",
"license": "MIT",
"private": true,
"scripts": {
"lint": "yarn g:lint",
"storybook": "storybook dev -p 6006",
Expand Down
1 change: 1 addition & 0 deletions app/client/packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@appsmith/utils",
"version": "1.0.0",
"description": "This package has all the shared util functions which can be used in different packages e.g. client, rts etc",
"private": true,
"main": "src/index.ts",
"types": "src/index.d.ts",
"scripts": {
Expand Down
Loading
Loading