|
| 1 | +name: Release to npm |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + version: |
| 9 | + description: 'Version to release (e.g., 0.1.0)' |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + |
| 13 | +jobs: |
| 14 | + build-and-publish: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout code |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Set up Node.js |
| 22 | + uses: actions/setup-node@v4 |
| 23 | + with: |
| 24 | + node-version: '20' |
| 25 | + registry-url: 'https://registry.npmjs.org' |
| 26 | + |
| 27 | + - name: Extract version from tag or input |
| 28 | + id: version |
| 29 | + run: | |
| 30 | + if [ "${{ github.event_name }}" == "release" ]; then |
| 31 | + VERSION=${GITHUB_REF#refs/tags/v} |
| 32 | + VERSION=${VERSION#refs/tags/} |
| 33 | + else |
| 34 | + VERSION="${{ github.event.inputs.version }}" |
| 35 | + fi |
| 36 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 37 | + echo "Version: $VERSION" |
| 38 | + |
| 39 | + - name: Update version in package.json |
| 40 | + run: | |
| 41 | + VERSION="${{ steps.version.outputs.version }}" |
| 42 | + npm version $VERSION --no-git-tag-version |
| 43 | + |
| 44 | + - name: Install dependencies |
| 45 | + run: | |
| 46 | + npm ci |
| 47 | + |
| 48 | + - name: Install Playwright browsers |
| 49 | + run: | |
| 50 | + npx playwright install chromium |
| 51 | + |
| 52 | + - name: Run tests |
| 53 | + run: | |
| 54 | + npm test |
| 55 | + env: |
| 56 | + CI: true |
| 57 | + |
| 58 | + - name: Build package |
| 59 | + run: | |
| 60 | + npm run build |
| 61 | + |
| 62 | + - name: Publish to npm |
| 63 | + run: | |
| 64 | + npm publish --access public |
| 65 | + env: |
| 66 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 67 | + |
| 68 | + - name: Create GitHub Release |
| 69 | + if: github.event_name == 'workflow_dispatch' |
| 70 | + uses: softprops/action-gh-release@v1 |
| 71 | + with: |
| 72 | + tag_name: v${{ steps.version.outputs.version }} |
| 73 | + name: Release v${{ steps.version.outputs.version }} |
| 74 | + body: | |
| 75 | + Release v${{ steps.version.outputs.version }} of sentience-ts |
| 76 | + |
| 77 | + ## Installation |
| 78 | + ```bash |
| 79 | + npm install sentience-ts@${{ steps.version.outputs.version }} |
| 80 | + ``` |
| 81 | + draft: false |
| 82 | + prerelease: false |
| 83 | + env: |
| 84 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 85 | + |
0 commit comments