|
| 1 | +name: Build & Publish Package |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + increment: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + preid: |
| 10 | + required: false |
| 11 | + type: string |
| 12 | + |
| 13 | +env: |
| 14 | + NODE_VERSION: 22 |
| 15 | + |
| 16 | +jobs: |
| 17 | + build-and-publish: |
| 18 | + runs-on: ubuntu-24.04 |
| 19 | + timeout-minutes: 5 |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} |
| 24 | + - run: | |
| 25 | + git config --global user.name 'AboutBits Tech' |
| 26 | + git config --global user.email 'tech@aboutbits.it' |
| 27 | + - uses: aboutbits/github-actions-node/setup-and-install@v2 |
| 28 | + with: |
| 29 | + node-version: ${{ env.NODE_VERSION }} |
| 30 | + registry-url: 'https://registry.npmjs.org' |
| 31 | + - name: Get current package version |
| 32 | + id: currentVersion |
| 33 | + run: echo "currentVersion=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT |
| 34 | + - name: Validate prerelease increment |
| 35 | + if: github.event.inputs.increment == 'prerelease' && !contains(steps.currentVersion.outputs.currentVersion, '-') |
| 36 | + run: exit 1 |
| 37 | + - name: npm version |
| 38 | + run: | |
| 39 | + if [ -n "${{ github.event.inputs.preid }}" ]; then |
| 40 | + npm version ${{ github.event.inputs.increment }} --preid ${{ github.event.inputs.preid }} |
| 41 | + else |
| 42 | + npm version ${{ github.event.inputs.increment }} |
| 43 | + fi |
| 44 | + - name: Get next package version |
| 45 | + id: nextVersion |
| 46 | + run: echo "nextVersion=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT |
| 47 | + - run: npm publish |
| 48 | + env: |
| 49 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 50 | + - name: Create GitHub release |
| 51 | + uses: actions/github-script@v7 |
| 52 | + with: |
| 53 | + script: | |
| 54 | + github.rest.repos.createRelease({ |
| 55 | + owner: context.repo.owner, |
| 56 | + repo: context.repo.repo, |
| 57 | + tag_name: 'v${{ steps.nextVersion.outputs.nextVersion }}', |
| 58 | + name: 'v${{ steps.nextVersion.outputs.nextVersion }}', |
| 59 | + prerelease: '${{ steps.nextVersion.outputs.nextVersion }}'.includes('-') |
| 60 | + }) |
0 commit comments