Skip to content

Commit 2d4428f

Browse files
authored
create github action
1 parent e26be0b commit 2d4428f

1 file changed

Lines changed: 191 additions & 0 deletions

File tree

.github/workflows/main.yml

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
name: React Native CI/CD
2+
on:
3+
push:
4+
branches: [main, master]
5+
paths-ignore:
6+
- "**.md"
7+
- "LICENSE"
8+
- "docs/**"
9+
pull_request:
10+
branches: [main, master]
11+
workflow_dispatch:
12+
inputs:
13+
buildType:
14+
type: choice
15+
description: "Build type to run"
16+
options:
17+
- dev
18+
- prod-apk
19+
- all
20+
21+
env:
22+
EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }}
23+
NODE_OPTIONS: --openssl-legacy-provider
24+
25+
jobs:
26+
check-skip:
27+
runs-on: ubuntu-latest
28+
if: "!contains(github.event.head_commit.message, '[skip ci]')"
29+
steps:
30+
- name: Skip CI check
31+
run: echo "Proceeding with workflow"
32+
33+
test:
34+
needs: check-skip
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: 🏗 Checkout repository
38+
uses: actions/checkout@v4
39+
40+
- name: 🏗 Setup Node.js
41+
uses: actions/setup-node@v4
42+
with:
43+
node-version: "20"
44+
cache: "yarn"
45+
46+
- name: 📦 Get yarn cache directory path
47+
id: yarn-cache-dir-path
48+
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
49+
50+
- name: 📦 Setup yarn cache
51+
uses: actions/cache@v3
52+
with:
53+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
54+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
55+
restore-keys: |
56+
${{ runner.os }}-yarn-
57+
58+
- name: 📦 Install dependencies
59+
run: yarn install
60+
61+
- name: 🧪 Run TypeScript check
62+
run: yarn tsc
63+
64+
- name: 🧹 Run ESLint
65+
run: yarn lint
66+
67+
- name: 🎨 Run Prettier check
68+
run: yarn format:check
69+
70+
build-and-deploy:
71+
needs: test
72+
if: (github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')) || github.event_name == 'workflow_dispatch'
73+
runs-on: ubuntu-latest
74+
steps:
75+
- name: 🏗 Checkout repository
76+
uses: actions/checkout@v4
77+
78+
- name: 🏗 Setup Node.js
79+
uses: actions/setup-node@v4
80+
with:
81+
node-version: "20"
82+
cache: "yarn"
83+
84+
- name: 📦 Get yarn cache directory path
85+
id: yarn-cache-dir-path
86+
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
87+
88+
- name: 📦 Setup yarn cache
89+
uses: actions/cache@v3
90+
with:
91+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
92+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
93+
restore-keys: |
94+
${{ runner.os }}-yarn-
95+
96+
- name: 📦 Install dependencies
97+
run: |
98+
yarn install
99+
yarn global add eas-cli@latest
100+
101+
- name: 📱 Setup EAS build cache
102+
uses: actions/cache@v3
103+
with:
104+
path: ~/.eas-build-local
105+
key: ${{ runner.os }}-eas-build-local-${{ hashFiles('**/package.json') }}
106+
restore-keys: |
107+
${{ runner.os }}-eas-build-local-
108+
109+
- name: 🔄 Verify EAS CLI installation
110+
run: |
111+
echo "EAS CLI version:"
112+
eas --version
113+
114+
- name: 📋 Fix package.json main entry
115+
run: |
116+
# Check if jq is installed, if not install it
117+
if ! command -v jq &> /dev/null; then
118+
echo "Installing jq..."
119+
sudo apt-get update && sudo apt-get install -y jq
120+
fi
121+
122+
# Fix the main entry in package.json
123+
if [ -f ./package.json ]; then
124+
# Create a backup
125+
cp package.json package.json.bak
126+
# Update the package.json
127+
jq '.main = "node_modules/expo/AppEntry.js"' package.json > package.json.tmp && mv package.json.tmp package.json
128+
echo "Updated package.json main entry"
129+
cat package.json | grep "main"
130+
else
131+
echo "package.json not found"
132+
exit 1
133+
fi
134+
135+
- name: 📋 Update metro.config.js for SVG support
136+
run: |
137+
if [ -f ./metro.config.js ]; then
138+
echo "Creating backup of metro.config.js"
139+
cp ./metro.config.js ./metro.config.js.backup
140+
echo "Updating metro.config.js to CommonJS format"
141+
cat > ./metro.config.js << 'EOFMARKER'
142+
/* eslint-disable @typescript-eslint/no-var-requires */
143+
const { getDefaultConfig } = require('expo/metro-config');
144+
145+
const config = getDefaultConfig(__dirname);
146+
147+
const { transformer, resolver } = config;
148+
149+
config.transformer = {
150+
...transformer,
151+
babelTransformerPath: require.resolve('react-native-svg-transformer/expo'),
152+
};
153+
154+
config.resolver = {
155+
...resolver,
156+
assetExts: resolver.assetExts.filter(ext => ext !== 'svg'),
157+
sourceExts: [...resolver.sourceExts, 'svg'],
158+
};
159+
160+
module.exports = config;
161+
EOFMARKER
162+
echo "metro.config.js updated to CommonJS format"
163+
else
164+
echo "metro.config.js not found"
165+
fi
166+
167+
- name: 📱 Build Development APK
168+
if: github.event.inputs.buildType == 'all' || github.event.inputs.buildType == 'dev' || github.event_name == 'push'
169+
run: |
170+
# Build with increased memory limit
171+
export NODE_OPTIONS="--openssl-legacy-provider --max_old_space_size=4096"
172+
eas build --platform android --profile development --local --non-interactive --output=./app-dev.apk
173+
env:
174+
NODE_ENV: development
175+
176+
- name: 📱 Build Production APK
177+
if: github.event.inputs.buildType == 'all' || github.event.inputs.buildType == 'prod-apk' || github.event_name == 'push'
178+
run: |
179+
export NODE_OPTIONS="--openssl-legacy-provider --max_old_space_size=4096"
180+
eas build --platform android --profile production-apk --local --non-interactive --output=./app-prod.apk
181+
env:
182+
NODE_ENV: production
183+
184+
- name: 📦 Upload build artifacts to GitHub
185+
uses: actions/upload-artifact@v4
186+
with:
187+
name: app-builds
188+
path: |
189+
./app-dev.apk
190+
./app-prod.apk
191+
retention-days: 7

0 commit comments

Comments
 (0)