-
Notifications
You must be signed in to change notification settings - Fork 0
[RN][CI] add React Native release publishing flow #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
kieran-osgood-shopify
wants to merge
3
commits into
main
Choose a base branch
from
kieran-osgood/release-workflow/react-native-publish
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| const fs = require("node:fs"); | ||
|
|
||
| const file = process.argv[2]; | ||
|
|
||
| if (!file) { | ||
| console.error("Usage: package-json-version <package.json>"); | ||
| process.exit(2); | ||
| } | ||
|
|
||
| if (!fs.existsSync(file)) { | ||
| console.error(`::error file=${file}::Version source file does not exist.`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| let pkg; | ||
| try { | ||
| pkg = JSON.parse(fs.readFileSync(file, "utf8")); | ||
| } catch (error) { | ||
| console.error(`::error file=${file}::Could not parse JSON: ${error.message}`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| if (typeof pkg.version !== "string" || pkg.version.length === 0) { | ||
| console.error(`::error file=${file}::Could not extract version.`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| process.stdout.write(pkg.version); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| name: React Native — Publish to npm | ||
|
|
||
| on: | ||
| release: | ||
| types: | ||
| - published | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
|
|
||
| concurrency: | ||
| group: react-native-publish | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| release: | ||
| name: Publish @shopify/checkout-kit-react-native to npm | ||
| if: | | ||
| (github.event_name == 'release' && startsWith(github.event.release.tag_name, 'react-native/')) | ||
| || github.event_name == 'workflow_dispatch' | ||
| environment: | ||
| name: npm-react-native | ||
| url: https://www.npmjs.com/package/@shopify/checkout-kit-react-native | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 15 | ||
| defaults: | ||
| run: | ||
| working-directory: platforms/react-native | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
|
|
||
| - name: Validate release tag matches package.json version | ||
| id: release | ||
| working-directory: ${{ github.workspace }} | ||
| env: | ||
| RELEASE_TAG: ${{ github.event.release.tag_name }} | ||
| run: | | ||
| set -euo pipefail | ||
| if [ "$GITHUB_EVENT_NAME" = "release" ]; then | ||
| TAG="$RELEASE_TAG" | ||
| else | ||
| TAG="$GITHUB_REF_NAME" | ||
| fi | ||
|
|
||
| .github/scripts/validate-release-version "React Native" "" "$TAG" >> "$GITHUB_OUTPUT" | ||
|
|
||
| # `ignore-scripts` prevents dependency postinstall scripts from running in | ||
| # this privileged npm publishing job. | ||
| - name: Setup Node.js, pnpm, and install dependencies | ||
| uses: ./.github/actions/setup | ||
| with: | ||
| node-version-file: platforms/react-native/package.json | ||
| cache-dependency-path: platforms/react-native/pnpm-lock.yaml | ||
| package-json-file: platforms/react-native/package.json | ||
| working-directory: platforms/react-native | ||
| ignore-scripts: "true" | ||
|
|
||
| - name: Verify version is not already published | ||
| run: | | ||
| set -euo pipefail | ||
| NAME=$(node -p "require('./modules/@shopify/checkout-kit-react-native/package.json').name") | ||
| VERSION=$(node -p "require('./modules/@shopify/checkout-kit-react-native/package.json').version") | ||
| ENCODED_NAME=$(node -p "encodeURIComponent(require('./modules/@shopify/checkout-kit-react-native/package.json').name)") | ||
| URL="https://registry.npmjs.org/${ENCODED_NAME}/${VERSION}" | ||
| if curl -fs "$URL" > /dev/null; then | ||
| echo "::error::${NAME}@${VERSION} is already published on npm. Bump platforms/react-native/modules/@shopify/checkout-kit-react-native/package.json before re-running." | ||
| exit 1 | ||
| fi | ||
| echo "::notice::${NAME}@${VERSION} is not yet on npm — safe to proceed." | ||
|
|
||
| - name: Build package | ||
| run: | | ||
| set -euo pipefail | ||
| cp README.md modules/@shopify/checkout-kit-react-native/README.md | ||
| pnpm module clean | ||
| pnpm module build | ||
|
|
||
| - name: Pack and inspect contents | ||
| run: | | ||
| set -euo pipefail | ||
| mkdir -p /tmp/react-native-publish | ||
| cd modules/@shopify/checkout-kit-react-native | ||
| pnpm pack --dry-run | ||
| pnpm pack --pack-destination /tmp/react-native-publish | ||
| echo "Tarball contents:" | ||
| tar -tzf /tmp/react-native-publish/*.tgz | sort | ||
|
|
||
| - name: Verify packed manifest has no workspace dependencies | ||
| run: | | ||
| set -euo pipefail | ||
| tar -xOf /tmp/react-native-publish/*.tgz package/package.json > /tmp/react-native-publish/package.json | ||
| node <<'NODE' | ||
| const pkg = require('/tmp/react-native-publish/package.json'); | ||
| const sections = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']; | ||
| const workspaceDependencies = []; | ||
| for (const section of sections) { | ||
| for (const [name, version] of Object.entries(pkg[section] ?? {})) { | ||
| if (typeof version === 'string' && version.startsWith('workspace:')) { | ||
| workspaceDependencies.push(`${section}.${name}=${version}`); | ||
| } | ||
| } | ||
| } | ||
| if (workspaceDependencies.length > 0) { | ||
| console.error(`::error::Packed package still contains workspace dependencies: ${workspaceDependencies.join(', ')}`); | ||
| process.exit(1); | ||
| } | ||
| console.log('Packed package manifest has no workspace: dependencies.'); | ||
| NODE | ||
|
|
||
| - name: Print npm auth mode | ||
| env: | ||
| NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| run: | | ||
| set -euo pipefail | ||
| if [ -n "${NPM_TOKEN:-}" ]; then | ||
| echo "::notice::NPM_TOKEN is present — bootstrap/token publish path will be used." | ||
| pnpm whoami | ||
| else | ||
| echo "::notice::NPM_TOKEN is not present — relying on npm trusted publishing/OIDC." | ||
| fi | ||
|
|
||
| - name: Publish to npm | ||
| run: | | ||
| set -euo pipefail | ||
| cd modules/@shopify/checkout-kit-react-native | ||
| pnpm publish --no-git-checks --ignore-scripts --access public --tag "$NPM_TAG" --provenance | ||
| env: | ||
| NPM_TAG: ${{ steps.release.outputs.npm_tag }} | ||
| NPM_CONFIG_PROVENANCE: "true" | ||
| NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this matches what the web workflow does too