Skip to content

Commit

Permalink
Added additional workflows
Browse files Browse the repository at this point in the history
Added checks for iOS and Android builds
Added scripts for incrementing build numbers/versions
  • Loading branch information
Alex Risch authored and Alex Risch committed Jul 24, 2024
1 parent 11a8282 commit c005474
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ on:
# - "ios/**"
# - "android/**"
# - "package.json"
schedule:
# These will run only on the default branch
- cron: "0 18 * * 2" # Tuesdays at 11 AM PT
- cron: "0 23 * * 4" # Thursdays at 4 PM PT
workflow_dispatch:

jobs:
build-android:
Expand Down Expand Up @@ -61,3 +66,46 @@ jobs:

- name: Build for iOS
run: eas build --profile production-ios --platform ios --non-interactive

increment-build-numbers:
runs-on: ubuntu-latest
needs: [build-android, build-ios]

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: "18"

- name: Increment version numbers
run: node scripts/build/incrementBuildNumbers.js

- name: Commit changes
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add app.json
git commit -m "Increment version numbers"
- name: Push changes
run: git push origin HEAD:increment-version

create-pull-request:
runs-on: ubuntu-latest
needs: increment-build-numbers

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: increment-version
title: "Increment version numbers"
body: "This PR increments the buildNumber for iOS and the versionCode for Android."
base: feat/xmtp-groups-dash # Change the base branch if needed
51 changes: 51 additions & 0 deletions .github/workflows/check-android-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Android App APK Build

on:
pull_request:
branches:
- feat/xmtp-groups-dash
# Uncomment after verification
# paths:
# - "android/**"
# - "package.json"

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Setup repo
uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v4.0.2
with:
node-version: 18.x
cache: "yarn"

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: "17"
distribution: "temurin"

- name: Setup Android SDK
uses: android-actions/setup-android@v3

- name: Setup Expo
uses: expo/expo-github-action@v8
with:
expo-version: latest
eas-version: latest
token: ${{ secrets.EXPO_TOKEN }}

- name: Install dependencies
run: yarn install

- name: Build Android app
run: eas build --platform android --profile preview --local --output ${{ github.workspace }}/app-release.apk
# Don't upload the artifact for now as we just want to make sure it builds
# - name: Upload APK artifact
# uses: actions/upload-artifact@v4
# with:
# name: app-release
# path: ${{ github.workspace }}/app-release.apk
42 changes: 42 additions & 0 deletions .github/workflows/check-ios-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: iOS App Build

on:
pull_request:
branches:
- feat/xmtp-groups-dash
# Uncomment after verification
# paths:
# - "ios/**"
# - "package.json"

jobs:
build:
runs-on: macos-latest
steps:
- name: Setup repo
uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v4.0.2
with:
node-version: 18.x
cache: "yarn"

- name: Setup Expo
uses: expo/expo-github-action@v8
with:
expo-version: latest
eas-version: latest
token: ${{ secrets.EXPO_TOKEN }}

- name: Install dependencies
run: yarn install

- name: Build iOS app
run: eas build --platform ios --local --non-interactive --output ${{ github.workspace }}/app-release.ipa
# Don't upload the artifact for now
# - name: Upload IPA artifact
# uses: actions/upload-artifact@v4
# with:
# name: app-release
# path: ${{ github.workspace }}/app-release.ipa
18 changes: 18 additions & 0 deletions scripts/build/incrementBuildNumbers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const fs = require("fs");

// Path to app.json
const filePath = "./app.json";

// Read app.json
const appJson = JSON.parse(fs.readFileSync(filePath, "utf-8"));

// Increment build numbers
appJson.expo.ios.buildNumber = (
parseInt(appJson.expo.ios.buildNumber, 10) + 1
).toString();
appJson.expo.android.versionCode = appJson.expo.android.versionCode + 1;

// Write the updated app.json back to the file
fs.writeFileSync(filePath, JSON.stringify(appJson, null, 2), "utf-8");

console.log("Version numbers incremented successfully.");
70 changes: 70 additions & 0 deletions scripts/build/incrementVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const fs = require("fs");
const path = require("path");

// Path to app.json
const filePath = path.join("./app.json");

// Function to increment version number
function incrementVersion(version, incrementType) {
const parts = version.split(".").map(Number);

switch (incrementType) {
case "patch":
parts[2] += 1;
break;
case "minor":
parts[1] += 1;
parts[2] = 0;
break;
case "major":
parts[0] += 1;
parts[1] = 0;
parts[2] = 0;
break;
default:
console.error(
'Invalid increment type. Use "patch", "minor", or "major".'
);
process.exit(1);
}

return parts.join(".");
}

// Get the increment type from command-line arguments
const args = process.argv.slice(2);
const incrementTypeArg = args.find((arg) => arg.startsWith("--bump="));

if (!incrementTypeArg) {
console.error(
"Please provide a valid increment type using --bump=<patch|minor|major>"
);
process.exit(1);
}

const incrementType = incrementTypeArg.split("=")[1];

// Read app.json
fs.readFile(filePath, "utf-8", (err, data) => {
if (err) {
console.error("Error reading app.json:", err);
process.exit(1);
}

const appJson = JSON.parse(data);

// Increment the version for both iOS and Android
const newVersion = incrementVersion(appJson.expo.ios.version, incrementType);

appJson.expo.ios.version = newVersion;
appJson.expo.android.version = newVersion;

// Write the updated app.json back to the file
fs.writeFile(filePath, JSON.stringify(appJson, null, 2), "utf-8", (err) => {
if (err) {
console.error("Error writing app.json:", err);
process.exit(1);
}
console.log(`Version updated to ${newVersion} successfully.`);
});
});

0 comments on commit c005474

Please sign in to comment.