|
| 1 | +name: Deploy (manual) |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'Version or semver (e.g., 3.2.0 | patch | minor | major)' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + tag: |
| 11 | + description: 'npm dist-tag to publish under' |
| 12 | + required: true |
| 13 | + default: latest |
| 14 | + type: choice |
| 15 | + options: |
| 16 | + - latest |
| 17 | + - next |
| 18 | + create_release: |
| 19 | + description: 'Also create a GitHub Release from the tag' |
| 20 | + required: false |
| 21 | + default: false |
| 22 | + type: boolean |
| 23 | + git_user_name: |
| 24 | + description: 'Git author name for release commit' |
| 25 | + required: false |
| 26 | + default: 'react-native-iap bot' |
| 27 | + type: string |
| 28 | + git_user_email: |
| 29 | + description: 'Git author email for release commit' |
| 30 | + required: false |
| 31 | + default: 'github-actions[bot]@users.noreply.github.com' |
| 32 | + type: string |
| 33 | + |
| 34 | +permissions: |
| 35 | + contents: write |
| 36 | + |
| 37 | +jobs: |
| 38 | + publish: |
| 39 | + runs-on: ubuntu-latest |
| 40 | + |
| 41 | + steps: |
| 42 | + - name: Checkout |
| 43 | + uses: actions/checkout@v4 |
| 44 | + with: |
| 45 | + fetch-depth: 0 |
| 46 | + |
| 47 | + - name: Setup Node.js |
| 48 | + uses: actions/setup-node@v4 |
| 49 | + with: |
| 50 | + node-version: 20.x |
| 51 | + registry-url: 'https://registry.npmjs.org' |
| 52 | + always-auth: true |
| 53 | + |
| 54 | + - name: Enable Corepack (Yarn 3) |
| 55 | + run: corepack enable |
| 56 | + |
| 57 | + - name: Use Yarn 3 cache dir |
| 58 | + id: yarn_cache |
| 59 | + run: echo "dir=$(yarn config get cacheFolder)" >> "$GITHUB_OUTPUT" |
| 60 | + |
| 61 | + - name: Restore Yarn cache |
| 62 | + uses: actions/cache@v4 |
| 63 | + with: |
| 64 | + path: ${{ steps.yarn_cache.outputs.dir }} |
| 65 | + key: yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }} |
| 66 | + restore-keys: | |
| 67 | + yarn-${{ runner.os }}- |
| 68 | +
|
| 69 | + - name: Install dependencies |
| 70 | + run: yarn install --immutable |
| 71 | + |
| 72 | + - name: Lint |
| 73 | + run: | |
| 74 | + yarn lint:tsc |
| 75 | + npx eslint --ext .ts,.tsx,.js,.jsx src plugin/src |
| 76 | + npx prettier --check "**/*.{md,js,jsx,ts,tsx}" |
| 77 | +
|
| 78 | + - name: Configure Git user |
| 79 | + run: | |
| 80 | + git config user.name "${{ github.event.inputs.git_user_name }}" |
| 81 | + git config user.email "${{ github.event.inputs.git_user_email }}" |
| 82 | +
|
| 83 | + - name: Bump version and tag |
| 84 | + id: bump |
| 85 | + env: |
| 86 | + INPUT_VERSION: ${{ github.event.inputs.version }} |
| 87 | + run: | |
| 88 | + # Yarn 3 uses corepack-managed npm; ensure git tagging commit is created |
| 89 | + npm version "$INPUT_VERSION" --tag-version-prefix="" -m "chore(release): %s" |
| 90 | + NEW_VERSION=$(node -p "require('./package.json').version") |
| 91 | + echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT" |
| 92 | +
|
| 93 | + - name: Prepare package (build + codegen) |
| 94 | + run: yarn prepare |
| 95 | + |
| 96 | + - name: Push commit and tags |
| 97 | + run: | |
| 98 | + git push --follow-tags |
| 99 | +
|
| 100 | + - name: Configure npm auth |
| 101 | + env: |
| 102 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 103 | + run: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc |
| 104 | + |
| 105 | + - name: Verify npm auth |
| 106 | + env: |
| 107 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 108 | + run: npm whoami |
| 109 | + |
| 110 | + - name: Publish to npm |
| 111 | + env: |
| 112 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 113 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 114 | + run: | |
| 115 | + if [ "${{ github.event.inputs.tag }}" = "latest" ]; then |
| 116 | + npm publish |
| 117 | + else |
| 118 | + npm publish --tag ${{ github.event.inputs.tag }} |
| 119 | + fi |
| 120 | +
|
| 121 | + - name: Create GitHub Release |
| 122 | + if: ${{ github.event.inputs.create_release == 'true' }} |
| 123 | + uses: softprops/action-gh-release@v2 |
| 124 | + with: |
| 125 | + tag_name: ${{ steps.bump.outputs.version }} |
| 126 | + name: ${{ steps.bump.outputs.version }} |
| 127 | + draft: false |
| 128 | + prerelease: ${{ github.event.inputs.tag != 'latest' }} |
| 129 | + generate_release_notes: true |
0 commit comments