-
Notifications
You must be signed in to change notification settings - Fork 18
chore(monorepo): 🤖 Independent Package Publisher (NPM) #953
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
Open
punkbit
wants to merge
17
commits into
chore/monorepo-changeset-root-setup
Choose a base branch
from
chore/monorepo-package-releaser
base: chore/monorepo-changeset-root-setup
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
6159cb3
chore: 🤖 move click-ui into packages/click-ui
punkbit 5cea870
chore: 🤖 make monorepo (yarn workspaces)
punkbit 3337b34
chore: 🤖 update workflows
punkbit 5feba1a
chore: 🤖 setup changeset for monorepository architecture
punkbit 2728146
chore: 🤖 add monorepo package release (initial, copied from a concurr…
punkbit 5ee13ac
docs: 📝 monorepo package release distinction
punkbit 5946314
chore: 🤖 add notes
punkbit 71016f3
fix: 🐛 Fixed both references (lines 259 and 272) from monorepo-packag…
punkbit 9215390
refactor(security): 💡 string inputs (package, confirm_package, confir…
punkbit 53ecc23
chore: 🤖 Added a new GitHub Actions Security block with the rule expl…
punkbit 4ae1b7a
refactor: 💡 extended validation step condition to latest
punkbit fa78362
docs: 📝 Added a paragraph after the existing trusted publisher guidance
punkbit 698df37
fix: 🐛 Two steps fixed: check version on npm (lines 169-171): moved p…
punkbit 72875c4
chore: 🤖 Removed the Upgrade npm for OIDC support step. setup-node@v6…
punkbit 4324918
chore: 🤖 update create github release step
punkbit 5b81008
fix: 🐛 conflict resolution
punkbit 57ce616
fix: 🐛 issue was the resolutions field was in packages/click-ui/packa…
punkbit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,237 @@ | ||
| name: 🎯 Monorepo Package Publisher (NPM) | ||
|
|
||
| # TODO: Create release workflow as this is a concurrent NPM publisher to the original changeset based workflow for Click UI | ||
| # which is much stricter with a very particular | ||
| # release cycle: test or release-candidate -> stable -> latest | ||
| # The "Monorepo Package Publisher" initial version is not strict | ||
| # and relies on the user managing the changeset state | ||
| # e.g. enter/leave pre-release mode as needed (`yarn workspace @clickhouse/design-tokens changeset pre enter <tag>` / `changeset pre exit`), run `yarn workspace @clickhouse/design-tokens changeset version` to bump the version and generate the changelog, ensure the version bump and changelog are committed in the branch/commit you intend to release | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| package: | ||
| description: 'Package to release' | ||
| required: true | ||
| type: choice | ||
| options: | ||
| # NOTE: Declare the package names | ||
| # that can be published to NPM registry | ||
| - design-tokens | ||
| release_type: | ||
punkbit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| description: 'Release type' | ||
| required: true | ||
| type: choice | ||
| options: | ||
| - test | ||
| - rc | ||
| - stable | ||
| - latest | ||
| default: 'test' | ||
| confirm_package: | ||
| description: 'Type the package name to confirm (e.g., "design-tokens")' | ||
| required: true | ||
| type: string | ||
| confirm_branch: | ||
| description: 'For stable and latest releases: type the branch name (e.g., "main")' | ||
| required: false | ||
| type: string | ||
| dry_run: | ||
| description: 'Dry run (e.g., skip publish, github release, and slack notification)' | ||
| required: true | ||
| type: boolean | ||
| default: true | ||
|
|
||
| concurrency: ${{ github.workflow }}-${{ github.ref }} | ||
|
|
||
| env: | ||
| HUSKY: 0 | ||
|
|
||
| jobs: | ||
| monorepo-release-package: | ||
| name: Monorepo Release Package | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| id-token: write | ||
| steps: | ||
| - name: Validate package confirmation | ||
| env: | ||
| INPUT_PACKAGE: ${{ inputs.package }} | ||
| INPUT_CONFIRM_PACKAGE: ${{ inputs.confirm_package }} | ||
| run: | | ||
| if [[ "$INPUT_PACKAGE" != "$INPUT_CONFIRM_PACKAGE" ]]; then | ||
| echo "👹 Oops! Package confirmation mismatch!" | ||
| echo " Selected: '$INPUT_PACKAGE'" | ||
| echo " Typed: '$INPUT_CONFIRM_PACKAGE'" | ||
| echo "" | ||
| echo "💡 Please type the exact package name to confirm." | ||
| exit 1 | ||
| fi | ||
| echo "✅ Package confirmed: $INPUT_PACKAGE" | ||
|
|
||
| - name: Validate branch for stable and latest release | ||
| if: inputs.release_type == 'stable' || inputs.release_type == 'latest' | ||
| env: | ||
| INPUT_RELEASE_TYPE: ${{ inputs.release_type }} | ||
| INPUT_CONFIRM_BRANCH: ${{ inputs.confirm_branch }} | ||
| CURRENT_BRANCH: ${{ github.ref_name }} | ||
| run: | | ||
| if [[ -z "$INPUT_CONFIRM_BRANCH" ]]; then | ||
| echo "👹 Oops! Branch confirmation required for $INPUT_RELEASE_TYPE releases!" | ||
| echo " Current branch: '$CURRENT_BRANCH'" | ||
| echo "" | ||
| echo "💡 Please type the branch name in 'confirm_branch' to proceed." | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ "$CURRENT_BRANCH" != "$INPUT_CONFIRM_BRANCH" ]]; then | ||
| echo "👹 Oops! Branch confirmation mismatch!" | ||
| echo " Current branch: '$CURRENT_BRANCH'" | ||
| echo " Typed: '$INPUT_CONFIRM_BRANCH'" | ||
| echo "" | ||
| echo "💡 Please type the exact branch name to confirm." | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ "$CURRENT_BRANCH" != "main" ]]; then | ||
| echo "👹 Oops! $INPUT_RELEASE_TYPE releases must be from 'main' branch!" | ||
| echo " Current branch: '$CURRENT_BRANCH'" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "✅ Branch confirmed: $CURRENT_BRANCH" | ||
|
|
||
| - name: Generate GitHub workflow token | ||
| if: ${{ !inputs.dry_run }} | ||
punkbit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| id: gh-workflow-token | ||
| uses: actions/create-github-app-token@v2 | ||
| with: | ||
| app-id: ${{ secrets.WORKFLOW_AUTH_PUBLIC_APP_ID }} | ||
| private-key: ${{ secrets.WORKFLOW_AUTH_PUBLIC_PRIVATE_KEY }} | ||
|
|
||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version: '23.x' | ||
| registry-url: 'https://registry.npmjs.org' | ||
|
|
||
| - name: Enable Corepack | ||
| run: corepack enable | ||
|
|
||
| - name: Install dependencies | ||
| run: yarn install --frozen-lockfile | ||
|
|
||
| - name: Load package configuration | ||
| id: package-config | ||
| env: | ||
| INPUT_PACKAGE: ${{ inputs.package }} | ||
| run: | | ||
| PKG_DIR="packages/$INPUT_PACKAGE" | ||
|
|
||
| if [[ ! -f "$PKG_DIR/package.json" ]]; then | ||
| echo "👹 Oops! No package.json found at $PKG_DIR" | ||
| exit 1 | ||
| fi | ||
|
|
||
| PKG_NAME=$(node -p "require('./$PKG_DIR/package.json').name") | ||
| echo "package_name=$PKG_NAME" >> $GITHUB_OUTPUT | ||
| echo "package_path=$PKG_DIR" >> $GITHUB_OUTPUT | ||
| echo "changelog_file=CHANGELOG.md" >> $GITHUB_OUTPUT | ||
|
|
||
| echo "✅ Loaded config for $PKG_NAME ($PKG_DIR)" | ||
|
|
||
| - name: Build package | ||
| working-directory: ${{ steps.package-config.outputs.package_path }} | ||
| run: yarn build | ||
|
|
||
| - name: Get version from package.json | ||
| id: package-version | ||
| working-directory: ${{ steps.package-config.outputs.package_path }} | ||
| run: | | ||
| VERSION=$(node -p "require('./package.json').version") | ||
| echo "version=$VERSION" >> $GITHUB_OUTPUT | ||
| echo "📦 Package version: $VERSION" | ||
|
|
||
| - name: Check version on npm | ||
| if: ${{ !inputs.dry_run }} | ||
| env: | ||
| PKG_NAME: ${{ steps.package-config.outputs.package_name }} | ||
| VERSION: ${{ steps.package-version.outputs.version }} | ||
| run: | | ||
| echo "🔍 Checking if $PKG_NAME@$VERSION already exists on NPM..." | ||
|
|
||
| if npm view "$PKG_NAME@$VERSION" version 2>/dev/null; then | ||
| echo "👹 Oops! Version $VERSION of $PKG_NAME is already published on NPM!" | ||
| echo "💡 Please bump the version via changesets and try again." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "✅ Version $VERSION is not yet published, safe to proceed." | ||
|
|
||
| - name: Publish to npm over OpenID Connect (OIDC) | ||
| working-directory: ${{ steps.package-config.outputs.package_path }} | ||
| run: | | ||
| if [[ "${{ inputs.dry_run }}" == "true" ]]; then | ||
| echo "🧪 Dry run mode — publishing with --dry-run" | ||
| npm publish \ | ||
| --access public \ | ||
| --provenance \ | ||
| --tag ${{ inputs.release_type }} \ | ||
| --dry-run | ||
| else | ||
| npm publish \ | ||
| --access public \ | ||
| --provenance \ | ||
| --tag ${{ inputs.release_type }} | ||
| fi | ||
punkbit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| - name: Extract changelog | ||
| if: ${{ !inputs.dry_run }} | ||
| id: changelog | ||
| env: | ||
| VERSION: ${{ steps.package-version.outputs.version }} | ||
| PKG_PATH: ${{ steps.package-config.outputs.package_path }} | ||
| CHANGELOG_FILE: ${{ steps.package-config.outputs.changelog_file }} | ||
| run: | | ||
| CHANGELOG_PATH="${PKG_PATH}/${CHANGELOG_FILE}" | ||
|
|
||
| if [[ -f "$CHANGELOG_PATH" ]]; then | ||
| CHANGELOG=$(awk "/## $VERSION/,/## [0-9]/" "$CHANGELOG_PATH" | sed '1d;$d' | sed '/^$/d') | ||
|
|
||
| if [[ -z "$CHANGELOG" ]]; then | ||
| CHANGELOG="📝 See [CHANGELOG.md](./$CHANGELOG_FILE) for details." | ||
| fi | ||
punkbit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| else | ||
| CHANGELOG="No changelog available." | ||
| fi | ||
|
|
||
| echo "$CHANGELOG" > /tmp/changelog.txt | ||
| echo "📄 Extracted changelog" | ||
|
|
||
| - name: Create GitHub release | ||
| if: ${{ !inputs.dry_run }} | ||
| uses: softprops/action-gh-release@v2 | ||
| with: | ||
| tag_name: ${{ steps.package-config.outputs.package_name }}@v${{ steps.package-version.outputs.version }} | ||
| name: "${{ inputs.package }} v${{ steps.package-version.outputs.version }}" | ||
| body_path: /tmp/changelog.txt | ||
| prerelease: ${{ inputs.release_type == 'test' || inputs.release_type == 'rc' }} | ||
| env: | ||
| GITHUB_TOKEN: ${{ steps.gh-workflow-token.outputs.token }} | ||
|
|
||
| - name: Notify Slack about new release | ||
| if: ${{ !inputs.dry_run && secrets.SLACK_BOT_TOKEN != '' }} | ||
| uses: slackapi/slack-github-action@v2.1.1 | ||
| with: | ||
| method: chat.postMessage | ||
| token: ${{ secrets.SLACK_BOT_TOKEN }} | ||
| payload: | | ||
| channel: "${{ secrets.SLACK_CHANNEL_FOR_GENERAL }}" | ||
| text: "===\n🚀 *${{ steps.package-config.outputs.package_name }}* v${{ steps.package-version.outputs.version }} released to npm!\n\n📦 <https://www.npmjs.com/package/${{ steps.package-config.outputs.package_name }}/v/${{ steps.package-version.outputs.version }}|View on npm>\n🏷️ Tag: `${{ inputs.release_type }}`\n===" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.