|
| 1 | +name: React Native — Publish to npm |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: |
| 6 | + - published |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + dry-run: |
| 10 | + description: Run the full pipeline and pack the package, but skip npm publish. |
| 11 | + required: false |
| 12 | + type: boolean |
| 13 | + default: true |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: read |
| 17 | + id-token: write |
| 18 | + |
| 19 | +concurrency: |
| 20 | + group: react-native-publish |
| 21 | + cancel-in-progress: false |
| 22 | + |
| 23 | +jobs: |
| 24 | + release: |
| 25 | + name: Publish @shopify/checkout-kit-react-native to npm |
| 26 | + if: | |
| 27 | + (github.event_name == 'release' && startsWith(github.event.release.tag_name, 'react-native/')) |
| 28 | + || github.event_name == 'workflow_dispatch' |
| 29 | + runs-on: ubuntu-latest |
| 30 | + timeout-minutes: 15 |
| 31 | + defaults: |
| 32 | + run: |
| 33 | + working-directory: platforms/react-native |
| 34 | + |
| 35 | + steps: |
| 36 | + - name: Checkout |
| 37 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 38 | + |
| 39 | + - name: Validate release tag matches package.json version |
| 40 | + id: release |
| 41 | + working-directory: ${{ github.workspace }} |
| 42 | + env: |
| 43 | + RELEASE_TAG: ${{ github.event.release.tag_name }} |
| 44 | + run: | |
| 45 | + set -euo pipefail |
| 46 | + if [ "$GITHUB_EVENT_NAME" = "release" ]; then |
| 47 | + TAG="$RELEASE_TAG" |
| 48 | + else |
| 49 | + TAG="$GITHUB_REF_NAME" |
| 50 | + fi |
| 51 | +
|
| 52 | + .github/scripts/validate-release-version "React Native" "" "$TAG" >> "$GITHUB_OUTPUT" |
| 53 | +
|
| 54 | + # `ignore-scripts` prevents dependency postinstall scripts from running in |
| 55 | + # this privileged npm publishing job. |
| 56 | + - name: Setup Node.js, pnpm, and install dependencies |
| 57 | + uses: ./.github/actions/setup |
| 58 | + with: |
| 59 | + node-version-file: platforms/react-native/package.json |
| 60 | + cache-dependency-path: platforms/react-native/pnpm-lock.yaml |
| 61 | + package-json-file: platforms/react-native/package.json |
| 62 | + working-directory: platforms/react-native |
| 63 | + ignore-scripts: "true" |
| 64 | + |
| 65 | + - name: Verify version is not already published |
| 66 | + run: | |
| 67 | + set -euo pipefail |
| 68 | + NAME=$(node -p "require('./modules/@shopify/checkout-kit-react-native/package.json').name") |
| 69 | + VERSION=$(node -p "require('./modules/@shopify/checkout-kit-react-native/package.json').version") |
| 70 | + ENCODED_NAME=$(node -p "encodeURIComponent(require('./modules/@shopify/checkout-kit-react-native/package.json').name)") |
| 71 | + URL="https://registry.npmjs.org/${ENCODED_NAME}/${VERSION}" |
| 72 | + if curl -fs "$URL" > /dev/null; then |
| 73 | + echo "::error::${NAME}@${VERSION} is already published on npm. Bump platforms/react-native/modules/@shopify/checkout-kit-react-native/package.json before re-running." |
| 74 | + exit 1 |
| 75 | + fi |
| 76 | + echo "::notice::${NAME}@${VERSION} is not yet on npm — safe to proceed." |
| 77 | +
|
| 78 | + - name: Build package |
| 79 | + run: | |
| 80 | + set -euo pipefail |
| 81 | + cp README.md modules/@shopify/checkout-kit-react-native/README.md |
| 82 | + pnpm module clean |
| 83 | + pnpm module build |
| 84 | +
|
| 85 | + - name: Pack and inspect contents |
| 86 | + run: | |
| 87 | + set -euo pipefail |
| 88 | + mkdir -p /tmp/react-native-publish |
| 89 | + cd modules/@shopify/checkout-kit-react-native |
| 90 | + npm pack --dry-run |
| 91 | + npm pack --pack-destination /tmp/react-native-publish |
| 92 | + echo "Tarball contents:" |
| 93 | + tar -tzf /tmp/react-native-publish/*.tgz | sort |
| 94 | +
|
| 95 | + - name: Publish to npm |
| 96 | + if: ${{ !inputs.dry-run }} |
| 97 | + run: | |
| 98 | + set -euo pipefail |
| 99 | + cd modules/@shopify/checkout-kit-react-native |
| 100 | + npm publish --access public --tag "$NPM_TAG" --provenance |
| 101 | + env: |
| 102 | + NPM_TAG: ${{ steps.release.outputs.npm_tag }} |
| 103 | + NPM_CONFIG_PROVENANCE: "true" |
| 104 | + NPM_TOKEN: "" |
| 105 | + NODE_AUTH_TOKEN: "" |
| 106 | + |
| 107 | + - name: Dry-run summary |
| 108 | + if: ${{ inputs.dry-run }} |
| 109 | + env: |
| 110 | + NPM_TAG: ${{ steps.release.outputs.npm_tag }} |
| 111 | + run: | |
| 112 | + echo "::notice::Dry-run requested — skipped npm publish." |
| 113 | + echo "Would have published with: --access public --tag $NPM_TAG --provenance" |
0 commit comments