|
| 1 | +name: Publish to NPM |
| 2 | + |
| 3 | +# publish only when package json has changed - assuming version upgrade |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: [main] |
| 7 | + paths: "lib/fork-me/package.json" |
| 8 | + |
| 9 | +jobs: |
| 10 | + publish: |
| 11 | + # Don't run just after creating repo from template |
| 12 | + # Also avoid running after merging set-up PR |
| 13 | + if: github.run_number > 2 && github.event.repository.owner.login == 'react18-tools' |
| 14 | + runs-on: ubuntu-latest |
| 15 | + permissions: |
| 16 | + packages: write |
| 17 | + contents: write |
| 18 | + id-token: write |
| 19 | + |
| 20 | + defaults: |
| 21 | + run: |
| 22 | + working-directory: ./lib/fork-me |
| 23 | + |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v3 |
| 26 | + with: |
| 27 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 28 | + |
| 29 | + - uses: actions/setup-node@v3 |
| 30 | + with: |
| 31 | + node-version: 20 |
| 32 | + registry-url: https://registry.npmjs.org |
| 33 | + - run: npm i -g pnpm && pnpm i |
| 34 | + name: Install dependencies |
| 35 | + # fail and not publish if any of the unit tests are failing |
| 36 | + - name: Test |
| 37 | + run: pnpm test |
| 38 | + - name: Create release and publish to NPM |
| 39 | + run: pnpm build && pnpm publish-package |
| 40 | + # continue on error to publish scoped package name <- by default repo is setup for a non-scoped + scoped package name |
| 41 | + continue-on-error: true |
| 42 | + env: |
| 43 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} |
| 44 | + TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + OWNER: ${{ github.event.repository.owner.login }} |
| 46 | + REPO: ${{ github.event.repository.name }} |
| 47 | + |
| 48 | + - name: Publish Scoped package to NPM |
| 49 | + # continue on error - expecing npm to trow error if scoping is done twice |
| 50 | + continue-on-error: true |
| 51 | + id: publish_scoped |
| 52 | + run: cd dist && node ../scope.js && npm publish --provenance --access public |
| 53 | + env: |
| 54 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} |
| 55 | + TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 56 | + OWNER: ${{ github.event.repository.owner.login }} |
| 57 | + REPO: ${{ github.event.repository.name }} |
0 commit comments