Skip to content

swapping pnpm for npm #4

swapping pnpm for npm

swapping pnpm for npm #4

name: Publish x402 Package (Matrix)
on:
# Comment out manual trigger
# workflow_dispatch:
# inputs:
# packages:
# description: "Select packages to publish"
# required: true
# type: choice
# options:
# - "all"
# - "express"
# - "hono"
# - "fetch"
# - "facilitator"
# default: "all"
# Automatic trigger on any branch
push:
branches:
- '**'
jobs:
publish-x402-package:
runs-on: ubuntu-latest
# Only use the npm environment on main branch
environment: ${{ github.ref == 'refs/heads/main' && 'npm' || '' }}
permissions:
contents: read
id-token: write
strategy:
matrix:
package: ["express"] # Hardcoded for testing, can be expanded later
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "18"
registry-url: "https://registry.npmjs.org"
cache: "npm"
cache-dependency-path: ./x402/packages/typescript/package-lock.json
- name: Install and build
working-directory: ./x402/packages/typescript/x402
run: |
npm ci
npm run build
- name: Generate package.json for ${{ matrix.package }}
working-directory: ./x402/packages/typescript/x402
run: |
SELECTED="${{ matrix.package }}"
# Extract base package information
BASE_NAME=$(node -p "require('./package.json').name")
BASE_VERSION=$(node -p "require('./package.json').version")
BASE_AUTHOR=$(node -p "require('./package.json').author")
BASE_LICENSE=$(node -p "require('./package.json').license")
BASE_REPOSITORY=$(node -p "JSON.stringify(require('./package.json').repository)")
# Check for component-specific version file
if [ -f "src/$SELECTED/version" ]; then
COMPONENT_VERSION=$(cat "src/$SELECTED/version")
echo "Using component-specific version: $COMPONENT_VERSION for $SELECTED"
else
COMPONENT_VERSION="$BASE_VERSION"
echo "Using base version: $COMPONENT_VERSION for $SELECTED"
fi
# Create specific package.json for the component
cat > ./dist/$SELECTED/package.json << EOF
{
"name": "${BASE_NAME}-${SELECTED}",
"version": "${COMPONENT_VERSION}",
"description": "${SELECTED} integration for x402",
"main": "index.js",
"types": "index.d.ts",
"author": ${BASE_AUTHOR},
"license": "${BASE_LICENSE}",
"repository": ${BASE_REPOSITORY},
"dependencies": {
"${BASE_NAME}": "^${BASE_VERSION}"
},
"peerDependencies": {
"${SELECTED}": "*"
}
}
EOF
- name: Publish ${{ matrix.package }} package (dry-run for non-main branches)
working-directory: ./x402/packages/typescript/x402
run: |
SELECTED="${{ matrix.package }}"
cd ./dist/$SELECTED
# Get the version from package.json
PACKAGE_VERSION=$(node -p "require('./package.json').version")
PACKAGE_NAME=$(node -p "require('./package.json').name")
echo "Publishing $PACKAGE_NAME@$PACKAGE_VERSION"
# Only publish on main branch, do dry-run otherwise
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "Running on main branch - would publish for real"
# npm publish --provenance --access public
else
echo "Running on non-main branch (${{ github.ref }}) - dry run only"
# npm publish --dry-run --provenance --access public
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}