Skip to content

Commit c50bf99

Browse files
committed
chore: add format tests to ci and format codebase
1 parent 75e7fe6 commit c50bf99

27 files changed

+962
-720
lines changed

.github/actions/setup/action.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: Setup
16+
description: Setup Node.js and install dependencies
17+
18+
runs:
19+
using: composite
20+
steps:
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v3
23+
with:
24+
node-version-file: .nvmrc
25+
26+
- name: Cache dependencies
27+
id: yarn-cache
28+
uses: actions/cache@v3
29+
with:
30+
path: |
31+
**/node_modules
32+
.yarn/install-state.gz
33+
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}-${{ hashFiles('**/package.json', '!node_modules/**') }}
34+
restore-keys: |
35+
${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
36+
${{ runner.os }}-yarn-
37+
38+
- name: Install dependencies
39+
if: steps.yarn-cache.outputs.cache-hit != 'true'
40+
run: yarn install --immutable
41+
shell: bash

.github/workflows/ci.yml

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: CI
16+
on:
17+
push:
18+
branches:
19+
- main
20+
pull_request:
21+
branches:
22+
- main
23+
workflow_call:
24+
25+
jobs:
26+
lint:
27+
runs-on: ubuntu-latest
28+
timeout-minutes: 30
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v4
32+
33+
- name: Setup
34+
uses: ./.github/actions/setup
35+
36+
- name: Lint files
37+
run: yarn lint
38+
39+
- name: Typecheck files
40+
run: yarn test:types
41+
42+
check-objc-formatting:
43+
runs-on: ubuntu-latest
44+
timeout-minutes: 30
45+
steps:
46+
- name: Checkout
47+
uses: actions/checkout@v4
48+
49+
- name: Install clang-format
50+
run: sudo apt-get install clang-format
51+
52+
- name: Check Objective-C formatting
53+
run: ./scripts/format-objc.sh --check
54+
55+
check-java-formatting:
56+
runs-on: ubuntu-latest
57+
timeout-minutes: 30
58+
steps:
59+
- name: Checkout
60+
uses: actions/checkout@v4
61+
62+
- name: Install JDK
63+
uses: actions/setup-java@v3
64+
with:
65+
distribution: 'zulu'
66+
java-version: '17'
67+
java-package: 'jdk'
68+
69+
- name: Download google-java-format
70+
run: |
71+
GOOGLE_JAVA_FORMAT_VERSION=1.23.0
72+
GOOGLE_JAVA_FORMAT_URL=https://github.com/google/google-java-format/releases/download/v${GOOGLE_JAVA_FORMAT_VERSION}/google-java-format-${GOOGLE_JAVA_FORMAT_VERSION}-all-deps.jar
73+
mkdir -p $HOME/google-java-format
74+
curl -L -o $HOME/google-java-format/google-java-format.jar $GOOGLE_JAVA_FORMAT_URL
75+
76+
- name: Create google-java-format wrapper script
77+
run: |
78+
cat << 'EOF' > /usr/local/bin/google-java-format
79+
#!/bin/sh
80+
exec java -jar "$HOME/google-java-format/google-java-format.jar" "$@"
81+
EOF
82+
chmod +x /usr/local/bin/google-java-format
83+
84+
- name: Check Java formatting
85+
run: ./scripts/format-java.sh --check
86+
87+
test:
88+
runs-on: ubuntu-latest
89+
timeout-minutes: 30
90+
steps:
91+
- name: Placeholder Test Step
92+
run: echo "No tests to run yet" && true
93+
# TODO: build test orchestration for Android and iOS and run detox tests on both platforms.
94+
# - name: Checkout
95+
# uses: actions/checkout@v4
96+
97+
# - name: Setup
98+
# uses: ./.github/actions/setup
99+
100+
# - name: Run unit tests
101+
# run: yarn test --maxWorkers=2 --coverage
102+
103+
build-library:
104+
runs-on: ubuntu-latest
105+
timeout-minutes: 30
106+
steps:
107+
- name: Checkout
108+
uses: actions/checkout@v4
109+
110+
- name: Setup
111+
uses: ./.github/actions/setup
112+
113+
- name: Build package
114+
run: yarn prepare
115+
116+
build-android:
117+
runs-on: ubuntu-latest
118+
timeout-minutes: 30
119+
env:
120+
TURBO_CACHE_DIR: .turbo/android
121+
steps:
122+
- name: Checkout
123+
uses: actions/checkout@v4
124+
125+
- name: Setup
126+
uses: ./.github/actions/setup
127+
128+
- name: Cache turborepo for Android
129+
uses: actions/cache@v3
130+
with:
131+
path: ${{ env.TURBO_CACHE_DIR }}
132+
key: ${{ runner.os }}-turborepo-android-${{ hashFiles('yarn.lock') }}
133+
restore-keys: |
134+
${{ runner.os }}-turborepo-android-
135+
136+
- name: Check turborepo cache for Android
137+
run: |
138+
TURBO_CACHE_STATUS=$(node -p "($(yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:android').cache.status")
139+
140+
if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
141+
echo "turbo_cache_hit=1" >> $GITHUB_ENV
142+
fi
143+
144+
- name: Install JDK
145+
if: env.turbo_cache_hit != 1
146+
uses: actions/setup-java@v3
147+
with:
148+
distribution: 'zulu'
149+
java-version: '17'
150+
java-package: 'jdk'
151+
152+
- name: Finalize Android SDK
153+
if: env.turbo_cache_hit != 1
154+
run: |
155+
/bin/bash -c "yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses > /dev/null"
156+
157+
- name: Cache Gradle
158+
if: env.turbo_cache_hit != 1
159+
uses: actions/cache@v3
160+
with:
161+
path: |
162+
~/.gradle/wrapper
163+
~/.gradle/caches
164+
key: ${{ runner.os }}-gradle-${{ hashFiles('example/android/gradle/wrapper/gradle-wrapper.properties') }}
165+
restore-keys: |
166+
${{ runner.os }}-gradle-
167+
168+
- name: Build example for Android
169+
env:
170+
JAVA_OPTS: '-Xmx4g -XX:MaxMetaspaceSize=1g'
171+
run: |
172+
echo "MAPS_API_KEY=FAKE_API_KEY" > example/android/local.properties
173+
yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}"
174+
175+
build-ios:
176+
runs-on: macos-14
177+
timeout-minutes: 45
178+
env:
179+
TURBO_CACHE_DIR: .turbo/ios
180+
steps:
181+
- name: Checkout
182+
uses: actions/checkout@v4
183+
184+
- name: Setup
185+
uses: ./.github/actions/setup
186+
187+
- name: Cache turborepo for iOS
188+
uses: actions/cache@v3
189+
with:
190+
path: ${{ env.TURBO_CACHE_DIR }}
191+
key: ${{ runner.os }}-turborepo-ios-${{ hashFiles('yarn.lock') }}
192+
restore-keys: |
193+
${{ runner.os }}-turborepo-ios-
194+
195+
- name: Check turborepo cache for iOS
196+
run: |
197+
TURBO_CACHE_STATUS=$(node -p "($(yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:ios').cache.status")
198+
199+
if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
200+
echo "turbo_cache_hit=1" >> $GITHUB_ENV
201+
else
202+
echo "turbo_cache_hit=0" >> $GITHUB_ENV
203+
fi
204+
205+
- name: Cache cocoapods
206+
if: env.turbo_cache_hit != 1
207+
id: cocoapods-cache
208+
uses: actions/cache@v3
209+
with:
210+
path: |
211+
**/ios/Pods
212+
key: ${{ runner.os }}-cocoapods-${{ hashFiles('**/package.json') }}
213+
restore-keys: |
214+
${{ runner.os }}-cocoapods-
215+
216+
- name: Install cocoapods
217+
if: env.turbo_cache_hit != 1 || steps.cocoapods-cache.outputs.cache-hit != 'true'
218+
run: |
219+
cd example/ios
220+
RCT_NEW_ARCH_ENABLED=0 pod install
221+
env:
222+
NO_FLIPPER: 1
223+
224+
- name: Copy Keys.plist file from sample
225+
run: cp example/ios/SampleApp/Keys.plist.sample example/ios/SampleApp/Keys.plist
226+
227+
- name: Build example for iOS
228+
run: |
229+
yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}"

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ This project follows
2929
- [git](https://git-scm.com) (used for source version control).
3030
- An IDE such as [Android Studio](https://developer.android.com/studio) or [Visual Studio Code](https://code.visualstudio.com/).
3131
- [addlicense](https://github.com/google/addlicense)
32+
- [google-java-format Version 1.23.0](https://github.com/google/google-java-format) (used to format Java code).
33+
- [clang-format](https://clang.llvm.org/docs/ClangFormat.html) (used to format Objective-C code).
3234

3335
## 2. Forking & cloning the repository
3436

0 commit comments

Comments
 (0)