|
| 1 | +# 🔗 Links: |
| 2 | +# Source file: https://github.com/rootstrap/react-native-template/blob/master/.github/workflows/new-cli-version.yml |
| 3 | + |
| 4 | +# ✍️ Description: |
| 5 | +# This workflow is used to create a new version of the CLI and publish it to the npm registry. |
| 6 | +# As this workflow will push code to the repo, we set up GitHub Bot as a Git user. |
| 7 | +# This Workflow need to be triggered manually from the Actions tab in the repo. |
| 8 | +# 1. Choose your release type (patch, minor, major) |
| 9 | +# 2. The workflow will run the np-release script which runs the following steps: |
| 10 | +# - Bump the version in package.json based on the release type using np |
| 11 | +# - Build & publish the CLI to the npm registry |
| 12 | +# |
| 13 | + |
| 14 | +# 🚨 GITHUB SECRETS REQUIRED: |
| 15 | +# - GH_TOKEN: A GitHub token with write repo access. |
| 16 | +# You can generate one from here: https://docs.github.com/en/[email protected]/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens |
| 17 | +# make sure to add it to the repo secrets with the name GH_TOKEN |
| 18 | + |
| 19 | +name: New CLI Version |
| 20 | + |
| 21 | +on: |
| 22 | + workflow_dispatch: |
| 23 | + inputs: |
| 24 | + release-type: |
| 25 | + type: choice |
| 26 | + description: 'Release type (one of): patch, minor, major' |
| 27 | + required: true |
| 28 | + default: 'patch' |
| 29 | + options: |
| 30 | + - patch |
| 31 | + - minor |
| 32 | + - major |
| 33 | + |
| 34 | +jobs: |
| 35 | + release: |
| 36 | + name: Create New Version and push new tag |
| 37 | + runs-on: ubuntu-latest |
| 38 | + permissions: |
| 39 | + contents: write |
| 40 | + steps: |
| 41 | + - name: 🔍 GH_TOKEN |
| 42 | + if: env.GH_TOKEN == '' |
| 43 | + env: |
| 44 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + run: echo "GH_TOKEN=${GITHUB_TOKEN}" >> $GITHUB_ENV |
| 46 | + |
| 47 | + - name: 📦 Checkout project repo |
| 48 | + uses: actions/checkout@v3 |
| 49 | + with: |
| 50 | + fetch-depth: 0 |
| 51 | + token: ${{ secrets.GH_TOKEN }} |
| 52 | + |
| 53 | + - name: 📝 Git User Setup |
| 54 | + run: | |
| 55 | + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 56 | + git config --global user.name "github-actions[bot]" |
| 57 | +
|
| 58 | + - name: 📦 Setup Node + PNPM |
| 59 | + uses: ./.github/actions/setup-node-pnpm-install |
| 60 | + |
| 61 | + - name: Install CLI dependencies |
| 62 | + run: | |
| 63 | + cd cli |
| 64 | + pnpm install --frozen-lockfile |
| 65 | +
|
| 66 | + - name: Bump release version |
| 67 | + run: | |
| 68 | + cd cli |
| 69 | + echo "NEW_VERSION=$(npm --no-git-tag-version version $RELEASE_TYPE)" >> $GITHUB_ENV |
| 70 | + echo "RELEASE_TAG=latest" >> $GITHUB_ENV |
| 71 | + env: |
| 72 | + RELEASE_TYPE: ${{ github.event.inputs.release-type }} |
| 73 | + |
| 74 | + - name: Commit package.json changes |
| 75 | + run: | |
| 76 | + git add "cli/package.json" |
| 77 | + git commit -m "build(cli): release ${{ env.NEW_VERSION }}" |
| 78 | +
|
| 79 | + - name: Set publishing config |
| 80 | + run: pnpm config set '//registry.npmjs.org/:_authToken' "${NODE_AUTH_TOKEN}" |
| 81 | + env: |
| 82 | + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} |
| 83 | + |
| 84 | + - name: Publish |
| 85 | + run: | |
| 86 | + cd cli |
| 87 | + pnpm publish --verbose --tag ${{ env.RELEASE_TAG }} |
| 88 | +
|
| 89 | + - name: Push changes to repository |
| 90 | + env: |
| 91 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 92 | + run: | |
| 93 | + git push origin && git push --tags |
0 commit comments