Publish Single Package Canary to NPM #25
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
| name: Publish Single Package Canary to NPM | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| branch: | |
| description: "Branch to release from" | |
| required: true | |
| default: "v2.0" | |
| dir: | |
| description: "Path to the package (e.g., packages/pos-client)" | |
| required: true | |
| canaryVersion: | |
| description: "Custom version (e.g., 1.2.3-canary.42)" | |
| required: true | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| with: | |
| ref: ${{ github.event.inputs.branch }} | |
| - name: Validate canary version format π | |
| run: | | |
| VERSION="${{ github.event.inputs.canaryVersion }}" | |
| if [[ ! "$VERSION" =~ -canary\. ]]; then | |
| echo "β Invalid version: '$VERSION'. It must include '-canary.'." | |
| exit 1 | |
| fi | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20.x" | |
| registry-url: "https://registry.npmjs.org" | |
| - name: Validate dir input π | |
| run: | | |
| DIR="${{ github.event.inputs.dir }}" | |
| # Only allow directories like packages/foo or providers/bar (no slashes after the prefix, no .., no special chars) | |
| if [[ ! "$DIR" =~ ^(packages|providers)/[a-zA-Z0-9_-]+$ ]]; then | |
| echo "β Invalid dir: $DIR" | |
| exit 1 | |
| fi | |
| if [ ! -d "$DIR" ]; then | |
| echo "β Directory does not exist: $DIR" | |
| exit 1 | |
| fi | |
| echo "β Valid dir: $DIR" | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build project | |
| run: npm run build | |
| - name: Update package.json in target dir π¦ | |
| run: | | |
| DIR="${{ github.event.inputs.dir }}" | |
| VERSION="${{ github.event.inputs.canaryVersion }}" | |
| if [ ! -f "$DIR/package.json" ]; then | |
| echo "β No package.json found in $DIR" | |
| exit 1 | |
| fi | |
| echo "π¦ Updating version of $DIR to $VERSION" | |
| npm version "$VERSION" --no-git-tag-version --prefix "$DIR" | |
| - name: Rebuild after version change π | |
| run: npm run build | |
| - name: Publish canary on NPM π | |
| run: | | |
| cd ${{ github.event.inputs.dir }} | |
| npm publish --access public --tag canary | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |