|
| 1 | +# SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | +# SPDX-FileCopyrightText: 2025 Hyperpolymath |
| 3 | +name: Publish to npm |
| 4 | + |
| 5 | +on: |
| 6 | + release: |
| 7 | + types: [published] |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + dry_run: |
| 11 | + description: 'Dry run (do not actually publish)' |
| 12 | + required: false |
| 13 | + default: 'true' |
| 14 | + type: boolean |
| 15 | + package: |
| 16 | + description: 'Package to publish' |
| 17 | + required: false |
| 18 | + default: 'all' |
| 19 | + type: choice |
| 20 | + options: |
| 21 | + - all |
| 22 | + - javascript |
| 23 | + - typescript |
| 24 | + |
| 25 | +permissions: read-all |
| 26 | + |
| 27 | +jobs: |
| 28 | + publish-javascript: |
| 29 | + name: Publish JavaScript package |
| 30 | + runs-on: ubuntu-latest |
| 31 | + if: inputs.package == 'all' || inputs.package == 'javascript' || github.event_name == 'release' |
| 32 | + permissions: |
| 33 | + contents: read |
| 34 | + id-token: write |
| 35 | + defaults: |
| 36 | + run: |
| 37 | + working-directory: bindings/javascript |
| 38 | + |
| 39 | + steps: |
| 40 | + - name: Checkout repository |
| 41 | + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 |
| 42 | + |
| 43 | + - name: Setup Node.js |
| 44 | + uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4 |
| 45 | + with: |
| 46 | + node-version: '20' |
| 47 | + registry-url: 'https://registry.npmjs.org' |
| 48 | + |
| 49 | + - name: Verify package |
| 50 | + run: npm pack --dry-run |
| 51 | + |
| 52 | + - name: Publish to npm |
| 53 | + if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.dry_run == false) |
| 54 | + run: npm publish --access public --provenance |
| 55 | + env: |
| 56 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 57 | + |
| 58 | + publish-typescript: |
| 59 | + name: Publish TypeScript package |
| 60 | + runs-on: ubuntu-latest |
| 61 | + if: inputs.package == 'all' || inputs.package == 'typescript' || github.event_name == 'release' |
| 62 | + permissions: |
| 63 | + contents: read |
| 64 | + id-token: write |
| 65 | + defaults: |
| 66 | + run: |
| 67 | + working-directory: bindings/typescript |
| 68 | + |
| 69 | + steps: |
| 70 | + - name: Checkout repository |
| 71 | + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 |
| 72 | + |
| 73 | + - name: Setup Node.js |
| 74 | + uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4 |
| 75 | + with: |
| 76 | + node-version: '20' |
| 77 | + registry-url: 'https://registry.npmjs.org' |
| 78 | + |
| 79 | + - name: Install dependencies |
| 80 | + run: npm install |
| 81 | + |
| 82 | + - name: Build TypeScript |
| 83 | + run: npm run build |
| 84 | + |
| 85 | + - name: Verify package |
| 86 | + run: npm pack --dry-run |
| 87 | + |
| 88 | + - name: Publish to npm |
| 89 | + if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.dry_run == false) |
| 90 | + run: npm publish --access public --provenance |
| 91 | + env: |
| 92 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 93 | + |
| 94 | + summary: |
| 95 | + name: Publish summary |
| 96 | + needs: [publish-javascript, publish-typescript] |
| 97 | + runs-on: ubuntu-latest |
| 98 | + if: always() |
| 99 | + |
| 100 | + steps: |
| 101 | + - name: Summary |
| 102 | + run: | |
| 103 | + echo "## npm Packages Published" >> $GITHUB_STEP_SUMMARY |
| 104 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 105 | + echo "| Package | Registry |" >> $GITHUB_STEP_SUMMARY |
| 106 | + echo "|---------|----------|" >> $GITHUB_STEP_SUMMARY |
| 107 | + echo "| @proven/javascript | [npm](https://www.npmjs.com/package/@proven/javascript) |" >> $GITHUB_STEP_SUMMARY |
| 108 | + echo "| @proven/typescript | [npm](https://www.npmjs.com/package/@proven/typescript) |" >> $GITHUB_STEP_SUMMARY |
0 commit comments