Skip to content
Draft
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
7 changes: 0 additions & 7 deletions .changeset/commander-15-esm.md

This file was deleted.

7 changes: 0 additions & 7 deletions .changeset/config.json

This file was deleted.

7 changes: 0 additions & 7 deletions .changeset/execa-10.md

This file was deleted.

7 changes: 0 additions & 7 deletions .changeset/ora-9-4-1.md

This file was deleted.

7 changes: 0 additions & 7 deletions .changeset/prettier-3-9-6.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/slow-oranges-hang.md

This file was deleted.

9 changes: 0 additions & 9 deletions .changeset/swift-ferrets-climb.md

This file was deleted.

1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ bin
coverage
dist
*.yaml
.changeset
165 changes: 139 additions & 26 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
name: Release

on:
push:
branches:
- main
workflow_dispatch:
inputs:
tag:
description: 'npm dist-tag to publish under'
required: true
default: 'latest'
type: choice
options:
- latest
- next

concurrency: ${{ github.workflow }}-${{ github.ref }}

Expand All @@ -13,31 +20,137 @@
if: github.repository == 'strapi/sdk-plugin'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
id-token: write # Required for npm trusted publishing (OIDC)
contents: read
id-token: write # required for npm trusted publishing (OIDC)
outputs:
package_version: ${{ steps.package_version.outputs.package_version }}
steps:
- uses: actions/checkout@v7
- uses: pnpm/action-setup@v6
- uses: actions/setup-node@v6
- name: Checkout repo
uses: actions/checkout@v7
with:
fetch-depth: 0

- name: Install pnpm
uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6
with:
version: 9.1.0

- name: Setup node
uses: actions/setup-node@v6
with:
node-version: 22
cache: pnpm
node-version: lts/*
registry-url: 'https://registry.npmjs.org' # Pin the publish registry for npm trusted publishing (OIDC)
- run: pnpm --version
# npm trusted publishing (OIDC) requires npm CLI >= 11.5.1
- run: npm install -g npm@11.17.0
- run: npm --version
- run: pnpm install
- run: pnpm build

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1

- name: Update npm for trusted publishing
run: npm install -g 'npm@^11.5.1' # OIDC trusted publishing requires npm >= 11.5.1

Check warning on line 45 in .github/workflows/release.yml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using dependencies without locking resolved versions is security-sensitive.

See more on https://sonarcloud.io/project/issues?id=strapi_sdk-plugin&issues=AaFoQvPhQjX7FJMZCeCL&open=AaFoQvPhQjX7FJMZCeCL&pullRequest=245

Check warning on line 45 in .github/workflows/release.yml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Omitting "--ignore-scripts" allows lifecycle scripts to run during package installation.

See more on https://sonarcloud.io/project/issues?id=strapi_sdk-plugin&issues=AaFoQvPhQjX7FJMZCeCK&open=AaFoQvPhQjX7FJMZCeCK&pullRequest=245

- name: Install deps
run: pnpm install --frozen-lockfile

Check warning on line 48 in .github/workflows/release.yml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Omitting "--ignore-scripts" allows lifecycle scripts to run during package installation.

See more on https://sonarcloud.io/project/issues?id=strapi_sdk-plugin&issues=AaFoQvPhQjX7FJMZCeCM&open=AaFoQvPhQjX7FJMZCeCM&pullRequest=245

- name: Build
run: pnpm run build

- name: Resolve package version
id: package_version
run: echo "package_version=$(node -p "require('./package.json').version")" >> "$GITHUB_OUTPUT"

- name: Publish to npm
run: npm publish --provenance --access public --tag ${{ inputs.tag }}

notify_slack:
name: 'Notify Slack'
needs: [release]
runs-on: ubuntu-latest
if: github.repository == 'strapi/sdk-plugin' && success()
permissions: {}
steps:
- name: send message to slack
uses: slackapi/slack-github-action@e28cf165c92ffef168d23c5c9000cffc8a25e117 # v1.24.0
with:
payload: |
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "@strapi/sdk-plugin ${{ needs.release.outputs.package_version }} has been successfully deployed :tada:",
"emoji": true
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Check out the *<https://github.com/strapi/sdk-plugin/releases|release note>*"
}
},
{
"type": "context",
"elements": [
{
"type": "image",
"image_url": "https://github.com/${{ github.triggering_actor }}.png",
"alt_text": "${{ github.triggering_actor }} avatar"
},
{
"type": "mrkdwn",
"text": "Triggered by *${{ github.triggering_actor }}*"
}
]
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_RELEASE_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK

notify_on_error:
needs: [release]
name: notify on error
runs-on: ubuntu-latest
if: failure()
permissions: {}
steps:
- name: send message to slack
uses: slackapi/slack-github-action@e28cf165c92ffef168d23c5c9000cffc8a25e117 # v1.24.0
with:
version: pnpm release:version
publish: pnpm release:publish
commit: 'chore: version packages for release'
title: 'chore: version packages for release'
payload: |
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "Deployment failed or has been rejected :disappointed:",
"emoji": true
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Click here to see the logs>"
}
]
},
{
"type": "context",
"elements": [
{
"type": "image",
"image_url": "https://github.com/${{ github.triggering_actor }}.png",
"alt_text": "${{ github.triggering_actor }} avatar"
},
{
"type": "mrkdwn",
"text": "Triggered by *${{ github.triggering_actor }}*"
}
]
}
]
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_RELEASE_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
13 changes: 3 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,6 @@ jobs:
name: Restore build output
with:
name: build-output-node-${{ matrix.node }}
# On Node < 24.9, Jest can't load pure-ESM deps (commander 15) via its normal
# import, so we fall back to a native dynamic import that escapes Jest's per-file
# environment. If a worker is reused across test files, a later file's import hits
# the previous file's torn-down environment ("import after teardown"). Forcing one
# worker per suite (we have 8) prevents reuse. Node 24/26 load ESM natively and
# don't need this.
- if: matrix.node == 22
run: pnpm test:unit --maxWorkers=8
- if: matrix.node != 22
run: pnpm test:unit
# Node < 24.9 needs one Jest worker per suite (see jest.config.mjs). The config
# sets that; do not pass a smaller --maxWorkers here.
- run: pnpm test:unit
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
bin
dist
pnpm-lock.yaml
.changeset
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# @strapi/sdk-plugin

Versions through 6.1.1 were cut with Changesets. Later releases follow [CONTRIBUTING.md](./CONTRIBUTING.md) and use GitHub release notes.

## 6.1.1

### Patch Changes
Expand Down
32 changes: 32 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Releases

This section is for maintainers.

To release a new version:

1. Create a release branch from `main` and ensure it is up to date.

The branch name should follow the format: `releases/<major>.<minor>.<patch>`.

2. Install the latest dependencies with `pnpm install`.
3. Update the package version in the root [package.json](./package.json):

```diff
{
"name": "@strapi/sdk-plugin",
- "version": "6.1.1",
+ "version": "6.1.2",
// ...
}
```

4. Perform a dry-run publication with `pnpm publish --dry-run --tag latest`.
5. If the dry run succeeds, commit the version update with the message `release: <major>.<minor>.<patch>`. If it fails, resolve the issues before proceeding.
6. Create a version tag with `git tag v<major>.<minor>.<patch>`.
7. Push the tag to the remote repository: `git push origin v<major>.<minor>.<patch>`.
8. Push the release branch and run the [Release workflow](https://github.com/strapi/sdk-plugin/actions/workflows/release.yml) on that branch. Choose the npm dist-tag, `latest` or `next`. The workflow publishes with npm trusted publishing.
9. [Draft a new release](https://github.com/strapi/sdk-plugin/releases/new) on GitHub.
10. Select the newly created tag under the `Choose a tag` dropdown, leaving the `Target` as `auto`.
11. Click `Generate release notes`, review the content (for example, remove PRs related to the release process), and make necessary corrections.
12. Ensure the `Set as the latest release` option is selected, then click `Publish release`.
13. Create a pull request named `release: <major>.<minor>.<patch>` targeting the `main` branch.
43 changes: 42 additions & 1 deletion jest.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,42 @@
import { readdirSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const rootDir = path.dirname(fileURLToPath(import.meta.url));

/**
* Suites Jest will actually run. On Node < 24.9 each one needs its own worker.
*/
const countTestFiles = (dir) => {
let count = 0;

for (const entry of readdirSync(dir, { withFileTypes: true })) {
if (entry.name !== 'fixtures' && entry.name !== 'node_modules') {
const fullPath = path.join(dir, entry.name);

if (entry.isDirectory()) {
count += countTestFiles(fullPath);
} else if (entry.isFile() && /\.test\.(js|ts)$/.test(entry.name)) {
count += 1;
}
}
}

return count;
};

const [nodeMajor = 0, nodeMinor = 0] = process.versions.node.split('.').map(Number);
// Same cutoff as src/cli/commands/utils/esm-interop.ts. Below it, commander is loaded
// with a native dynamic import that escapes Jest's per-file environment. Reusing a
// worker for the next file throws "import after teardown". `npm publish` runs these
// tests from `prepack` on the Release workflow's Node 22 image, which has fewer
// cores than test files, so the default worker count is not enough.
const isolateEsmWorkers = nodeMajor < 24 || (nodeMajor === 24 && nodeMinor < 9);

/**
* @type {import('jest').Config}
*/
export default {
const config = {
modulePathIgnorePatterns: ['dist'],
testMatch: ['**/__tests__/**/*.test.{js,ts}'],
testPathIgnorePatterns: ['__tests__/fixtures/'],
Expand All @@ -11,3 +46,9 @@ export default {
displayName: 'Plugin CLI',
collectCoverageFrom: ['src/**/*.ts'],
};

if (isolateEsmWorkers) {
config.maxWorkers = Math.max(countTestFiles(path.join(rootDir, 'src', '__tests__')), 1);
}

export default config;
9 changes: 1 addition & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,9 @@
"check": "pnpm lint && pnpm test:ts && pnpm test:unit",
"lint": "eslint .",
"prepare": "husky",
"prerelease:enter": "changeset pre enter",
"prerelease:exit": "changeset pre exit",
"prepack": "pnpm prettier:check && pnpm check && pnpm build",
"prettier:check": "prettier --check .",
"prettier:write": "prettier --write .",
"release:add": "changeset add",
"release:publish": "changeset publish",
"release:version": "changeset version && pnpm install",
"test:ts": "tsc --noEmit",
"test:unit": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"watch": "vite build --watch"
Expand All @@ -79,9 +75,6 @@
"yup": "1.7.1"
},
"devDependencies": {
"@changesets/changelog-git": "^0.2.1",
"@changesets/changelog-github": "^0.7.0",
"@changesets/cli": "^2.31.0",
"@commitlint/cli": "^21.0.1",
"@commitlint/config-conventional": "^21.0.1",
"@strapi/eslint-config": "^1.0.1",
Expand Down
Loading
Loading