|
| 1 | +name: Publish npm package |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + id-token: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + validate-pr-and-release: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Checkout repository |
| 18 | + uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + fetch-depth: 0 |
| 21 | + |
| 22 | + - name: Setup Node.js |
| 23 | + uses: actions/setup-node@v4 |
| 24 | + with: |
| 25 | + node-version: 22.14.0 |
| 26 | + |
| 27 | + - name: Upgrade npm and install Yarn |
| 28 | + run: npm install --global npm@11.5.1 yarn@1.22.22 |
| 29 | + |
| 30 | + - name: Verify npm version |
| 31 | + run: npm --version |
| 32 | + |
| 33 | + - name: Install dependencies |
| 34 | + run: yarn install --frozen-lockfile --ignore-engines |
| 35 | + |
| 36 | + - name: Build package |
| 37 | + run: npm run prepublishOnly |
| 38 | + |
| 39 | + - name: Check package contents |
| 40 | + run: npm pack --dry-run |
| 41 | + |
| 42 | + release-please-on-main: |
| 43 | + if: github.event_name == 'push' |
| 44 | + needs: validate-pr-and-release |
| 45 | + runs-on: ubuntu-latest |
| 46 | + permissions: |
| 47 | + contents: write |
| 48 | + pull-requests: write |
| 49 | + outputs: |
| 50 | + release_created: ${{ steps.release.outputs.release_created }} |
| 51 | + version: ${{ steps.release.outputs.version }} |
| 52 | + steps: |
| 53 | + - name: Checkout repository |
| 54 | + uses: actions/checkout@v4 |
| 55 | + with: |
| 56 | + fetch-depth: 0 |
| 57 | + |
| 58 | + - name: Create release PR or tag |
| 59 | + id: release |
| 60 | + uses: googleapis/release-please-action@v4 |
| 61 | + with: |
| 62 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 63 | + config-file: .github/release-please-config.json |
| 64 | + manifest-file: .release-please-manifest.json |
| 65 | + |
| 66 | + publish-release: |
| 67 | + if: needs.release-please-on-main.outputs.release_created == 'true' |
| 68 | + needs: release-please-on-main |
| 69 | + runs-on: ubuntu-latest |
| 70 | + permissions: |
| 71 | + contents: read |
| 72 | + id-token: write |
| 73 | + steps: |
| 74 | + - name: Checkout repository |
| 75 | + uses: actions/checkout@v4 |
| 76 | + with: |
| 77 | + fetch-depth: 0 |
| 78 | + |
| 79 | + - name: Setup Node.js |
| 80 | + uses: actions/setup-node@v4 |
| 81 | + with: |
| 82 | + node-version: 22.14.0 |
| 83 | + registry-url: https://registry.npmjs.org |
| 84 | + |
| 85 | + - name: Upgrade npm and install Yarn |
| 86 | + run: npm install --global npm@11.5.1 yarn@1.22.22 |
| 87 | + |
| 88 | + - name: Verify npm version |
| 89 | + run: npm --version |
| 90 | + |
| 91 | + - name: Install dependencies |
| 92 | + run: yarn install --frozen-lockfile --ignore-engines |
| 93 | + |
| 94 | + - name: Build package |
| 95 | + run: npm run prepublishOnly |
| 96 | + |
| 97 | + - name: Publish to npm |
| 98 | + run: npm publish --provenance --access public |
0 commit comments