Skip to content

Commit ded48e5

Browse files
authored
Merge pull request #123 from retyui/github-actions-setup
Setup Github Actions
2 parents a64c322 + 762713f commit ded48e5

File tree

6 files changed

+286
-0
lines changed

6 files changed

+286
-0
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: Build App
2+
description: 'Set up your GitHub Actions workflow with a specific version of Node.js'
3+
inputs:
4+
new-arch-enabled:
5+
description: 'Enable new architecture (example: 1 or 0))'
6+
required: true
7+
8+
rn-ver:
9+
description: 'Version of React Native (example: 0.72.6))'
10+
required: true
11+
12+
arch:
13+
description: 'Architecture (example: "arm64-v8a" or "x86_64,arm64-v8a") android only'
14+
required: false
15+
default: 'armeabi-v7a,arm64-v8a,x86,x86_64'
16+
17+
module-to-install:
18+
description: 'Module to install (example: "react-native-architectures" or "file:/path/to/module"))'
19+
required: true
20+
21+
store-artifacts:
22+
description: 'Store artifacts on GitHub (example: true or false))'
23+
required: false
24+
default: 'true'
25+
26+
platform:
27+
description: 'Platform (example: android or ios))'
28+
required: true
29+
30+
31+
runs:
32+
using: 'composite'
33+
steps:
34+
- uses: ./.github/actions/lock-nodejs-ver
35+
36+
- uses: ./.github/actions/lock-java-ver
37+
if: ${{ inputs.platform == 'android' }}
38+
39+
- uses: ./.github/actions/lock-ruby-ver
40+
if: ${{ inputs.platform == 'ios' }}
41+
42+
- name: Create tmp directory
43+
shell: bash
44+
id: clear_name
45+
env:
46+
APP_NAME: Example${{ inputs.rn-ver }}${{ inputs.new-arch-enabled }}App
47+
run: |
48+
input_string="${{ env.APP_NAME }}"
49+
50+
# Remove "." and "-" symbols from the input string
51+
modified_string="${input_string//./}"
52+
modified_string="${modified_string//-/}"
53+
54+
echo "folder=${modified_string}" >> $GITHUB_OUTPUT
55+
56+
- name: Build ${{ inputs.platform }} (${{ inputs.arch }})
57+
working-directory: /tmp
58+
shell: bash
59+
id: app_build
60+
env:
61+
APP_NAME: ${{ steps.clear_name.outputs.folder }}
62+
# iOS only
63+
NO_FLIPPER: 1
64+
RCT_NEW_ARCH_ENABLED: ${{ inputs.new-arch-enabled }}
65+
run: |
66+
set -x # print all executed commands
67+
68+
# Create new tmp React Native project
69+
npx react-native@${{ inputs.rn-ver }} init ${{ env.APP_NAME }} --version ${{ inputs.rn-ver }}
70+
cd ${{ env.APP_NAME }}
71+
72+
# Install my module
73+
yarn add ${{ inputs.module-to-install }}
74+
75+
# Debug info
76+
npx react-native@${{ inputs.rn-ver }} info
77+
78+
if [[ '${{ inputs.platform }}' == 'ios' ]]; then
79+
brew install xcbeautify
80+
81+
# Update pods after adding new module
82+
npx pod-install
83+
84+
# Build iOS App
85+
xcodebuild -scheme ${{ env.APP_NAME }} -workspace ios/${{ env.APP_NAME }}.xcworkspace -configuration Release -sdk iphonesimulator -destination 'generic/platform=iOS Simulator' | xcbeautify --quiet
86+
87+
# set output variable
88+
echo "app_path=$(find ~/Library/Developer/Xcode/DerivedData -type d -name "${{ env.APP_NAME }}.app")" >> $GITHUB_OUTPUT
89+
else
90+
# Enable new arch for Android
91+
if [[ '${{ inputs.new-arch-enabled }}' == '1' ]]; then
92+
sed -i 's/newArchEnabled=false/newArchEnabled=true/' android/gradle.properties
93+
fi
94+
95+
# Build Android
96+
./android/gradlew assembleRelease --no-daemon -p android -PreactNativeArchitectures=${{ inputs.arch }}
97+
98+
# set output variable
99+
echo "app_path=$(find $(pwd)/android -type f -name '*.apk')" >> $GITHUB_OUTPUT
100+
fi
101+
102+
- name: Store Android artifacts on GitHub
103+
uses: actions/upload-artifact@v3
104+
if: ${{ inputs.store-artifacts == 'true' }}
105+
with:
106+
name: ${{ inputs.platform }}-${{ inputs.rn-ver }}-newArch${{ inputs.new-arch-enabled }}
107+
if-no-files-found: error
108+
retention-days: 14 # 2 weeks
109+
path: ${{ steps.app_build.outputs.app_path }}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Install dependencies
2+
description: 'Installs and caches Node.js dependencies using Yarn.'
3+
inputs:
4+
node-version:
5+
description: 'The Node.js version to set up'
6+
required: false
7+
8+
9+
runs:
10+
using: 'composite'
11+
steps:
12+
- uses: ./.github/actions/lock-nodejs-ver
13+
with:
14+
node-version: ${{ inputs.node-version }}
15+
16+
- name: Restore node_modules from cache
17+
uses: actions/cache/restore@v3
18+
id: restore_node_modules
19+
with:
20+
key: ${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}
21+
restore-keys: ${{ runner.os }}-yarn-
22+
path: ${{ github.workspace }}/node_modules
23+
24+
25+
- name: Install node_modules
26+
if: steps.restore_node_modules.outputs.cache-hit != 'true'
27+
shell: bash
28+
run: |
29+
# Retry 3 times before the steps actually fails
30+
(echo "===== Install node_modules Attempt: 1 ====" && yarn install --frozen-lockfile) || \
31+
(echo "===== Install node_modules Attempt: 2 ====" && yarn install --frozen-lockfile) || \
32+
(echo "===== Install node_modules Attempt: 3 ====" && yarn install --frozen-lockfile) || \
33+
(echo "===== Install node_modules Step Failed ====" && exit 1)
34+
35+
36+
- name: Save node_modules to cache
37+
if: steps.restore_node_modules.outputs.cache-hit != 'true'
38+
uses: actions/cache/save@v3
39+
with:
40+
key: ${{ steps.restore_node_modules.outputs.cache-primary-key }}
41+
path: ${{ github.workspace }}/node_modules
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Setup Java
2+
description: 'Set up your GitHub Actions workflow with a specific version of Java'
3+
inputs:
4+
java-version:
5+
description: 'The Java version to set up'
6+
required: false
7+
default: 17
8+
9+
runs:
10+
using: 'composite'
11+
steps:
12+
- name: Setup Java ${{ inputs.java-version }}
13+
uses: actions/setup-java@v3
14+
with:
15+
distribution: 'temurin'
16+
java-version: ${{ inputs.java-version }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Setup Node.js
2+
description: 'Set up your GitHub Actions workflow with a specific version of Node.js'
3+
inputs:
4+
node-version:
5+
description: 'The Node.js version to set up'
6+
required: false
7+
default: 18
8+
9+
runs:
10+
using: 'composite'
11+
steps:
12+
- name: Setup Node.js ${{ inputs.node-version }}
13+
uses: actions/setup-node@v3
14+
with:
15+
node-version: ${{ inputs.node-version }}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Setup Ruby
2+
description: 'Set up your GitHub Actions workflow with a specific version of Ruby'
3+
inputs:
4+
ruby-version:
5+
description: 'The Ruby version to set up'
6+
required: false
7+
default: 3.0
8+
9+
runs:
10+
using: 'composite'
11+
steps:
12+
- name: Setup Ruby
13+
uses: ruby/setup-ruby@v1
14+
with:
15+
ruby-version: ${{ inputs.ruby-version }}
16+
bundler-cache: true

.github/workflows/main.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Main
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
push:
8+
branches:
9+
- master
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
env:
16+
ACTIONS_RUNNER_DEBUG: true # Enable debug logs
17+
18+
jobs:
19+
cache-node-modules:
20+
name: Cache node_modules
21+
runs-on: ubuntu-22.04
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v3
25+
with:
26+
fetch-depth: 0
27+
- uses: ./.github/actions/install-dependencies
28+
29+
code-quality:
30+
name: Code Quality
31+
runs-on: ubuntu-22.04
32+
needs: [cache-node-modules]
33+
steps:
34+
- name: Checkout repository
35+
uses: actions/checkout@v3
36+
with:
37+
fetch-depth: 0
38+
- uses: ./.github/actions/install-dependencies
39+
40+
- name: Lint files
41+
run: yarn run test:eslint
42+
43+
- name: Flow files
44+
run: yarn run test:flow
45+
46+
build-android:
47+
name: Build Android
48+
runs-on: ubuntu-22.04
49+
strategy:
50+
fail-fast: false
51+
max-parallel: 4
52+
matrix:
53+
new_arch_enabled: [ 1, 0 ]
54+
rn_ver: [latest ] # also, can be any npm tag: 0.71-stable, next, nightly
55+
steps:
56+
- name: Checkout repository
57+
uses: actions/checkout@v3
58+
with:
59+
fetch-depth: 0
60+
- uses: ./.github/actions/build-app
61+
with:
62+
arch: arm64-v8a
63+
new-arch-enabled: ${{ matrix.new_arch_enabled }}
64+
rn-ver: ${{ matrix.rn_ver }}
65+
module-to-install: file:${{ github.workspace }}
66+
store-artifacts: true
67+
platform: android
68+
69+
build-ios:
70+
name: Build iOS
71+
runs-on: macos-13
72+
strategy:
73+
fail-fast: false
74+
max-parallel: 3
75+
matrix:
76+
new_arch_enabled: [ 1, 0 ]
77+
rn_ver: [latest ] # also, can be any npm tag: 0.71-stable, next, nightly
78+
steps:
79+
- name: Checkout repository
80+
uses: actions/checkout@v3
81+
with:
82+
fetch-depth: 0
83+
- uses: ./.github/actions/build-app
84+
with:
85+
new-arch-enabled: ${{ matrix.new_arch_enabled }}
86+
rn-ver: ${{ matrix.rn_ver }}
87+
module-to-install: file:${{ github.workspace }}
88+
store-artifacts: true
89+
platform: ios

0 commit comments

Comments
 (0)