Skip to content

Commit 9b2614b

Browse files
authored
ci: add publishing workflow (#705)
## Description <!-- Provide a concise and descriptive summary of the changes implemented in this PR. --> ### Introduces a breaking change? - [ ] Yes - [ ] No ### Type of change - [ ] Bug fix (change which fixes an issue) - [ ] New feature (change which adds functionality) - [ ] Documentation update (improves or adds clarity to existing documentation) - [ ] Other (chores, tests, code style improvements etc.) ### Tested on - [ ] iOS - [ ] Android ### Testing instructions <!-- Provide step-by-step instructions on how to test your changes. Include setup details if necessary. --> ### Screenshots <!-- Add screenshots here, if applicable --> ### Related issues <!-- Link related issues here using #issue-number --> ### Checklist - [ ] I have performed a self-review of my code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation accordingly - [ ] My changes generate no new warnings ### Additional notes <!-- Include any additional information, assumptions, or context that reviewers might need to understand this PR. -->
1 parent bb27ec9 commit 9b2614b

File tree

2 files changed

+148
-0
lines changed

2 files changed

+148
-0
lines changed

.github/workflows/npm-publish.yml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
name: NPM publish
2+
3+
on:
4+
schedule:
5+
- cron: '01 00 * * *' # Every day at 00:01 UTC
6+
workflow_dispatch:
7+
inputs:
8+
latest-build:
9+
description: 'Whether to publish as a latest build'
10+
required: true
11+
type: boolean
12+
13+
permissions:
14+
id-token: write
15+
contents: read
16+
17+
concurrency:
18+
group: 'npm-executorch-package-build'
19+
cancel-in-progress: false
20+
21+
jobs:
22+
build:
23+
if: github.repository == 'software-mansion/react-native-executorch'
24+
runs-on: ubuntu-latest
25+
environment: deployment
26+
permissions:
27+
contents: read
28+
id-token: write
29+
env:
30+
EXECUTORCH_DIR: packages/react-native-executorch
31+
EXECUTORCH_VERSION: PLACEHOLDER
32+
PACKAGE_NAME: PLACEHOLDER
33+
TAG: PLACEHOLDER
34+
steps:
35+
- name: Checkout
36+
uses: actions/checkout@v4
37+
38+
- name: Setup Node
39+
uses: actions/setup-node@v4
40+
with:
41+
node-version: 22
42+
cache: 'yarn'
43+
registry-url: https://registry.npmjs.org/
44+
45+
- name: Update NPM
46+
run: npm install -g npm@latest
47+
48+
- name: Determine version
49+
working-directory: ${{ env.EXECUTORCH_DIR }}
50+
run: |
51+
VERSION=$(jq -r .version package.json)
52+
echo "EXECUTORCH_VERSION=$VERSION" >> $GITHUB_ENV
53+
54+
- name: Assert EXECUTORCH_VERSION
55+
if: ${{ env.EXECUTORCH_VERSION == 'PLACEHOLDER' }}
56+
run: exit 1 # this should never happen
57+
58+
- name: Install monorepo dependencies
59+
run: yarn install --immutable
60+
61+
- name: Set tag
62+
run: |
63+
if [[ "${{ inputs.latest-build }}" != "true" ]]; then
64+
echo "TAG=executorch-nightly" >> $GITHUB_ENV
65+
else
66+
echo "TAG=latest" >> $GITHUB_ENV
67+
fi
68+
69+
- name: Assert tag
70+
if: ${{ env.TAG == 'PLACEHOLDER' }}
71+
run: exit 1 # this should never happen
72+
73+
- name: Build package
74+
id: build
75+
working-directory: ${{ env.EXECUTORCH_DIR }}
76+
run: |
77+
if [[ "${{ inputs.latest-build }}" != "true" ]]; then
78+
./scripts/create-package.sh generate_nightly_version
79+
else
80+
./scripts/create-package.sh
81+
fi
82+
83+
- name: Check if any node_modules were packed
84+
id: check_node_modules
85+
working-directory: ${{ env.EXECUTORCH_DIR }}
86+
run: >-
87+
! grep --silent -E "node_modules/.+" build.log
88+
89+
- name: Show build log
90+
working-directory: ${{ env.EXECUTORCH_DIR }}
91+
if: failure() && steps.build.outcome == 'failure'
92+
run: cat build.log
93+
94+
- name: Show packed node_modules
95+
working-directory: ${{ env.EXECUTORCH_DIR }}
96+
if: failure() && steps.node_modules.outcome == 'failure'
97+
run: >-
98+
! grep -E "node_modules/.+" build.log
99+
100+
- name: Add package name to env
101+
working-directory: ${{ env.EXECUTORCH_DIR }}
102+
run: echo "PACKAGE_NAME=$(ls -l | egrep -o "react-native-executorch-(.*)(=?\.tgz)")" >> $GITHUB_ENV
103+
104+
- name: Assert package name
105+
if: ${{ env.PACKAGE_NAME == 'PLACEHOLDER' }}
106+
run: exit 1 # this should never happen
107+
108+
- name: Upload package to GitHub
109+
uses: actions/upload-artifact@v4
110+
with:
111+
name: ${{ env.PACKAGE_NAME }}
112+
path: ${{ env.EXECUTORCH_DIR }}/${{ env.PACKAGE_NAME }}
113+
114+
- name: Move package to monorepo root
115+
run: mv ${{ env.EXECUTORCH_DIR }}/${{ env.PACKAGE_NAME }} .
116+
117+
- name: Publish package to npm
118+
run: npm publish $PACKAGE_NAME --tag ${{ env.TAG }} --provenance
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
yarn install --immutable
4+
5+
if [ $# -ge 1 ] && [ "$1" = "generate_nightly_version" ]; then
6+
VERSION=$(jq -r '.version' package.json)
7+
IFS='.' read -r MAJOR MINOR PATCH <<<"$VERSION"
8+
GIT_COMMIT=$(git rev-parse HEAD)
9+
DATE=$(date +%Y%m%d)
10+
NIGHTLY_UNIQUE_NAME="${GIT_COMMIT:0:7}-$DATE"
11+
if [[ "$OSTYPE" == "darwin"* ]]; then
12+
sed -i '' "3s/.*/ \"version\": \"$MAJOR.$MINOR.$PATCH-nightly-$NIGHTLY_UNIQUE_NAME\",/" package.json
13+
else
14+
sed -i "3s/.*/ \"version\": \"$MAJOR.$MINOR.$PATCH-nightly-$NIGHTLY_UNIQUE_NAME\",/" package.json
15+
fi
16+
fi
17+
18+
yarn bob build
19+
20+
npm pack
21+
22+
if [ $# -ge 1 ] && [ "$1" = "generate_nightly_version" ]; then
23+
if [[ "$OSTYPE" == "darwin"* ]]; then
24+
sed -i '' "3s/.*/ \"version\": \"$MAJOR.$MINOR.$PATCH\",/" package.json
25+
else
26+
sed -i "3s/.*/ \"version\": \"$MAJOR.$MINOR.$PATCH\",/" package.json
27+
fi
28+
fi
29+
30+
echo "Done!"

0 commit comments

Comments
 (0)