diff --git a/.github/workflows/create-release-pr.yml b/.github/workflows/create-release-pr.yml new file mode 100644 index 000000000..b816bcd15 --- /dev/null +++ b/.github/workflows/create-release-pr.yml @@ -0,0 +1,265 @@ +name: Create Unity Release PR + +on: + # For making a release pr from android / ios sdk actions + workflow_call: + inputs: + unity_version: + description: 'New Unity Version (e.g., 5.2.15 or 5.2.15-beta.1)' + required: true + type: string + android_version: + description: 'New Android SDK Version (e.g., 2.3.0). Leave blank to skip.' + required: false + type: string + ios_version: + description: 'New iOS SDK Version (e.g., 1.5.0). Leave blank to skip.' + required: false + type: string + + # For making a release pr from github actions + workflow_dispatch: + inputs: + unity_version: + description: 'New Unity Version (e.g., 5.2.15 or 5.2.15-beta.1)' + required: true + type: string + android_version: + description: 'New Android SDK Version (e.g., 2.3.0). Leave blank to skip.' + required: false + type: string + ios_version: + description: 'New iOS SDK Version (e.g., 1.5.0). Leave blank to skip.' + required: false + type: string + +permissions: + contents: write + pull-requests: write + +jobs: + prep: + uses: OneSignal/sdk-actions/.github/workflows/prep-release.yml@main + with: + version: ${{ inputs.unity_version }} + + # Unity specific steps + update-version: + needs: prep + runs-on: ubuntu-latest + outputs: + unity_from: ${{ steps.current_versions.outputs.unity_from }} + ios_from: ${{ steps.current_versions.outputs.ios_from }} + android_from: ${{ steps.current_versions.outputs.android_from }} + + steps: + - name: Checkout + uses: actions/checkout@v5 + with: + ref: ${{ needs.prep.outputs.release_branch }} + + - name: Configure Git + run: | + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git config --global user.name "github-actions[bot]" + + - name: Prepare Environment + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + sudo apt-get update + sudo apt-get install -y gh jq || true + gh auth status || gh auth login --with-token <<< "$GH_TOKEN" + + - name: Get current native SDK versions + id: current_versions + run: | + # Current Unity version + CURRENT_VERSION=$(cat OneSignalExample/Assets/OneSignal/VERSION | tr -d '\n\r' | xargs) + + # Extract current Android SDK version + ANDROID_VERSION=$(grep -oE 'spec="com.onesignal:OneSignal:[0-9]+\.[0-9]+\.[0-9]+"' com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.xml | sed -E 's/.*OneSignal:([0-9]+\.[0-9]+\.[0-9]+)".*/\1/' | head -1) + + # Extract current iOS SDK version + IOS_VERSION=$(grep -oE 'version="[0-9.]+"' com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.xml | grep -oE '[0-9.]+' | head -1) + + echo "unity_from=${CURRENT_VERSION}" >> $GITHUB_OUTPUT + echo "android_from=${ANDROID_VERSION}" >> $GITHUB_OUTPUT + echo "ios_from=${IOS_VERSION}" >> $GITHUB_OUTPUT + + echo " unity_from: ${CURRENT_VERSION}" + echo " android_from: ${ANDROID_VERSION}" + echo " ios_from: ${IOS_VERSION}" + + - name: Update Android SDK version + if: inputs.android_version != '' + run: | + VERSION="${{ inputs.android_version }}" + + # Validate version exists on GitHub + RELEASE=$(curl -s -H "Authorization: token ${{ github.token }}" \ + "https://api.github.com/repos/OneSignal/OneSignal-Android-SDK/releases/tags/${VERSION}") + + if [ -z "$RELEASE" ]; then + echo "✗ Android SDK version ${VERSION} not found" + exit 1 + fi + + sed -i -E "s/spec=\"com\.onesignal:OneSignal:[0-9][0-9.]*\"/spec=\"com.onesignal:OneSignal:$VERSION\"/" com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.xml + sed -i -E "s/'com\.onesignal:OneSignal:[0-9][0-9.]*'/'com.onesignal:OneSignal:$VERSION'/" OneSignalExample/Assets/Plugins/Android/mainTemplate.gradle + sed -i -E "s/com\.onesignal:OneSignal:[0-9][0-9.]*<\/package>/com.onesignal:OneSignal:$VERSION<\/package>/" OneSignalExample/ProjectSettings/AndroidResolverDependencies.xml + + echo "✓ Updated Android SDK to ${VERSION}" + git add . + git commit -m "Bump Android SDK $VERSION" + git push + + - name: Update iOS SDK version + if: inputs.ios_version != '' + run: | + VERSION="${{ inputs.ios_version }}" + + # Validate version exists on GitHub + RELEASE=$(curl -s -H "Authorization: token ${{ github.token }}" \ + "https://api.github.com/repos/OneSignal/OneSignal-iOS-SDK/releases/tags/${VERSION}") + + if [ -z "$RELEASE" ]; then + echo "✗ iOS SDK version ${VERSION} not found" + exit 1 + fi + + sed -i -E "s/version=\"[0-9][0-9.]*\"/version=\"$VERSION\"/" com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.xml + + echo "✓ Updated iOS SDK to ${VERSION}" + git add . + git commit -m "Bump iOS SDK $VERSION" + git push + + create-pr: + needs: [prep, update-version] + uses: OneSignal/sdk-actions/.github/workflows/create-release.yml@main + with: + release_branch: ${{ needs.prep.outputs.release_branch }} + version_from: ${{ needs.update-version.outputs.unity_from }} + version_to: ${{ inputs.unity_version }} + android_from: ${{ needs.update-version.outputs.android_from }} + android_to: ${{ inputs.android_version }} + ios_from: ${{ needs.update-version.outputs.ios_from }} + ios_to: ${{ inputs.ios_version }} + + draft-release: + needs: [prep, update-version] + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v5 + with: + ref: ${{ needs.prep.outputs.release_branch }} + + - name: Update Unity SDK version + run: | + echo "Updating Unity SDK version to ${{ inputs.unity_version }}" + + # Version string formats + PADDED_VERSION=$(printf "%06d" $(echo "${{ inputs.unity_version }}" | sed 's/[^0-9]//g')) + + # VERSION file + echo "${{ inputs.unity_version }}" > OneSignalExample/Assets/OneSignal/VERSION + + # package.json files + for file in com.onesignal.unity.core/package.json com.onesignal.unity.android/package.json com.onesignal.unity.ios/package.json; do + sed -i "s/\"version\": \".*\"/\"version\": \"${{ inputs.unity_version }}\"/" "$file" + sed -i "s/\"com.onesignal.unity.core\": \".*\"/\"com.onesignal.unity.core\": \"${{ inputs.unity_version }}\"/" "$file" + done + + sed -i "s/public const string Version = \".*\"/public const string Version = \"${{ inputs.unity_version }}\"/" \ + com.onesignal.unity.core/Runtime/OneSignal.cs + sed -i "s/public const string VersionHeader = \".*\"/public const string VersionHeader = \"${PADDED_VERSION}\"/" \ + com.onesignal.unity.core/Runtime/OneSignalPlatform.cs + + # asmdef files + for asm in \ + OneSignalExample/Assets/OneSignal/Example/OneSignal.UnityPackage.Example.asmdef \ + OneSignalExample/Assets/OneSignal/Editor/OneSignal.UnityPackage.Editor.asmdef \ + OneSignalExample/Assets/OneSignal/Attribution/OneSignal.UnityPackage.Attribution.asmdef; do + sed -i "s/\"expression\": \".*\"/\"expression\": \"${{ inputs.unity_version }}\"/" "$asm" + done + + # packages-lock.json + sed -i "s/\"com.onesignal.unity.core\": \"[0-9.]\+\"/\"com.onesignal.unity.core\": \"${{ inputs.unity_version }}\"/g" \ + OneSignalExample/Packages/packages-lock.json + + # ProjectSettings.asset + sed -i "s/bundleVersion: .*/bundleVersion: ${{ inputs.unity_version }}/" \ + OneSignalExample/ProjectSettings/ProjectSettings.asset + + # iOS plugin version (UIApplication+OneSignalUnity.mm) + sed -i "s/setSdkVersion:@\"[0-9]*\"/setSdkVersion:@\"${PADDED_VERSION}\"/" \ + com.onesignal.unity.ios/Runtime/Plugins/iOS/UIApplication+OneSignalUnity.mm + + # to save time, use cached Unity installation if available + - name: Cache Unity + uses: actions/cache@v4 + with: + path: /home/runner/Unity/Hub/Editor + key: UnityEditor-${{ runner.os }} + restore-keys: | + UnityEditor-${{ runner.os }} + + # setup Unity using the version file + - name: Setup Unity + uses: buildalon/unity-setup@v2.1.1 + with: + version-file: 'OneSignalExample/ProjectSettings/ProjectVersion.txt' + + # need to activate the Unity license to run Unity in batchmode; required for exportPackage + - uses: buildalon/activate-unity-license@v2 + with: + license: 'Personal' + username: '${{ secrets.UNITY_USERNAME }}' + password: '${{ secrets.UNITY_PASSWORD }}' + + - name: Cleaning up Unity locks + run: | + pkill -f Unity || true + rm -f OneSignalExample/Temp/UnityLockfile + rm -rf OneSignalExample/Library OneSignalExample/Temp OneSignalExample/obj OneSignalExample/UserSettings || true + + - name: Run UpdateProjectVersion + uses: buildalon/unity-action@v3 + with: + project-path: OneSignalExample + args: -quit -batchmode -nographics -buildTarget Android -executeMethod OneSignalSDK.OneSignalPackagePublisher.UpdateProjectVersion + + - name: Run ExportUnityPackage + uses: buildalon/unity-action@v3 + with: + project-path: OneSignalExample + args: -quit -batchmode -nographics -buildTarget Android -executeMethod OneSignalSDK.OneSignalPackagePublisher.ExportUnityPackage + + - name: Commit Release + run: | + git add . + git commit -m "Release ${{ inputs.unity_version }}" + git push + + - name: Debug — list Unity package files + run: | + echo "Current working directory:" + pwd + echo "" + echo "List of all files under OneSignalExample:" + ls -Rlh OneSignalExample || true + echo "" + echo "Searching for .unitypackage files:" + find OneSignalExample -type f -name "*.unitypackage" -print + + - name: Draft Release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + package_path="OneSignalExample/OneSignal-v${{ inputs.unity_version }}.unitypackage" + gh release create "${{ inputs.unity_version }}" "${package_path}"\ + --draft\ + --title "${{ inputs.unity_version }} Release"\ + --notes "TODO" \ No newline at end of file diff --git a/OneSignalExample/Assets/OneSignalPackager/Editor/OneSignalPackagePublisher.cs b/OneSignalExample/Assets/OneSignalPackager/Editor/OneSignalPackagePublisher.cs index 6c9a8d768..b6630d245 100644 --- a/OneSignalExample/Assets/OneSignalPackager/Editor/OneSignalPackagePublisher.cs +++ b/OneSignalExample/Assets/OneSignalPackager/Editor/OneSignalPackagePublisher.cs @@ -45,12 +45,24 @@ public static void UpdateProjectVersion() [MenuItem("OneSignal/ExportUnityPackage")] public static void ExportUnityPackage() { + UnityEngine.Debug.Log($"[OneSignalPackagePublisher] start exporting package"); AssetDatabase.Refresh(); var packageVersion = File.ReadAllText(VersionFilePath); var packageName = $"OneSignal-v{packageVersion}.unitypackage"; + UnityEngine.Debug.Log($"[OneSignalPackagePublisher] package name: {packageName}"); + + string[] filePaths = _filePaths(); + UnityEngine.Debug.Log( + $"[OneSignalPackagePublisher] Found {filePaths.Length} files/directories to include:" + ); + foreach (var path in filePaths) + { + UnityEngine.Debug.Log($"[OneSignalPackagePublisher] - {path}"); + } + AssetDatabase.ExportPackage( - _filePaths(), + filePaths, packageName, ExportPackageOptions.Recurse | ExportPackageOptions.IncludeDependencies ); @@ -68,6 +80,9 @@ public static void ExportUnityPackage() private static string[] _filePaths() { var files = Directory.GetFileSystemEntries(PackagePath); + UnityEngine.Debug.Log( + $"[OneSignalPackagePublisher] Getting file paths from: {PackagePath}" + ); var pathsToInclude = files.Where(file => { if (file.EndsWith(".meta")) diff --git a/OneSignalExample/Assets/Plugins/Android/mainTemplate.gradle b/OneSignalExample/Assets/Plugins/Android/mainTemplate.gradle index 8367ed164..9059180e0 100644 --- a/OneSignalExample/Assets/Plugins/Android/mainTemplate.gradle +++ b/OneSignalExample/Assets/Plugins/Android/mainTemplate.gradle @@ -6,7 +6,7 @@ apply plugin: 'com.android.library' dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) // Android Resolver Dependencies Start - implementation 'com.onesignal:OneSignal:5.1.37' // Packages/com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.xml:6 + implementation 'com.onesignal:OneSignal:5.1.38' // Packages/com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.xml:6 // Android Resolver Dependencies End **DEPS**} diff --git a/OneSignalExample/ProjectSettings/AndroidResolverDependencies.xml b/OneSignalExample/ProjectSettings/AndroidResolverDependencies.xml index a8f902665..8d6a24f89 100644 --- a/OneSignalExample/ProjectSettings/AndroidResolverDependencies.xml +++ b/OneSignalExample/ProjectSettings/AndroidResolverDependencies.xml @@ -1,6 +1,6 @@ - com.onesignal:OneSignal:5.1.37 + com.onesignal:OneSignal:5.1.38 diff --git a/com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.xml b/com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.xml index ef098636b..06a843794 100644 --- a/com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.xml +++ b/com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.xml @@ -3,6 +3,6 @@ https://repo.maven.apache.org/maven2 - + diff --git a/com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.xml b/com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.xml index ba5b6bff1..3b2267cc0 100644 --- a/com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.xml +++ b/com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.xml @@ -1,5 +1,5 @@  - + diff --git a/composeRelease.sh b/composeRelease.sh index 8febddb11..d6b76d70a 100755 --- a/composeRelease.sh +++ b/composeRelease.sh @@ -67,39 +67,34 @@ fi # try to find unity executable unity_project_version_path="OneSignalExample/ProjectSettings/ProjectVersion.txt" -unity_project_version=$(cat ${unity_project_version_path} | sed -n 's/^m_EditorVersion: //p') -unity_versions_path="/Applications/Unity/Hub/Editor" -unity_path="${unity_versions_path}/${unity_project_version}" - -if [[ ! -d "${unity_versions_path}" ]] -then - echo "Could not find any versions of Unity installed at path: ${unity_versions_path}" - exit 1 -elif [[ ! -d "${unity_path}" ]] -then - echo "Could not find Unity ${unity_project_version}" - pushd "${unity_versions_path}" > /dev/null 2>&1 - - options=(* "Exit") - PS3="Please select an installed Unity version: " - select option in "${options[@]}" - do - if [[ "$option" = "Exit" ]] - then - exit 1 - elif [[ "${options[@]}" =~ "$option" ]] - then - echo "Using ${option}" - unity_path="${unity_versions_path}/${option}" - break - fi - done +unity_project_version=$(cat "${unity_project_version_path}" | sed -n 's/^m_EditorVersion: //p') + +# Unity project path from CI environment if available +unity_project_path="${UNITY_PROJECT_PATH:-OneSignalExample}" + +# Common installation locations (CI, macOS, local) +unity_candidates=( + "/home/runner/Unity/Hub/Editor/${unity_project_version}/Editor/Unity" # Linux (buildalon/unity-setup) + "/Applications/Unity/Hub/Editor/${unity_project_version}/Unity.app/Contents/MacOS/Unity" # macOS +) + +unity_executable="" +for candidate in "${unity_candidates[@]}"; do + if [[ -x "$candidate" ]]; then + unity_executable="$candidate" + break + fi +done - popd > /dev/null 2>&1 +if [[ -z "$unity_executable" ]]; then + echo "❌ Could not locate Unity executable for version ${unity_project_version}" + echo "Checked the following paths:" + printf ' - %s\n' "${unity_candidates[@]}" + exit 1 +else + echo "✅ Found Unity executable: ${unity_executable}" fi -unity_executable="${unity_path}/Unity.app/Contents/MacOS/Unity" - # VERSION file will act as the source of truth version_filepath="OneSignalExample/Assets/OneSignal/VERSION" current_version=$(cat "$version_filepath") @@ -282,26 +277,45 @@ executeUnityMethod() { local project_path=$1 local build_target=$2 local method_name=$3 - local log_path="${PWD}/logs/${method_name}-${build_target}-$(date +%Y%m%d%H%M%S).txt" - - ${unity_executable} -projectpath "${project_path}"\ - -quit\ - -batchmode\ - -nographics\ - -buildTarget "${build_target}"\ - -executeMethod "${method_name}"\ - -logFile "${log_path}" - + local log_dir="${PWD}/logs" + mkdir -p "${log_dir}" + + local log_path="${log_dir}/${method_name}-${build_target}-$(date +%Y%m%d%H%M%S).txt" + + echo "▶️ Running Unity method: ${method_name} (${build_target})" + echo " Log file: ${log_path}" + + # Clean up stale locks before running + pkill -f Unity || true + rm -f "${project_path}/Temp/UnityLockfile" + + # Run Unity in batchmode + "${unity_executable}" \ + -projectPath "${project_path}" \ + -quit \ + -batchmode \ + -nographics \ + -buildTarget "${build_target}" \ + -executeMethod "${method_name}" \ + -logFile "${log_path}" + local method_result=$? - + if [[ ${method_result} -ne 0 ]]; then - echo "Unity method failed with ${method_result}" - exit ${method_result} + echo "❌ Unity method ${method_name} failed with exit code ${method_result}" + echo "----- Unity log tail (last 40 lines) -----" + tail -n 40 "${log_path}" || echo "(no log file found)" + echo "------------------------------------------" else - echo "Unity method completed" + echo "✅ Unity method ${method_name} completed successfully" + echo " Full log: ${log_path}" fi } +echo "Cleaning up Unity locks..." +pkill -f Unity || true +rm -f OneSignalExample/Temp/UnityLockfile + # update project version projectsettings_path="OneSignalExample/ProjectSettings/ProjectSettings.asset" executeUnityMethod "OneSignalExample" "Android" "OneSignalSDK.OneSignalPackagePublisher.UpdateProjectVersion" @@ -335,4 +349,4 @@ gh release create "${new_version}" "${package_path}"\ # return to workspace git checkout "${current_branch}" -git stash pop \ No newline at end of file +git stash pop