|
| 1 | +name: Release |
| 2 | + |
| 3 | +# This workflow is for PUBLIC repositories that need to use workflows from a PRIVATE repository |
| 4 | +# It uses token-based checkout to access the private npm-release-workflows repository |
| 5 | +# |
| 6 | +# SETUP INSTRUCTIONS: |
| 7 | +# 1. Create a Personal Access Token (PAT) or GitHub App token with 'repo' scope |
| 8 | +# - See documentation for token creation instructions (docs/credentials.md) |
| 9 | +# 2. Add the token as a secret named 'WORKFLOWS_ACCESS_GITHUB_TOKEN' in your repository |
| 10 | +# 3. Replace 'heroku' with your GitHub organization name |
| 11 | +# 4. Replace 'npm-release-workflows' with the actual repository name if different |
| 12 | +# 5. Adjust the hardcoded values in the workflow (package_manager, test_command, lint_command, build_command) |
| 13 | +# based on your project's needs - these are hardcoded in the workflow, not passed as inputs |
| 14 | +# 6. Copy this file to .github/workflows/release.yml in your project |
| 15 | + |
| 16 | +on: |
| 17 | + workflow_dispatch: |
| 18 | + inputs: |
| 19 | + # DRY RUN MODE |
| 20 | + # Set to true to test the release process without actually publishing to npm |
| 21 | + # Useful for validating workflow changes or testing version bumps |
| 22 | + dry_run: |
| 23 | + description: 'Test release without publishing (creates PR but skips npm publish)' |
| 24 | + type: boolean |
| 25 | + default: false |
| 26 | + required: false |
| 27 | + |
| 28 | +jobs: |
| 29 | + validate: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - name: Checkout workflows repository |
| 35 | + uses: actions/checkout@v4 |
| 36 | + with: |
| 37 | + repository: heroku/npm-release-workflows |
| 38 | + token: ${{ secrets.WORKFLOWS_ACCESS_GITHUB_TOKEN }} |
| 39 | + path: workflows-repo |
| 40 | + ref: main |
| 41 | + |
| 42 | + - name: Validate and test |
| 43 | + uses: ./workflows-repo/.github/actions/release-validate-public |
| 44 | + with: |
| 45 | + # Update these values to match your project: |
| 46 | + package-manager: pnpm # Options: npm, yarn, or pnpm (must match your project's package manager) |
| 47 | + lint_command: 'run lint' # Set to '' to skip if no lint script exists |
| 48 | + test_command: 'test' # Set to '' to skip if no test script exists |
| 49 | + |
| 50 | + release-please-pr: |
| 51 | + needs: validate |
| 52 | + runs-on: ubuntu-latest |
| 53 | + permissions: |
| 54 | + contents: write |
| 55 | + pull-requests: write |
| 56 | + outputs: |
| 57 | + release_created: ${{ steps.release-workflow.outputs.release_created }} |
| 58 | + tag_name: ${{ steps.release-workflow.outputs.tag_name }} |
| 59 | + pr_number: ${{ steps.release-workflow.outputs.pr_number }} |
| 60 | + config_file: ${{ steps.release-workflow.outputs.config_file }} |
| 61 | + manifest_file: ${{ steps.release-workflow.outputs.manifest_file }} |
| 62 | + npm_tag: ${{ steps.release-workflow.outputs.npm_tag }} |
| 63 | + package_name: ${{ steps.release-workflow.outputs.package_name }} |
| 64 | + no_release_needed: ${{ steps.release-workflow.outputs.no_release_needed }} |
| 65 | + pr_already_exists: ${{ steps.release-workflow.outputs.pr_already_exists }} |
| 66 | + steps: |
| 67 | + - uses: actions/checkout@v4 |
| 68 | + |
| 69 | + - name: Checkout workflows repository |
| 70 | + uses: actions/checkout@v4 |
| 71 | + with: |
| 72 | + repository: heroku/npm-release-workflows |
| 73 | + token: ${{ secrets.WORKFLOWS_ACCESS_GITHUB_TOKEN }} |
| 74 | + path: workflows-repo |
| 75 | + ref: main |
| 76 | + |
| 77 | + - name: Create release PR |
| 78 | + id: release-workflow |
| 79 | + uses: ./workflows-repo/.github/actions/release-please-pr-public |
| 80 | + with: |
| 81 | + # Update package-manager to match your project (npm, yarn, or pnpm) |
| 82 | + package-manager: pnpm # Must match your project's package manager |
| 83 | + branch_name: ${{ github.ref_name }} |
| 84 | + dry_run: ${{ inputs.dry_run }} |
| 85 | + |
| 86 | + publish: |
| 87 | + needs: release-please-pr |
| 88 | + if: needs.release-please-pr.result == 'success' && (needs.release-please-pr.outputs.pr_number != '' || needs.release-please-pr.outputs.pr_already_exists == 'true') |
| 89 | + runs-on: ubuntu-latest |
| 90 | + permissions: |
| 91 | + contents: write |
| 92 | + pull-requests: write |
| 93 | + id-token: write |
| 94 | + steps: |
| 95 | + - uses: actions/checkout@v4 |
| 96 | + |
| 97 | + - name: Checkout workflows repository |
| 98 | + uses: actions/checkout@v4 |
| 99 | + with: |
| 100 | + repository: heroku/npm-release-workflows |
| 101 | + token: ${{ secrets.WORKFLOWS_ACCESS_GITHUB_TOKEN }} |
| 102 | + path: workflows-repo |
| 103 | + ref: main |
| 104 | + |
| 105 | + - name: Publish to npm |
| 106 | + uses: ./workflows-repo/.github/actions/release-publish-public |
| 107 | + with: |
| 108 | + # Update these values to match your project: |
| 109 | + package-manager: pnpm # Options: npm, yarn, or pnpm (used for installing dependencies and building; publishing always uses pnpm) |
| 110 | + workflows_token: ${{ secrets.WORKFLOWS_ACCESS_GITHUB_TOKEN }} |
| 111 | + build_command: 'run build' # Set to '' to skip if no build script exists |
| 112 | + dry_run: ${{ inputs.dry_run }} |
| 113 | + npm_tag: ${{ needs.release-please-pr.outputs.npm_tag }} |
| 114 | + package_name: ${{ needs.release-please-pr.outputs.package_name }} |
| 115 | + pr_number: ${{ needs.release-please-pr.outputs.pr_number }} |
| 116 | + branch_name: ${{ github.ref_name }} |
| 117 | + |
0 commit comments