Skip to content

Conversation

@NidhiDixit09
Copy link
Collaborator

Reference

SDK-XXXX -- <TITLE>.

Summary

Motivation

Type Of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Testing Instructions

cc @BranchMetrics/saas-sdk-devs for visibility.

Comment on lines +12 to +149
runs-on: macos-latest
steps:
# --- Step 1: Extract version from branch name ---
- name: Extract version from branch name
id: extract_version_step
run: |
BRANCH_NAME="${{ github.ref }}"
# Remove 'refs/heads/' prefix (e.g., refs/heads/Release-0.0.0 -> Release-0.0.0)
BRANCH_NAME_WITHOUT_PREFIX="${BRANCH_NAME#refs/heads/}"
# Extract version after "Release-" (e.g., Release-0.0.0 -> 0.0.0)
VERSION=$(echo "$BRANCH_NAME_WITHOUT_PREFIX" | sed -n 's/^Release-\([0-9]*\.[0-9]*\.[0-9]*\)$/\1/p')

if [ -z "$VERSION" ]; then
echo "Error: Could not extract version from branch name '$BRANCH_NAME_WITHOUT_PREFIX'. Expected format: Release-X.Y.Z"
exit 1
fi

echo "Extracted versionName: $VERSION"
echo "VERSION_STRING=$VERSION" >> $GITHUB_ENV

# Convert semantic version to an integer for CFBundleVersion (versionCode equivalent)
# Example: 1.2.3 -> 102003 (assuming max 2 digits for minor/patch)
# This should be adjusted based on the maximum expected values for major/minor/patch
MAJOR=$(echo "$VERSION" | cut -d. -f1)
MINOR=$(echo "$VERSION" | cut -d. -f2)
PATCH=$(echo "$VERSION" | cut -d. -f3)

# Calculate versionCode (CFBundleVersion) - ensure this fits in a 32-bit integer
# Standard Android-like conversion: Major * 10000 + Minor * 100 + Patch
# This provides sufficient uniqueness for most common versioning schemes.
VERSION_CODE_INT=$(( MAJOR * 10000 + MINOR * 100 + PATCH ))
echo "Calculated versionCode: $VERSION_CODE_INT"
echo "VERSION_CODE_INT=$VERSION_CODE_INT" >> $GITHUB_ENV


# --- Step 2: Checkout the iOS Branch SDK repository ---
- name: Checkout BranchMetrics/ios-branch-deep-linking-attribution (SDK)
uses: actions/checkout@v4
with:
repository: BranchMetrics/ios-branch-deep-linking-attribution
ref: ${{ github.ref }} # Use the same branch that triggered the workflow
path: ./branch-ios-sdk-repo # Checkout into a subdirectory

# --- Step 3: Build the iOS Branch SDK Framework ---
- name: Build Branch SDK Framework
run: |
# Build for simulator. Adjust scheme if necessary.
# The output framework will be in build/Debug-iphonesimulator/BranchSDK.framework
xcodebuild -scheme xcframework \
BUILD_DIR="${{ github.workspace }}/branch-ios-sdk-repo/build"
working-directory: ./branch-ios-sdk-repo

# --- Step 4: Checkout the iOS Branch Link Simulator App repository ---
- name: Checkout BranchMetrics/BranchLinkSimulator (App)
uses: actions/checkout@v4
with:
repository: BranchMetrics/BranchLinkSimulator
ref: gptdriver/linkingTests # Checkout the specific app branch
path: ./ios-app-repo # Checkout into another subdirectory

# --- Step 5: Copy the generated SDK Framework to the App's project ---
- name: Copy generated SDK Framework to App's libs directory
run: |
# Create a 'Frameworks' directory within the app repo for the local SDK
mkdir -p ./ios-app-repo/Frameworks
# Copy the built framework
cp -R ./branch-ios-sdk-repo/build/BranchSDK.xcframework ./ios-app-repo/Frameworks/
working-directory: ${{ github.workspace }} # Run from the root of the GITHUB_WORKSPACE

# --- Step 6: Install Code Sign Certificate and Provisioning profile
- name: Install the Apple certificate and provisioning profile
env:
BUILD_CERTIFICATE_BASE64: ${{ secrets.BS_BUILD_CERTIFICATE }}
P12_PASSWORD: ${{ secrets.BS_P12_PASSWORD }}
BUILD_PROVISION_PROFILE_BASE64: ${{ secrets.BS_BUILD_PROVISION_PROFILE_BASE64_PART_AA }}
KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }}
run: |
# create variables
CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12
KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db
PP_PATH=$RUNNER_TEMP/build_pp.mobileprovision

# import certificate
echo -n "$BUILD_CERTIFICATE_BASE64" | base64 --decode -o $CERTIFICATE_PATH

# Create Provisioning Profiles
echo "${{ secrets.BS_BUILD_PROVISION_PROFILE_BASE64_PART_AA }}" >> part_aa
#echo "${{ secrets.BS_BUILD_PROVISION_PROFILE_BASE64_PART_AB }}" >> part_aa
#echo "${{ secrets.BS_BUILD_PROVISION_PROFILE_BASE64_PART_AC }}" >> part_aa
base64 -D -i part_aa > $PP_PATH

# create temporary keychain
security create-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
security set-keychain-settings -lut 21600 $KEYCHAIN_PATH
security unlock-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH

# import certificate to keychain
security import $CERTIFICATE_PATH -P "$P12_PASSWORD" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH
security list-keychain -d user -s $KEYCHAIN_PATH

# apply provisioning profile
mkdir -p ~/Library/Developer/Xcode/UserData/Provisioning\ Profiles
cp $PP_PATH ~/Library/Developer/Xcode/UserData/Provisioning\ Profiles/

# --- Step 6: Build the iOS Branch Link Simulator App using the local SDK Framework ---
- name: Build iOS App with local SDK
run: |
# Build the app. Adjust project/workspace, scheme, and destination if necessary.
# We're passing MARKETING_VERSION (versionName) and CURRENT_PROJECT_VERSION (versionCode)
xcodebuild -scheme BranchLinkSimulator -allowProvisioningUpdates \
MARKETING_VERSION=${{ env.VERSION_STRING }} \
CURRENT_PROJECT_VERSION=${{ env.VERSION_CODE_INT }} \
-sdk iphoneos archive -archivePath ./IPA/BranchLinkSimulator.xcarchive
xcodebuild -exportArchive -archivePath ./IPA/BranchLinkSimulator.xcarchive -exportOptionsPlist IPA/Info.plist -exportPath IPA/
working-directory: ./ios-app-repo

# --- Step 7: Echo the location of the generated .app bundle ---
- name: Echo .app bundle location
run: |
APP_PATH="./ios-app-repo/IPA/BranchLinkSimulator.ipa"
echo "Generated IPA location: $APP_PATH"

# --- Step 8: Upload Build Artifacts ---
- name: Upload Build Artifacts
uses: actions/upload-artifact@v4
with:
name: BranchLinkSimulator-iOS-Debug-Build
path: ./ios-app-repo/IPA/BranchLinkSimulator.ipa

# --- Step 9: Run tests on GPTDriver service. ---
- name: Run GPTDriver tests
run: |
chmod +x ./branch-ios-sdk-repo/.github/gptdriverrunscript.sh
./branch-ios-sdk-repo/.github/gptdriverrunscript.sh ./ios-app-repo/IPA/BranchLinkSimulator.ipa ios
env:
API_ORG_KEY: ${{ secrets.MOBILEBOOST_API_ORG_KEY }}
API_KEY: ${{ secrets.MOBILEBOOST_API_ORG_KEY }}
TEST_TAGS: ios

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 22 days ago

To fix this issue, we need to explicitly set the permissions key in the workflow file to restrict the permissions granted to the GITHUB_TOKEN in the workflow. The minimal, safest starting point is contents: read, which grants read-only repository access. Since this workflow checks out code, builds, signs, and uploads artifacts, but does not push changes, open issues, or create pull requests, the minimal contents: read permission is appropriate. This should be added at the root level of the workflow file (after name: and before on:), which will affect all jobs unless overridden.

No changes to functionality will occur with this update, and all workflow steps will continue to work as before, but potential write access to repository content will be removed.

Suggested changeset 1
.github/workflows/gpt-driver-tests.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/gpt-driver-tests.yml b/.github/workflows/gpt-driver-tests.yml
--- a/.github/workflows/gpt-driver-tests.yml
+++ b/.github/workflows/gpt-driver-tests.yml
@@ -1,4 +1,6 @@
 name: GPTDriver Test Suite Automation
+permissions:
+  contents: read
 
 on:
   workflow_dispatch:
EOF
@@ -1,4 +1,6 @@
name: GPTDriver Test Suite Automation
permissions:
contents: read

on:
workflow_dispatch:
Copilot is powered by AI and may make mistakes. Always verify output.
@matter-code-review
Copy link
Contributor

Code Quality new feature

Summary By MatterAI MatterAI logo

🔄 What Changed

Added automation scripts for GPTDriver test suite execution via GitHub Actions. Introduced .github/gptdriverrunscript.sh (Bash script to upload builds, trigger tests, and validate results) and .github/workflows/gpt-driver-tests.yml (CI workflow to build iOS SDK & app, sign, package, and run automated tests on GPTDriver).

🔍 Impact of the Change

Enables fully automated testing of iOS builds on GPTDriver upon pushing to Release-* branches. Integrates version extraction, SDK compilation, app bundling, code signing, IPA generation, and cloud test execution with result reporting in GitHub Actions.

📁 Total Files Changed

  • .github/gptdriverrunscript.sh: Added (124 lines) – Core script to interact with GPTDriver API for uploading, running, and monitoring tests.
  • .github/workflows/gpt-driver-tests.yml: Added (149 lines) – Orchestrates full CI pipeline: version parsing, SDK/app build, code signing, IPA export, and test triggering.

🧪 Test Added

  • Automated E2E Test Flow: On push to Release-*, the workflow:
    1. Extracts version from branch name.
    2. Builds Branch SDK as .xcframework.
    3. Clones simulator app, injects SDK, signs, and builds IPA.
    4. Uploads IPA to GPTDriver via API.
    5. Triggers test suite with tags.
    6. Polls until completion (max 2h timeout).
    7. Reports results via GITHUB_STEP_SUMMARY.

🔒 Security Vulnerabilities

  • API token usage is secure via secrets.
  • Certificate and provisioning profile handling is correct.
  • No hardcoded credentials.
  • Minor risk: API_KEY is duplicated as API_ORG_KEY in env — potential misconfiguration.

Tip

Quality Recommendations

  1. Remove redundant API_KEY environment variable assignment; use API_ORG_KEY consistently

  2. Add timeout handling in curl calls within post_data() to prevent hanging

  3. Validate jq is installed before script execution to avoid runtime failures

  4. Use consistent error logging (all to stderr) and standardize exit codes

  5. Split long workflow steps into reusable composite actions for maintainability

Tanka Poem ♫

Build flows through air,
Tests wake in silent clouds,
Code signs with care,
Results bloom in green —
CI sings. 🌿

Sequence Diagram

sequenceDiagram
    participant GHA as GitHub Actions
    participant Script as gptdriverrunscript.sh
    participant API as GPTDriver API
    participant SDK as Branch SDK
    participant App as BranchLinkSimulator App

    Note over GHA: Trigger on push to Release-*

    GHA->>GHA: Extract version from branch
    GHA->>SDK: Build xcframework
    GHA->>App: Checkout & inject SDK
    GHA->>GHA: Sign app with cert + profile
    GHA->>GHA: Build IPA
    GHA->>Script: Run with IPA path, platform

    Script->>API: POST /uploadBuild (multipart)
    API-->>Script: {buildId, app_link}

    Script->>API: POST /tests/execute {organisationId, uploadId, tags}
    API-->>Script: {test_suite_ids[0]}

    Script->>API: GET /testSuiteRuns/{id}/gh (polling)

    alt Status = completed
        API-->>Script: {status: completed, result: succeeded}
        Script-->>GHA: exit 0
    else Timeout or failure
        Script-->>GHA: exit 1
    end

    Script->>GHA: Write markdown to GITHUB_STEP_SUMMARY
Loading

@matter-code-review
Copy link
Contributor

Important

PR Review Skipped

PR review skipped as per the configuration setting. Run a manually review by commenting /matter review

💡Tips to use MatterAI

Command List

  • /matter summary: Generate AI Summary for the PR
  • /matter review: Generate AI Reviews for the latest commit in the PR
  • /matter review-full: Generate AI Reviews for the complete PR
  • /matter release-notes: Generate AI release-notes for the PR
  • /matter : Chat with your PR with MatterAI Agent
  • /matter remember : Generate AI memories for the PR
  • /matter explain: Get an explanation of the PR
  • /matter help: Show the list of available commands and documentation
  • Need help? Join our Discord server: https://discord.gg/fJU5DvanU3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant