Add React Native CI/CD workflow for automated builds and releases #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: React Native CI/CD | ||
| on: | ||
| # workflow_dispatch: | ||
| # inputs: | ||
| # buildType: | ||
| # type: choice | ||
| # description: "Build type to run" | ||
| # options: | ||
| # - dev | ||
| # - prod-apk | ||
| # - prod-aab | ||
| # - ios-dev | ||
| # - ios-prod | ||
| # - publish-expo | ||
| # - publish-stores | ||
| # - all | ||
| # platform: | ||
| # type: choice | ||
| # description: "Platform to build" | ||
| # default: "all" | ||
| # options: | ||
| # - android | ||
| # - ios | ||
| # - all | ||
| workflow_call: | ||
| secrets: | ||
| EXPO_TOKEN: | ||
| required: true | ||
| EXPO_APPLE_ID: | ||
| required: true | ||
| EXPO_APPLE_PASSWORD: | ||
| required: true | ||
| EXPO_TEAM_ID: | ||
| required: true | ||
| GOOGLE_PLAY_SERVICE_ACCOUNT: | ||
| required: false | ||
| SLACK_WEBHOOK: | ||
| required: false | ||
| DISCORD_WEBHOOK: | ||
| required: false | ||
| GITHUB_TOKEN: | ||
| required: true | ||
| env: | ||
| EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }} | ||
| EXPO_APPLE_ID: ${{ secrets.EXPO_APPLE_ID }} | ||
| EXPO_APPLE_PASSWORD: ${{ secrets.EXPO_APPLE_PASSWORD }} | ||
| EXPO_TEAM_ID: ${{ secrets.EXPO_TEAM_ID }} | ||
| # GOOGLE_PLAY_SERVICE_ACCOUNT: ${{ secrets.GOOGLE_PLAY_SERVICE_ACCOUNT }} | ||
| SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | ||
| # DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} | ||
| NODE_OPTIONS: --openssl-legacy-provider | ||
| jobs: | ||
| check-skip: | ||
| runs-on: ubuntu-latest | ||
| if: "!contains(github.event.head_commit.message, '[skip ci]')" | ||
| steps: | ||
| - name: Skip CI check | ||
| run: echo "Proceeding with workflow" | ||
| test: | ||
| needs: check-skip | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: 🏗 Checkout repository | ||
| uses: actions/checkout@v4 | ||
| - name: 🏗 Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: "20" | ||
| cache: "yarn" | ||
| - name: 📦 Get yarn cache directory path | ||
| id: yarn-cache-dir-path | ||
| run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT | ||
| - name: 📦 Setup yarn cache | ||
| uses: actions/cache@v3 | ||
| with: | ||
| path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | ||
| key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-yarn- | ||
| - name: 📦 Install dependencies | ||
| run: yarn install | ||
| - name: 🧹 Run ESLint | ||
| run: yarn lint | ||
| - name: 📢 Notify test results | ||
| if: always() | ||
| uses: rtCamp/action-slack-notify@v2 | ||
| env: | ||
| SLACK_WEBHOOK: ${{ env.SLACK_WEBHOOK }} | ||
| SLACK_COLOR: ${{ job.status == 'success' && 'good' || 'danger' }} | ||
| SLACK_TITLE: Test Results | ||
| SLACK_MESSAGE: "Tests ${{ job.status == 'success' && 'passed ✅' || 'failed ❌' }}" | ||
| build-and-release: | ||
| needs: test | ||
| if: (github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')) || github.event_name == 'workflow_dispatch' | ||
| strategy: | ||
| matrix: | ||
| platform: [android] | ||
| include: | ||
| - platform: ios | ||
| runs-on: macos-latest | ||
| runs-on: ${{ matrix.platform == 'ios' && 'macos-latest' || 'ubuntu-latest' }} | ||
| steps: | ||
| - name: 🏗 Checkout repository | ||
| uses: actions/checkout@v4 | ||
| - name: 🏗 Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: "20" | ||
| cache: "yarn" | ||
| - name: 📦 Get yarn cache directory path | ||
| id: yarn-cache-dir-path | ||
| run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT | ||
| - name: 📦 Setup yarn cache | ||
| uses: actions/cache@v3 | ||
| with: | ||
| path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | ||
| key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-yarn- | ||
| - name: 📦 Install dependencies | ||
| run: | | ||
| yarn install | ||
| yarn global add eas-cli@latest | ||
| - name: 📱 Setup EAS build cache | ||
| uses: actions/cache@v3 | ||
| with: | ||
| path: ~/.eas-build-local | ||
| key: ${{ runner.os }}-eas-build-local-${{ hashFiles('**/package.json') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-eas-build-local- | ||
| - name: 🔄 Verify EAS CLI installation | ||
| run: | | ||
| echo "EAS CLI version:" | ||
| eas --version | ||
| - name: 📋 Fix package.json main entry | ||
| run: | | ||
| # Check if jq is installed, if not install it | ||
| if ! command -v jq &> /dev/null; then | ||
| echo "Installing jq..." | ||
| sudo apt-get update && sudo apt-get install -y jq | ||
| fi | ||
| # Fix the main entry in package.json | ||
| if [ -f ./package.json ]; then | ||
| # Create a backup | ||
| cp package.json package.json.bak | ||
| # Update the package.json | ||
| jq '.main = "node_modules/expo/AppEntry.js"' package.json > package.json.tmp && mv package.json.tmp package.json | ||
| echo "Updated package.json main entry" | ||
| cat package.json | grep "main" | ||
| else | ||
| echo "package.json not found" | ||
| exit 1 | ||
| fi | ||
| - name: 📋 Update metro.config.js for SVG support | ||
| run: | | ||
| if [ -f ./metro.config.js ]; then | ||
| echo "Creating backup of metro.config.js" | ||
| cp ./metro.config.js ./metro.config.js.backup | ||
| echo "Updating metro.config.js to CommonJS format" | ||
| cat > ./metro.config.js << 'EOFMARKER' | ||
| /* eslint-disable @typescript-eslint/no-var-requires */ | ||
| const { getDefaultConfig } = require('expo/metro-config'); | ||
| const config = getDefaultConfig(__dirname); | ||
| const { transformer, resolver } = config; | ||
| config.transformer = { | ||
| ...transformer, | ||
| babelTransformerPath: require.resolve('react-native-svg-transformer/expo'), | ||
| }; | ||
| config.resolver = { | ||
| ...resolver, | ||
| assetExts: resolver.assetExts.filter(ext => ext !== 'svg'), | ||
| sourceExts: [...resolver.sourceExts, 'svg'], | ||
| }; | ||
| module.exports = config; | ||
| EOFMARKER | ||
| echo "metro.config.js updated to CommonJS format" | ||
| else | ||
| echo "metro.config.js not found" | ||
| fi | ||
| - name: 📱 Build Development APK | ||
| if: github.event.inputs.buildType == 'all' || github.event.inputs.buildType == 'dev' || github.event_name == 'push' && (matrix.platform == 'android' || github.event.inputs.platform == 'all' || github.event.inputs.platform == 'android') | ||
| run: | | ||
| # Build with increased memory limit | ||
| export NODE_OPTIONS="--openssl-legacy-provider --max_old_space_size=4096" | ||
| eas build --platform android --profile development --local --non-interactive --output=./app-dev.apk | ||
| env: | ||
| NODE_ENV: development | ||
| - name: 📱 Build Production APK | ||
| if: github.event.inputs.buildType == 'all' || github.event.inputs.buildType == 'prod-apk' || github.event_name == 'push' && (matrix.platform == 'android' || github.event.inputs.platform == 'all' || github.event.inputs.platform == 'android') | ||
| run: | | ||
| export NODE_OPTIONS="--openssl-legacy-provider --max_old_space_size=4096" | ||
| eas build --platform android --profile production-apk --local --non-interactive --output=./app-prod.apk | ||
| env: | ||
| NODE_ENV: production | ||
| - name: 📱 Build Production AAB | ||
| if: github.event.inputs.buildType == 'all' || github.event.inputs.buildType == 'prod-aab' || github.event_name == 'push' && (matrix.platform == 'android' || github.event.inputs.platform == 'all' || github.event.inputs.platform == 'android') | ||
| run: | | ||
| export NODE_OPTIONS="--openssl-legacy-provider --max_old_space_size=4096" | ||
| eas build --platform android --profile production --local --non-interactive --output=./app-prod.aab | ||
| env: | ||
| NODE_ENV: production | ||
| - name: 📱 Build iOS Development | ||
| if: (github.event.inputs.buildType == 'all' || github.event.inputs.buildType == 'ios-dev') && (matrix.platform == 'ios' || github.event.inputs.platform == 'all' || github.event.inputs.platform == 'ios') | ||
| run: | | ||
| export NODE_OPTIONS="--openssl-legacy-provider --max_old_space_size=4096" | ||
| eas build --platform ios --profile development --local --non-interactive --output=./app-ios-dev.app | ||
| env: | ||
| NODE_ENV: development | ||
| - name: 📱 Build iOS Production | ||
| if: (github.event.inputs.buildType == 'all' || github.event.inputs.buildType == 'ios-prod') && (matrix.platform == 'ios' || github.event.inputs.platform == 'all' || github.event.inputs.platform == 'ios') | ||
| run: | | ||
| export NODE_OPTIONS="--openssl-legacy-provider --max_old_space_size=4096" | ||
| eas build --platform ios --profile production --local --non-interactive --output=./app-ios-prod.ipa | ||
| env: | ||
| NODE_ENV: production | ||
| - name: 🚀 Publish to Expo | ||
| if: github.event.inputs.buildType == 'all' || github.event.inputs.buildType == 'publish-expo' | ||
| run: | | ||
| eas update --auto | ||
| env: | ||
| EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }} | ||
| # - name: 🚀 Submit to Play Store | ||
| # if: (github.event.inputs.buildType == 'all' || github.event.inputs.buildType == 'publish-stores') && (matrix.platform == 'android' || github.event.inputs.platform == 'all' || github.event.inputs.platform == 'android') | ||
| # run: | | ||
| # eas submit -p android --path ./app-prod.aab --non-interactive | ||
| # env: | ||
| # EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }} | ||
| # GOOGLE_PLAY_SERVICE_ACCOUNT: ${{ secrets.GOOGLE_PLAY_SERVICE_ACCOUNT }} | ||
| # - name: 🚀 Submit to App Store | ||
| # if: (github.event.inputs.buildType == 'all' || github.event.inputs.buildType == 'publish-stores') && (matrix.platform == 'ios' || github.event.inputs.platform == 'all' || github.event.inputs.platform == 'ios') | ||
| # run: | | ||
| # eas submit -p ios --path ./app-ios-prod.ipa --non-interactive | ||
| # env: | ||
| # EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }} | ||
| # EXPO_APPLE_ID: ${{ secrets.EXPO_APPLE_ID }} | ||
| # EXPO_APPLE_PASSWORD: ${{ secrets.EXPO_APPLE_PASSWORD }} | ||
| # EXPO_TEAM_ID: ${{ secrets.EXPO_TEAM_ID }} | ||
| - name: 🏷️ Generate build information | ||
| id: build-info | ||
| run: | | ||
| VERSION=$(node -p "require('./app.json').expo.version") | ||
| BUILD_NUMBER=$(date +%Y%m%d%H%M) | ||
| echo "version=$VERSION" >> $GITHUB_OUTPUT | ||
| echo "build_number=$BUILD_NUMBER" >> $GITHUB_OUTPUT | ||
| # Generate changelog from commit messages since last tag | ||
| if git describe --tags --abbrev=0 > /dev/null 2>&1; then | ||
| LAST_TAG=$(git describe --tags --abbrev=0) | ||
| git log $LAST_TAG..HEAD --pretty=format:"- %s" > changelog.md | ||
| else | ||
| git log --pretty=format:"- %s" -n 10 > changelog.md | ||
| fi | ||
| - name: 📝 Create GitHub Release | ||
| uses: softprops/action-gh-release@v1 | ||
| with: | ||
| draft: true | ||
| name: "Release v${{ steps.build-info.outputs.version }}-${{ steps.build-info.outputs.build_number }}" | ||
| tag_name: "v${{ steps.build-info.outputs.version }}-${{ steps.build-info.outputs.build_number }}" | ||
| files: | | ||
| ./app-dev.apk | ||
| ./app-prod.apk | ||
| ./app-prod.aab | ||
| ./app-ios-dev.app | ||
| ./app-ios-prod.ipa | ||
| body_path: changelog.md | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: 📦 Upload build artifacts to GitHub | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: app-builds | ||
| path: | | ||
| ./app-dev.apk | ||
| ./app-prod.apk | ||
| ./app-prod.aab | ||
| ./app-ios-dev.app | ||
| ./app-ios-prod.ipa | ||
| retention-days: 7 | ||
| - name: 📢 Notify build completion | ||
| if: always() | ||
| uses: rtCamp/action-slack-notify@v2 | ||
| env: | ||
| SLACK_WEBHOOK: ${{ env.SLACK_WEBHOOK }} | ||
| SLACK_COLOR: ${{ job.status == 'success' && 'good' || 'danger' }} | ||
| SLACK_TITLE: Build Results | ||
| SLACK_MESSAGE: "Build ${{ job.status == 'success' && 'completed successfully ✅' || 'failed ❌' }}" | ||