Skip to content

Commit dfcfd77

Browse files
authored
tools: add __scripts__/generate-example.js (#68)
* tools: add __scripts__/generate-example.js * tools: reuse __scripts__/generate-example.js in ci * chore: add verbose, refactor 'clean' PATH logic
1 parent e4df66f commit dfcfd77

6 files changed

Lines changed: 265 additions & 99 deletions

File tree

.github/workflows/tests.yaml

Lines changed: 36 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,36 @@ on:
99
schedule:
1010
- cron: '0 0 * * 0' # https://crontab.guru/every-week
1111

12-
env:
13-
TEST_APP_DEPS: react-native-modal react-native-webview
14-
TEST_APP_DEV_DEPS: typescript @babel/preset-env react-shallow-renderer
15-
RN_BUNDLE_ARGS: --entry-file index.js --platform android --dev false --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
16-
1712
jobs:
1813
build:
1914
runs-on: ubuntu-latest
2015
steps:
2116
- uses: actions/checkout@v4
2217
- run: npm install
2318
- run: npm test
24-
test-yarn:
19+
20+
test:
2521
needs: build
26-
runs-on: ubuntu-latest
22+
runs-on: ${{ matrix.os }}
2723
outputs:
2824
rn-version: ${{ steps.rn-version.outputs.value }}
25+
concurrency:
26+
group: '${{ github.workflow }}-${{ matrix.platform }}-${{ matrix.pm }}-${{ github.head_ref || github.ref_name }}'
27+
cancel-in-progress: true
28+
strategy:
29+
fail-fast: false
30+
max-parallel: 5
31+
matrix:
32+
os: [ ubuntu-latest ]
33+
platform: [ android ]
34+
pm: [ npm, yarn ]
35+
include:
36+
- os: macos-latest
37+
platform: ios
38+
pm: npm
39+
- os: macos-latest
40+
platform: ios
41+
pm: yarn
2942
steps:
3043
- uses: actions/checkout@v4
3144
with:
@@ -34,85 +47,32 @@ jobs:
3447
with:
3548
java-version: 17
3649
distribution: adopt
37-
- run: npx react-native init rnexample
50+
- run: |
51+
# npm install -g ${{ matrix.pm }} react-native
52+
npm run example -- --pm ${{ matrix.pm }}
53+
working-directory: react-native-hcaptcha
3854
- id: rn-version
39-
working-directory: rnexample
55+
working-directory: react-native-hcaptcha-example
4056
run: |
4157
RN_VERSION=$(cat package.json | jq ".dependencies.\"react-native\"" -r)
4258
echo "value=${RN_VERSION}" >> $GITHUB_OUTPUT
43-
- name: Run yarn add ...
44-
working-directory: rnexample
45-
run: |
46-
yarn add @hcaptcha/react-native-hcaptcha@file:../react-native-hcaptcha
47-
yarn add --dev ${{ env.TEST_APP_DEV_DEPS }}
48-
yarn add ${{ env.TEST_APP_DEPS }}
49-
cp ../react-native-hcaptcha/Example.App.js App.js
50-
cp ../react-native-hcaptcha/Example.jest.config.js jest.config.js
51-
- run: |
52-
mkdir -p android/app/src/main/assets
53-
mkdir -p android/app/src/main/res
54-
yarn react-native bundle ${{ env.RN_BUNDLE_ARGS }}
55-
working-directory: rnexample
5659
- run: cat package.json
57-
working-directory: rnexample
60+
working-directory: react-native-hcaptcha-example
5861
- run: yarn test --config ./jest.config.js
59-
working-directory: rnexample
62+
working-directory: react-native-hcaptcha-example
63+
- run: npx react-native build-${{ matrix.platform }}
64+
working-directory: react-native-hcaptcha-example
6065
- run: npx --yes check-peer-dependencies --yarn --runOnlyOnRootDependencies
61-
working-directory: rnexample
62-
test-npm:
63-
needs: build
64-
runs-on: ubuntu-latest
65-
outputs:
66-
rn-version: ${{ steps.rn-version.outputs.value }}
67-
steps:
68-
- uses: actions/setup-java@v4
69-
with:
70-
java-version: 17
71-
distribution: adopt
72-
- run: npx react-native init rnexample
73-
- id: rn-version
74-
working-directory: rnexample
75-
run: |
76-
RN_VERSION=$(cat package.json | jq ".dependencies.\"react-native\"" -r)
77-
echo "value=${RN_VERSION}" >> $GITHUB_OUTPUT
78-
- uses: actions/checkout@v4
79-
with:
80-
path: rnexample/react-native-hcaptcha
81-
- name: Run npm install ...
82-
working-directory: rnexample
83-
run: |
84-
npm i --save file:./react-native-hcaptcha
85-
npm i --save --include=dev ${{ env.TEST_APP_DEV_DEPS }}
86-
npm i --save ${{ env.TEST_APP_DEPS }}
87-
cp ./react-native-hcaptcha/Example.App.js App.js
88-
cp ./react-native-hcaptcha/Example.jest.config.js jest.config.js
89-
- run: |
90-
mkdir -p android/app/src/main/assets
91-
mkdir -p android/app/src/main/res
92-
npx react-native bundle ${{ env.RN_BUNDLE_ARGS }}
93-
working-directory: rnexample
94-
- run: cat package.json
95-
working-directory: rnexample
96-
- run: npm run test -- --config ./jest.config.js
97-
working-directory: rnexample
98-
- run: npx --yes check-peer-dependencies --npm --runOnlyOnRootDependencies
99-
working-directory: rnexample
100-
- run: |
101-
echo "org.gradle.jvmargs=-Xmx4096m -XX:MaxMetaspaceSize=1024m" >> gradle.properties
102-
./gradlew assemble
103-
working-directory: rnexample/android
104-
- uses: actions/upload-artifact@v4
105-
with:
106-
name: apks
107-
path: rnexample/android/app/build/outputs/apk/release/app-release.apk
66+
working-directory: react-native-hcaptcha-example
67+
10868
create-an-issue:
10969
runs-on: ubuntu-latest
110-
needs: [test-npm, test-yarn]
111-
if: always() && github.event == 'schedule' && (needs.test-npm.result == 'failure' || needs.test-yarn.result == 'failure')
70+
needs: test
71+
if: always() && github.event == 'schedule' && needs.test.result == 'failure'
11272
steps:
11373
- uses: actions/checkout@v4
11474
- run: |
115-
RN_VERSION="${{ needs.test-npm.outputs.rn-version || needs.test-yarn.outputs.rn-version }}"
75+
RN_VERSION="${{ needs.test.outputs.rn-version }}"
11676
GHA_RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
11777
echo "RN_VERSION=${RN_VERSION}" >> $GITHUB_ENV
11878
echo "GHA_RUN_URL=${GHA_RUN_URL}" >> $GITHUB_ENV
@@ -123,9 +83,10 @@ jobs:
12383
assignees: CAMOBAP
12484
update_existing: true
12585
filename: .github/examples-issue-template.md
86+
12687
release:
12788
if: github.event_name == 'release'
128-
needs: [test-npm, test-yarn]
89+
needs: test
12990
runs-on: ubuntu-latest
13091
steps:
13192
- uses: actions/checkout@v4

Example.jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ module.exports = {
1212
+ "|react-native-animatable"
1313
+ ")/)",
1414
],
15+
setupFiles: ['./jest.setup.js'],
1516
}

Example.jest.setup.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
jest.mock('react-native-webview', () => {
2+
return {
3+
WebView: () => 'WebView',
4+
};
5+
});
6+

MAINTAINER.md

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,20 @@ PATCH: bugfix only.
2323

2424
For `expo` test app
2525

26-
- `cd ..`
27-
- `expo init expo-example -t blank`
28-
- `cd expo-example`
29-
- `yarn add file:../react-native-hcaptcha`
30-
- `yarn add react-native-modal react-native-webview`
31-
- `cp ../react-native-hcaptcha/Example.App.js App.js`
32-
- `yarn android`
26+
- `cd react-native-hcaptcha`
27+
- `yarn example --expo
28+
- `yarn android` or `npm run android`
3329

3430
For `react-native` test app
3531

36-
- `cd ..`
37-
- `react-native init rnexample` or `react-native init rnexample --version 0.63.4` for specific version
38-
- `cd rnexample`
39-
- `yarn add file:../react-native-hcaptcha`
40-
- `yarn add react-native-modal react-native-webview`
41-
- `cp ../react-native-hcaptcha/Example.App.js App.js`
42-
- `yarn android`
32+
- `cd react-native-hcaptcha`
33+
- `yarn example`
34+
- `yarn android` or `npm run android`
4335

4436
For iOS instead the last step do:
4537

46-
- `pushd ios; pod install; popd`
47-
- `yarn ios`
48-
49-
To quickly update `react-native-hcaptcha` locally just run:
50-
51-
`yarn upgrade file:../react-native-hcaptcha`
52-
38+
- `pushd ios; env USE_HERMES=0 pod install; popd`
39+
- `yarn ios` or `npm run ios`
5340

5441
### Known issues
5542

@@ -145,4 +132,27 @@ ERROR Invariant Violation: No callback found with cbID xxxxx and callID yyyyy
145132

146133
Solution: delete `node_modules` in `react-native-hcaptcha`.
147134

148-
This issue is related to mismatched `react-native` versions in the test app vs. `react-native-hcaptcha`
135+
This issue is related to mismatched `react-native` versions in the test app vs. `react-native-hcaptcha`
136+
137+
---
138+
139+
Problem:
140+
141+
Xcode failed to build with:
142+
143+
> ...
144+
> Framework 'hermes' not found
145+
146+
Solution: `env USE_HERMES=0 pod install` or add `:hermes_enabled => false` into `use_react_native!` call in `ios/Podfile`
147+
148+
---
149+
150+
Problem:
151+
```
152+
> yarn add file:../react-native-hcaptcha
153+
Usage Error: The file:../react-native-hcaptcha string didn't match the required format (package-name@range). Did you perhaps forget to explicitly reference the package name?
154+
```
155+
156+
Solution: `yarn add @hcaptcha/react-native-hcaptcha@file:../react-native-hcaptcha`
157+
158+
Yarn 2.10.x and above doesn't require `file:` scheme prefix https://stackoverflow.com/questions/40102686/how-to-install-package-with-local-path-by-yarn-it-couldnt-find-package

0 commit comments

Comments
 (0)