diff --git a/.github/actions/prepare/action.yml b/.github/actions/prepare/action.yml index 1389a85a..69f530a7 100644 --- a/.github/actions/prepare/action.yml +++ b/.github/actions/prepare/action.yml @@ -1,15 +1,38 @@ -name: build -description: Check that all packages build successfully +name: Prepare +description: Install dependencies and build the platform +inputs: + build: + description: Build the production bundle of the platform + required: false + default: 'true' + registry: + description: NPM registry to set up for auth + required: false + default: 'https://registry.npmjs.org' + runs: using: composite steps: + - uses: pnpm/action-setup@v4 + name: Install pnpm + with: + run_install: false + - name: Install Node.js uses: actions/setup-node@v4 - - name: Setup pnpm - uses: pnpm/action-setup@v4.0.0 + with: + node-version-file: package.json + registry-url: ${{ inputs.registry }} + cache: pnpm + + - name: Update npm + shell: bash + run: npm install -g npm@latest + - name: Install dependencies shell: bash run: pnpm install + - name: Build if: inputs.build == 'true' shell: bash diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..07e39d15 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,61 @@ +name: Publish + +on: + push: + branches: + - main + +permissions: + id-token: write + contents: read + +jobs: + publish: + name: Publish Packages + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Prepare + uses: ./.github/actions/prepare + + - name: Check if packages exist on NPM + run: | + missing_packages="" + + for pattern in $(yq -r '.packages[]' pnpm-workspace.yaml); do + for package in $pattern; do + if [ -f "$package/package.json" ]; then + name=$(jq -r .name "$package/package.json") + private=$(jq -r .private "$package/package.json") + + if [ "$private" != "true" ] && [ "$name" != "null" ]; then + echo "Checking if $name exists on NPM..." + if ! npm view "$name" > /dev/null 2>&1; then + echo "Error: Package $name does not exist on NPM." + missing_packages="$missing_packages $name" + else + echo "Package $name exists." + fi + fi + fi + done + done + + if [ -n "$missing_packages" ]; then + echo "Error: The following packages do not exist on NPM:" + for package in $missing_packages; do + echo " - $package" + done + echo "Please create these packages on NPM and configure Trusted Publishing before publishing." + exit 1 + fi + + - name: Publish packages to NPM + env: + NPM_CONFIG_PROVENANCE: true + run: | + pnpm --filter "./packages/*" --recursive publish \ + --access=public \ + --no-git-checks diff --git a/package.json b/package.json index 31c6cbdb..be50ff98 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "license": "MIT", "homepage": "https://github.com/directus-labs/extensions", "engines": { - "node": ">=18.18.0", + "node": "22", "pnpm": "~9" }, "directus:meta": { diff --git a/utils/package.json b/utils/package.json index a164ccfd..b106b25b 100644 --- a/utils/package.json +++ b/utils/package.json @@ -2,6 +2,7 @@ "name": "@directus-labs/utils", "type": "commonjs", "version": "0.0.0", + "private": true, "description": "Shared components for @directus-labs/extensions", "author": "", "license": "MIT",