|
| 1 | +name: TypeScript SDK Publish |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'ts-v*.*.*' |
| 7 | + |
| 8 | +jobs: |
| 9 | + publish: |
| 10 | + name: Build and Publish |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + contents: read |
| 14 | + id-token: write # Required for provenance |
| 15 | + |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Check if tag is on main branch |
| 20 | + run: | |
| 21 | + if ! git branch -r --contains ${{ github.ref }} | grep -q 'origin/main$'; then |
| 22 | + echo "Tag is not on main branch. Aborting." |
| 23 | + exit 1 |
| 24 | + fi |
| 25 | +
|
| 26 | + - name: Extract version from tag |
| 27 | + id: extract_version |
| 28 | + run: | |
| 29 | + # Extract version from ts-v*.*.* format |
| 30 | + TAG=${{ github.ref_name }} |
| 31 | + VERSION=${TAG#ts-v} |
| 32 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 33 | +
|
| 34 | + - name: Setup Node.js |
| 35 | + uses: actions/setup-node@v4 |
| 36 | + with: |
| 37 | + node-version: '20' |
| 38 | + registry-url: 'https://registry.npmjs.org' |
| 39 | + |
| 40 | + - name: Setup pnpm |
| 41 | + uses: pnpm/action-setup@v2 |
| 42 | + with: |
| 43 | + version: '9' |
| 44 | + run_install: false |
| 45 | + |
| 46 | + - name: Install dependencies |
| 47 | + working-directory: typescript |
| 48 | + run: pnpm install |
| 49 | + |
| 50 | + - name: Run linters |
| 51 | + working-directory: typescript |
| 52 | + run: pnpm lint |
| 53 | + |
| 54 | + - name: Run tests |
| 55 | + working-directory: typescript |
| 56 | + run: pnpm test |
| 57 | + |
| 58 | + - name: Update version in package.json |
| 59 | + working-directory: typescript |
| 60 | + run: | |
| 61 | + # Use jq to update the version in package.json |
| 62 | + jq '.version = "${{ steps.extract_version.outputs.version }}"' package.json > package.json.tmp |
| 63 | + mv package.json.tmp package.json |
| 64 | + |
| 65 | + - name: Build package |
| 66 | + working-directory: typescript |
| 67 | + run: pnpm build:prod |
| 68 | + |
| 69 | + - name: Publish to NPM |
| 70 | + working-directory: typescript |
| 71 | + run: npm publish --provenance |
| 72 | + env: |
| 73 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments