|
| 1 | +name: Create npm and GitHub Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + node-version: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + require-build: |
| 10 | + default: true |
| 11 | + type: string |
| 12 | + release-directory: |
| 13 | + default: './' |
| 14 | + type: string |
| 15 | + secrets: |
| 16 | + github-token: |
| 17 | + required: true |
| 18 | + npm-token: |
| 19 | + required: true |
| 20 | + |
| 21 | +### TODO: Replace instances of './.github/actions/' w/ `auth0/dx-sdk-actions/` and append `@latest` after the common `dx-sdk-actions` repo is made public. |
| 22 | +### TODO: Also remove `get-prerelease`, `get-version`, `release-create`, `tag-create` and `tag-exists` actions from this repo's .github/actions folder once the repo is public. |
| 23 | + |
| 24 | +jobs: |
| 25 | + release: |
| 26 | + if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.merged && startsWith(github.event.pull_request.head.ref, 'release/')) |
| 27 | + runs-on: ubuntu-latest |
| 28 | + environment: release |
| 29 | + |
| 30 | + steps: |
| 31 | + # Checkout the code |
| 32 | + - uses: actions/checkout@v4 |
| 33 | + with: |
| 34 | + fetch-depth: 0 |
| 35 | + |
| 36 | + # Get the version from the branch name |
| 37 | + - id: get_version |
| 38 | + uses: ./.github/actions/get-version |
| 39 | + |
| 40 | + # Get the prerelease flag from the branch name |
| 41 | + - id: get_prerelease |
| 42 | + uses: ./.github/actions/get-prerelease |
| 43 | + with: |
| 44 | + version: ${{ steps.get_version.outputs.version }} |
| 45 | + |
| 46 | + # Get the release notes |
| 47 | + - id: get_release_notes |
| 48 | + uses: ./.github/actions/get-release-notes |
| 49 | + with: |
| 50 | + token: ${{ secrets.github-token }} |
| 51 | + version: ${{ steps.get_version.outputs.version }} |
| 52 | + repo_owner: ${{ github.repository_owner }} |
| 53 | + repo_name: ${{ github.event.repository.name }} |
| 54 | + |
| 55 | + # Check if the tag already exists |
| 56 | + - id: tag_exists |
| 57 | + uses: ./.github/actions/tag-exists |
| 58 | + with: |
| 59 | + tag: ${{ steps.get_version.outputs.version }} |
| 60 | + token: ${{ secrets.github-token }} |
| 61 | + |
| 62 | + # If the tag already exists, exit with an error |
| 63 | + - if: steps.tag_exists.outputs.exists == 'true' |
| 64 | + run: exit 1 |
| 65 | + |
| 66 | + # Publish the release to npm |
| 67 | + - uses: ./.github/actions/npm-publish |
| 68 | + with: |
| 69 | + node-version: ${{ inputs.node-version }} |
| 70 | + require-build: ${{ inputs.require-build }} |
| 71 | + release-directory: ${{ inputs.release-directory }} |
| 72 | + version: ${{ steps.get_version.outputs.version }} |
| 73 | + npm-token: ${{ secrets.npm-token }} |
| 74 | + |
| 75 | + # Create a release for the tag |
| 76 | + - uses: ./.github/actions/release-create |
| 77 | + with: |
| 78 | + token: ${{ secrets.github-token }} |
| 79 | + name: ${{ steps.get_version.outputs.version }} |
| 80 | + body: ${{ steps.get_release_notes.outputs.release-notes }} |
| 81 | + tag: ${{ steps.get_version.outputs.version }} |
| 82 | + commit: ${{ github.sha }} |
| 83 | + prerelease: ${{ steps.get_prerelease.outputs.prerelease }} |
0 commit comments