|
| 1 | +# Reusable workflow that performs every `npm publish` in this repo. |
| 2 | +# |
| 3 | +# Why this exists: npmjs.com Trusted Publishing accepts only ONE |
| 4 | +# (org, repo, workflow_filename, environment) tuple per package. If |
| 5 | +# `react-native` were published from `publish-release.yml` AND |
| 6 | +# `nightly.yml` directly, we'd need two Trusted Publisher entries per |
| 7 | +# package — npm rejects that. By moving every `npm publish` into this |
| 8 | +# single reusable workflow file, the OIDC `job_workflow_ref` claim |
| 9 | +# always resolves to `publish-npm.yml` regardless of which top-level |
| 10 | +# workflow triggered the run, so each package needs exactly one |
| 11 | +# Trusted Publisher entry pointing here. |
| 12 | +# |
| 13 | +# See https://docs.npmjs.com/trusted-publishers and |
| 14 | +# https://docs.github.com/en/actions/sharing-automations/reusing-workflows . |
| 15 | +name: Publish to npm (reusable) |
| 16 | + |
| 17 | +on: |
| 18 | + workflow_call: |
| 19 | + inputs: |
| 20 | + mode: |
| 21 | + description: | |
| 22 | + 'react-native' runs the full Android/iOS-prebuilt + JS build |
| 23 | + and publishes via scripts/releases-ci/publish-npm.js (which |
| 24 | + publishes `react-native` and, in nightly mode, every |
| 25 | + @react-native/* package). 'monorepo-packages' runs only the |
| 26 | + JS build and publishes via |
| 27 | + scripts/releases-ci/publish-updated-packages.js (delta-based, |
| 28 | + gated on a #publish-packages-to-npm commit message). |
| 29 | + type: string |
| 30 | + required: true |
| 31 | + release-type: |
| 32 | + description: "For mode=react-native: release | nightly | dry-run." |
| 33 | + type: string |
| 34 | + required: false |
| 35 | + default: "dry-run" |
| 36 | + skip-apple-prebuilts: |
| 37 | + description: "For mode=react-native: skip downloading prebuilt Apple artifacts." |
| 38 | + type: boolean |
| 39 | + required: false |
| 40 | + default: false |
| 41 | + |
| 42 | +jobs: |
| 43 | + publish-react-native: |
| 44 | + if: inputs.mode == 'react-native' |
| 45 | + runs-on: 8-core-ubuntu |
| 46 | + # `id-token: write` is required so the npm CLI can mint the OIDC |
| 47 | + # token that npm Trusted Publishing exchanges for a publish token. |
| 48 | + permissions: |
| 49 | + contents: read |
| 50 | + id-token: write |
| 51 | + container: |
| 52 | + image: reactnativecommunity/react-native-android:latest |
| 53 | + env: |
| 54 | + TERM: "dumb" |
| 55 | + # Set the encoding to resolve a known character encoding issue with decompressing tar.gz files in containers |
| 56 | + # via Gradle: https://github.com/gradle/gradle/issues/23391#issuecomment-1878979127 |
| 57 | + LC_ALL: C.UTF8 |
| 58 | + GRADLE_OPTS: "-Dorg.gradle.daemon=false" |
| 59 | + # By default we only build ARM64 to save time/resources. For release/nightlies, we override this value to build all archs. |
| 60 | + ORG_GRADLE_PROJECT_reactNativeArchitectures: "arm64-v8a" |
| 61 | + REACT_NATIVE_DOWNLOADS_DIR: /opt/react-native-downloads |
| 62 | + env: |
| 63 | + ORG_GRADLE_PROJECT_SIGNING_PWD: ${{ secrets.ORG_GRADLE_PROJECT_SIGNING_PWD }} |
| 64 | + ORG_GRADLE_PROJECT_SIGNING_KEY: ${{ secrets.ORG_GRADLE_PROJECT_SIGNING_KEY }} |
| 65 | + ORG_GRADLE_PROJECT_SONATYPE_USERNAME: ${{ secrets.ORG_GRADLE_PROJECT_SONATYPE_USERNAME }} |
| 66 | + ORG_GRADLE_PROJECT_SONATYPE_PASSWORD: ${{ secrets.ORG_GRADLE_PROJECT_SONATYPE_PASSWORD }} |
| 67 | + steps: |
| 68 | + - name: Checkout |
| 69 | + uses: actions/checkout@v6 |
| 70 | + with: |
| 71 | + fetch-depth: 0 |
| 72 | + fetch-tags: true |
| 73 | + - name: Build and Publish NPM Package |
| 74 | + uses: ./.github/actions/build-npm-package |
| 75 | + with: |
| 76 | + release-type: ${{ inputs.release-type }} |
| 77 | + gradle-cache-encryption-key: ${{ secrets.GRADLE_CACHE_ENCRYPTION_KEY }} |
| 78 | + skip-apple-prebuilts: ${{ inputs.skip-apple-prebuilts && 'true' || 'false' }} |
| 79 | + |
| 80 | + publish-monorepo-packages: |
| 81 | + if: inputs.mode == 'monorepo-packages' |
| 82 | + runs-on: ubuntu-latest |
| 83 | + permissions: |
| 84 | + contents: read |
| 85 | + id-token: write |
| 86 | + steps: |
| 87 | + - name: Checkout |
| 88 | + uses: actions/checkout@v6 |
| 89 | + - name: Setup node.js |
| 90 | + uses: ./.github/actions/setup-node |
| 91 | + with: |
| 92 | + registry-url: "https://registry.npmjs.org" |
| 93 | + - name: Run Yarn Install |
| 94 | + uses: ./.github/actions/yarn-install |
| 95 | + - name: Build packages |
| 96 | + run: yarn build |
| 97 | + - name: Build types |
| 98 | + run: yarn build-types --skip-snapshot |
| 99 | + - name: Find and publish all bumped packages |
| 100 | + run: node ./scripts/releases-ci/publish-updated-packages.js |
0 commit comments