|
| 1 | +name: Publish Rosettify Plugins |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: |
| 8 | + - 'src/rosettify-plugins/**' |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +jobs: |
| 12 | + build-test-deploy: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + permissions: |
| 16 | + contents: read |
| 17 | + id-token: write |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout code |
| 21 | + uses: actions/checkout@v5 |
| 22 | + |
| 23 | + - name: Set up Node.js |
| 24 | + uses: actions/setup-node@v5 |
| 25 | + with: |
| 26 | + node-version: '24' |
| 27 | + registry-url: 'https://registry.npmjs.org' |
| 28 | + |
| 29 | + - name: Update npm |
| 30 | + run: npm install -g npm@latest |
| 31 | + |
| 32 | + - name: Install dependencies |
| 33 | + working-directory: ./src/rosettify-plugins |
| 34 | + run: npm ci |
| 35 | + |
| 36 | + - name: Run type validation |
| 37 | + working-directory: ./src/rosettify-plugins |
| 38 | + run: npm run typecheck |
| 39 | + |
| 40 | + - name: Build package |
| 41 | + working-directory: ./src/rosettify-plugins |
| 42 | + run: npm run build |
| 43 | + |
| 44 | + - name: Run tests |
| 45 | + working-directory: ./src/rosettify-plugins |
| 46 | + run: npm run test |
| 47 | + |
| 48 | + - name: Check if version exists on npm |
| 49 | + id: check_version |
| 50 | + working-directory: ./src/rosettify-plugins |
| 51 | + run: | |
| 52 | + VERSION=$(node -p "require('./package.json').version") |
| 53 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 54 | +
|
| 55 | + HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" https://registry.npmjs.org/rosettify-plugins/${VERSION}) |
| 56 | +
|
| 57 | + if [ "$HTTP_CODE" = "200" ]; then |
| 58 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 59 | + echo "::warning::Version $VERSION already exists on npm" |
| 60 | + else |
| 61 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 62 | + echo "Version $VERSION is new, will publish" |
| 63 | + fi |
| 64 | +
|
| 65 | + - name: Publish to npm |
| 66 | + if: steps.check_version.outputs.exists == 'false' |
| 67 | + working-directory: ./src/rosettify-plugins |
| 68 | + run: npm publish --access public |
| 69 | + |
| 70 | + - name: Fail if version exists |
| 71 | + if: steps.check_version.outputs.exists == 'true' |
| 72 | + run: | |
| 73 | + echo "::error::Version ${{ steps.check_version.outputs.version }} already exists on npm" |
| 74 | + echo "" |
| 75 | + echo "npm does not allow re-publishing the same version." |
| 76 | + echo "Please increment the version number in:" |
| 77 | + echo " src/rosettify-plugins/package.json (version field - single source of truth)" |
| 78 | + echo "" |
| 79 | + echo "Current version: ${{ steps.check_version.outputs.version }}" |
| 80 | + exit 1 |
| 81 | +
|
| 82 | + - name: Publish Success |
| 83 | + if: steps.check_version.outputs.exists == 'false' |
| 84 | + run: | |
| 85 | + echo "Successfully published version ${{ steps.check_version.outputs.version }} to npm!" |
| 86 | + echo "Package available at: https://www.npmjs.com/package/rosettify-plugins/v/${{ steps.check_version.outputs.version }}" |
| 87 | + echo "" |
| 88 | + echo "Install with: npm install -g rosettify-plugins@${{ steps.check_version.outputs.version }}" |
| 89 | + echo "Or with npx: npx rosettify-plugins" |
0 commit comments