|
| 1 | +# Reusable workflow: build, bump version, publish to GitHub Packages, create GitHub Release |
| 2 | +# Called by release.yml in each package repo |
| 3 | +name: Publish Package (reusable) |
| 4 | + |
| 5 | +on: |
| 6 | + workflow_call: |
| 7 | + inputs: |
| 8 | + package-path: |
| 9 | + description: "Relative path to the package directory (e.g. packages/post-db)" |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + package-name: |
| 13 | + description: "npm package name (e.g. @backendworks/post-db)" |
| 14 | + required: true |
| 15 | + type: string |
| 16 | + bump: |
| 17 | + description: "Version bump type: patch | minor | major" |
| 18 | + required: false |
| 19 | + type: string |
| 20 | + default: "patch" |
| 21 | + secrets: |
| 22 | + GH_TOKEN: |
| 23 | + required: true |
| 24 | + |
| 25 | +jobs: |
| 26 | + publish: |
| 27 | + name: Build & Publish ${{ inputs.package-name }} |
| 28 | + runs-on: ubuntu-latest |
| 29 | + permissions: |
| 30 | + contents: write # push version tag + commit |
| 31 | + packages: write # publish to GitHub Packages |
| 32 | + id-token: write # provenance attestation |
| 33 | + |
| 34 | + defaults: |
| 35 | + run: |
| 36 | + working-directory: ${{ inputs.package-path }} |
| 37 | + |
| 38 | + steps: |
| 39 | + - name: Checkout |
| 40 | + uses: actions/checkout@v4 |
| 41 | + with: |
| 42 | + token: ${{ secrets.GH_TOKEN }} |
| 43 | + fetch-depth: 0 |
| 44 | + |
| 45 | + - name: Setup Node |
| 46 | + uses: actions/setup-node@v4 |
| 47 | + with: |
| 48 | + node-version: 20 |
| 49 | + registry-url: "https://npm.pkg.github.com" |
| 50 | + scope: "@backendworks" |
| 51 | + |
| 52 | + - name: Install dependencies |
| 53 | + run: npm ci |
| 54 | + |
| 55 | + - name: Generate Prisma client |
| 56 | + run: npx prisma generate |
| 57 | + |
| 58 | + - name: Build |
| 59 | + run: npm run build |
| 60 | + |
| 61 | + - name: Configure git |
| 62 | + run: | |
| 63 | + git config user.name "github-actions[bot]" |
| 64 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 65 | +
|
| 66 | + - name: Bump version |
| 67 | + id: bump |
| 68 | + run: | |
| 69 | + npm version ${{ inputs.bump }} --no-git-tag-version |
| 70 | + VERSION=$(node -p "require('./package.json').version") |
| 71 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 72 | +
|
| 73 | + - name: Commit & tag |
| 74 | + run: | |
| 75 | + git add package.json |
| 76 | + git commit -m "chore(release): ${{ inputs.package-name }}@${{ steps.bump.outputs.version }}" |
| 77 | + git tag "${{ inputs.package-name }}@${{ steps.bump.outputs.version }}" |
| 78 | + git push origin HEAD --follow-tags |
| 79 | + env: |
| 80 | + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} |
| 81 | + |
| 82 | + - name: Publish to GitHub Packages |
| 83 | + run: npm publish |
| 84 | + env: |
| 85 | + NODE_AUTH_TOKEN: ${{ secrets.GH_TOKEN }} |
| 86 | + |
| 87 | + - name: Create GitHub Release |
| 88 | + uses: softprops/action-gh-release@v2 |
| 89 | + with: |
| 90 | + tag_name: "${{ inputs.package-name }}@${{ steps.bump.outputs.version }}" |
| 91 | + name: "${{ inputs.package-name }} v${{ steps.bump.outputs.version }}" |
| 92 | + generate_release_notes: true |
| 93 | + token: ${{ secrets.GH_TOKEN }} |
0 commit comments