Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions .changeset/lucky-sheep-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@ag.ds-next/react': patch
---

feat: add automated NPM publishing with GitHub Actions

- Implement test-and-publish workflow with changesets integration
- Add automated Release PR creation from develop branch
- Configure secure permissions and NPM authentication
- Optimize CI/CD with caching and parallel testing
- Replace manual versioning with changeset-driven releases
- Add prepublishOnly scripts to prevent manual publishing

Requires: NPM_TOKEN secret for publishing to @ag.ds-next registry
5 changes: 5 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Release

# Explicit permissions for security
permissions:
contents: read
pull-requests: write

on:
push:
branches:
Expand Down
103 changes: 103 additions & 0 deletions .github/workflows/test-and-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Test & Publish

# Explicit permissions for security
permissions:
contents: read
pull-requests: write
id-token: write

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
test-and-build:
name: Test, Lint & Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js 22.15.1
uses: actions/setup-node@v4
with:
node-version: 22.15.1

- name: Get number of CPU cores
id: cpu-cores
uses: SimenB/github-actions-cpu-cores@97ba232459a8e02ff6121db9362b09661c875ab8 # v2.0.0

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

- uses: actions/cache@v3
id: yarn-cache
with:
path: |
${{ steps.yarn-cache-dir-path.outputs.dir }}
node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Unit tests
run: yarn test --max-workers ${{ steps.cpu-cores.outputs.count }}

- name: Generate component props
run: yarn docs:generate-component-props

- name: Lint
run: yarn lint

- name: Build packages
run: yarn build

publish:
name: Publish to NPM
runs-on: ubuntu-latest
needs: [test-and-build]
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
permissions:
contents: write # Needed to create releases and tags
pull-requests: write # Needed to create Release PRs
id-token: write # Needed for NPM provenance
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22.15.1
cache: 'yarn'
registry-url: 'https://registry.npmjs.org'

- name: Install Dependencies
run: yarn install --frozen-lockfile

- name: Configure npm for public publishing
run: |
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
echo "@ag.ds-next:registry=https://registry.npmjs.org" >> ~/.npmrc
echo "access=public" >> ~/.npmrc
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

Comment on lines +86 to +93
Copy link

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

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

The NPM configuration writes the auth token to ~/.npmrc in plain text. Consider using the NODE_AUTH_TOKEN environment variable with actions/setup-node's built-in registry authentication instead, which is more secure and already configured on line 81.

Suggested change
- name: Configure npm for public publishing
run: |
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
echo "@ag.ds-next:registry=https://registry.npmjs.org" >> ~/.npmrc
echo "access=public" >> ~/.npmrc
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
# Removed insecure step that writes auth token to ~/.npmrc.
# If you need to set registry or access for scoped packages, add a step like:
# - name: Configure npm registry and access
# run: |
# echo "@ag.ds-next:registry=https://registry.npmjs.org" >> ~/.npmrc
# echo "access=public" >> ~/.npmrc

Copilot uses AI. Check for mistakes.

- name: Publish to NPM
run: |
echo "Publishing packages to NPM registry..."
yarn publish-changed
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
Copy link

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

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

Both NPM_TOKEN and NODE_AUTH_TOKEN are set to the same secret value, which creates redundancy. Since NODE_AUTH_TOKEN is the standard environment variable used by actions/setup-node for NPM authentication, you can remove NPM_TOKEN and rely solely on NODE_AUTH_TOKEN.

Suggested change
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

Copilot uses AI. Check for mistakes.

NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Display notification if a publish happens
run: echo "Packages published to NPM successfully!"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ yarn-error.log*

# typescript
*.tsbuildinfo

.npmrc
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"new:package": "plop --plopfile scripts/new-package.mjs && yarn format && yarn manypkg fix && preconstruct fix && yarn install",
"playroom:build": "yarn --cwd docs playroom:build",
"playroom:dev": "yarn --cwd docs playroom:dev",
"prepublishOnly": "echo 'Publishing from local machine is disabled. Use CI/CD pipeline.' && echo 'Push changes to develop branch to trigger release process.' && exit 1",
"publish-changed": "yarn build && yarn changeset publish",
"storybook:build": "storybook build -o docs/public/storybook",
"storybook:dev": "storybook dev --port 6006 --no-open",
Expand Down
3 changes: 3 additions & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@
},
"./package.json": "./package.json"
},
"scripts": {
"prepublishOnly": "echo 'Publishing from local machine is disabled. Use CI/CD pipeline.' && echo 'Push changes to develop branch to trigger release process.' && exit 1"
},
"dependencies": {
"@babel/runtime": "^7.27.1",
"@floating-ui/react-dom": "^2.0.8",
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/date-picker-next/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ describe('isValidDate', () => {

describe('minDate', () => {
test('returns true when it’s a valid date', () => {
expect(isValidDate(new Date(), { minDate: new Date() })).toEqual(true);
const fixedDate = new Date();
expect(isValidDate(fixedDate, { minDate: fixedDate })).toEqual(true);
expect(isValidDate('31/01/1950', { minDate: '31/01/1950' })).toEqual(
true
);
Expand Down