|
| 1 | +# Publish workflow for xdk-typescript |
| 2 | +# Triggered by the generator repo via repository_dispatch |
| 3 | +# Also supports manual triggering for hotfixes |
| 4 | + |
| 5 | +name: Publish to npm |
| 6 | + |
| 7 | +on: |
| 8 | + repository_dispatch: |
| 9 | + types: [release] |
| 10 | + |
| 11 | + workflow_dispatch: |
| 12 | + inputs: |
| 13 | + version: |
| 14 | + description: 'Version to publish (must match package.json)' |
| 15 | + required: true |
| 16 | + type: string |
| 17 | + |
| 18 | +jobs: |
| 19 | + publish: |
| 20 | + name: Build and Publish |
| 21 | + runs-on: ubuntu-latest |
| 22 | + permissions: |
| 23 | + contents: write |
| 24 | + environment: |
| 25 | + name: npm |
| 26 | + url: https://www.npmjs.com/package/@xdevplatform/xdk |
| 27 | + |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@v4 |
| 30 | + |
| 31 | + - name: Get version |
| 32 | + id: version |
| 33 | + run: | |
| 34 | + if [ "${{ github.event_name }}" = "repository_dispatch" ]; then |
| 35 | + VERSION="${{ github.event.client_payload.version }}" |
| 36 | + else |
| 37 | + VERSION="${{ inputs.version }}" |
| 38 | + fi |
| 39 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 40 | + echo "📦 Publishing version: $VERSION" |
| 41 | + |
| 42 | + - name: Verify version matches package.json |
| 43 | + run: | |
| 44 | + PKG_VERSION=$(node -p "require('./package.json').version") |
| 45 | + if [ "$PKG_VERSION" != "${{ steps.version.outputs.version }}" ]; then |
| 46 | + echo "❌ Version mismatch!" |
| 47 | + echo " package.json: $PKG_VERSION" |
| 48 | + echo " Requested: ${{ steps.version.outputs.version }}" |
| 49 | + exit 1 |
| 50 | + fi |
| 51 | + echo "✅ Version verified: $PKG_VERSION" |
| 52 | + |
| 53 | + - name: Setup Node.js |
| 54 | + uses: actions/setup-node@v4 |
| 55 | + with: |
| 56 | + node-version: '20' |
| 57 | + registry-url: 'https://registry.npmjs.org' |
| 58 | + cache: 'npm' |
| 59 | + |
| 60 | + - name: Install dependencies |
| 61 | + run: npm ci |
| 62 | + |
| 63 | + - name: Build |
| 64 | + run: npm run build |
| 65 | + |
| 66 | + - name: Run tests |
| 67 | + run: npm test |
| 68 | + |
| 69 | + - name: Publish to npm |
| 70 | + run: npm publish |
| 71 | + env: |
| 72 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 73 | + |
| 74 | + - name: Create Git tag |
| 75 | + run: | |
| 76 | + git config user.name "github-actions[bot]" |
| 77 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 78 | + git tag -a "v${{ steps.version.outputs.version }}" -m "Release v${{ steps.version.outputs.version }}" |
| 79 | + git push origin "v${{ steps.version.outputs.version }}" |
| 80 | + |
| 81 | + - name: Create GitHub Release |
| 82 | + uses: softprops/action-gh-release@v2 |
| 83 | + with: |
| 84 | + tag_name: v${{ steps.version.outputs.version }} |
| 85 | + name: v${{ steps.version.outputs.version }} |
| 86 | + generate_release_notes: true |
| 87 | + draft: false |
| 88 | + prerelease: ${{ contains(steps.version.outputs.version, 'beta') || contains(steps.version.outputs.version, 'alpha') }} |
| 89 | + |
| 90 | + - name: Summary |
| 91 | + run: | |
| 92 | + echo "# 🎉 Published to npm" >> $GITHUB_STEP_SUMMARY |
| 93 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 94 | + echo "**Version:** \`${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY |
| 95 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 96 | + echo "## Install" >> $GITHUB_STEP_SUMMARY |
| 97 | + echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY |
| 98 | + echo "npm install @xdevplatform/xdk@${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY |
| 99 | + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |
| 100 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 101 | + echo "## Links" >> $GITHUB_STEP_SUMMARY |
| 102 | + echo "- [npm](https://www.npmjs.com/package/@xdevplatform/xdk/v/${{ steps.version.outputs.version }})" >> $GITHUB_STEP_SUMMARY |
| 103 | + echo "- [GitHub Release](https://github.com/${{ github.repository }}/releases/tag/v${{ steps.version.outputs.version }})" >> $GITHUB_STEP_SUMMARY |
| 104 | +
|
0 commit comments