Skip to content

Publish Release to CocoaPods and SPM #7

Publish Release to CocoaPods and SPM

Publish Release to CocoaPods and SPM #7

name: Publish Release to CocoaPods and SPM
# This workflow publishes the OneSignal pods to CocoaPods trunk.
# And creates the tagged release in the OneSignal-XCFramework repository for SPM.
# Run this AFTER the release PR has been merged and the GitHub release has been created.
on:
workflow_dispatch:
inputs:
ref:
description: "Branch or commit SHA to run on (e.g., main, 5.3-main)"
type: string
required: false
default: "main"
permissions:
contents: write
pull-requests: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
publish:
outputs:
sdk_version: ${{ steps.extract_version.outputs.version }}
runs-on: macos-14
env:
COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout OneSignal-iOS-SDK
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.ref }}
fetch-depth: 0
- name: Detect current branch
id: detect_branch
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
BRANCH="${{ github.event.inputs.ref }}"
else
BRANCH="${GITHUB_REF#refs/heads/}"
fi
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
echo "Detected branch: $BRANCH"
- name: Extract release version from podspec
id: extract_version
run: |
VERSION=$(grep -E "s.version\s*=" OneSignal.podspec | sed -E 's/.*"(.*)".*/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION"
- name: 📋 Display Configuration
run: |
echo "============================================"
echo "📦 Release Version: ${{ steps.extract_version.outputs.version }}"
echo "🌿 Branch: ${{ steps.detect_branch.outputs.branch }}"
echo "============================================"
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.0"
- name: Install CocoaPods
run: |
gem install cocoapods
pod --version
- name: Validate OneSignal.podspec
run: |
echo "Validating OneSignal.podspec..."
pod spec lint OneSignal.podspec --allow-warnings
- name: Validate OneSignalXCFramework.podspec
run: |
echo "Validating OneSignalXCFramework.podspec..."
pod spec lint OneSignalXCFramework.podspec --allow-warnings
# - name: Publish OneSignal.podspec to CocoaPods Trunk
# run: |
# echo "Publishing OneSignal.podspec to CocoaPods Trunk..."
# pod trunk push OneSignal.podspec --allow-warnings
# - name: Publish OneSignalXCFramework.podspec to CocoaPods Trunk
# run: |
# echo "Publishing OneSignalXCFramework.podspec to CocoaPods Trunk..."
# pod trunk push OneSignalXCFramework.podspec --allow-warnings
- name: ✅ CocoaPods Published
run: |
VERSION="${{ steps.extract_version.outputs.version }}"
echo "============================================"
echo "✅ Successfully published version $VERSION to CocoaPods!"
echo "============================================"
echo "📦 OneSignal: https://cocoapods.org/pods/OneSignal"
echo "📦 OneSignalXCFramework: https://cocoapods.org/pods/OneSignalXCFramework"
- name: Checkout OneSignal-XCFramework
uses: actions/checkout@v4
with:
repository: OneSignal/OneSignal-XCFramework
ref: ${{ steps.detect_branch.outputs.branch }}
path: xcframework-repo
fetch-depth: 0
token: ${{ secrets.PAT_TOKEN_ONESIGNAL_XCFRAMEWORK }}
- name: Get iOS SDK Release Body
id: get_ios_release
run: |
VERSION="${{ steps.extract_version.outputs.version }}"
# Fetch the release body from OneSignal-iOS-SDK
if gh release view "$VERSION" --repo OneSignal/OneSignal-iOS-SDK --json body --jq '.body' > ios_release_body.md 2>/dev/null; then
echo "✅ Found iOS SDK release for version $VERSION"
echo "found=true" >> $GITHUB_OUTPUT
else
echo "⚠️ No iOS SDK release found for version $VERSION"
echo "found=false" >> $GITHUB_OUTPUT
echo "" > ios_release_body.md
fi
- name: Create GitHub Release for OneSignal-XCFramework
env:
GH_TOKEN: ${{ secrets.PAT_TOKEN_ONESIGNAL_XCFRAMEWORK }}
run: |
VERSION="${{ steps.extract_version.outputs.version }}"
BRANCH="${{ steps.detect_branch.outputs.branch }}"
cd xcframework-repo
# Configure git
git config --local user.email "[email protected]"
git config --local user.name "github-actions[bot]"
# Create and push tag
git tag -a "$VERSION" -m "Release $VERSION"
git push origin "$VERSION"
echo "✅ Created and pushed tag: $VERSION to OneSignal-XCFramework"
# Use iOS SDK release body if available, otherwise create default release notes
if [[ "${{ steps.get_ios_release.outputs.found }}" == "true" ]] && [[ -s ../ios_release_body.md ]]; then
echo "Using release notes from iOS SDK release"
cp ../ios_release_body.md release_notes.md
else
echo "No iOS SDK release body found, generating default release notes"
echo "## 🔖 Release $VERSION" > release_notes.md
echo "" >> release_notes.md
echo "This release corresponds to [OneSignal-iOS-SDK $VERSION](https://github.com/OneSignal/OneSignal-iOS-SDK/releases/tag/$VERSION)" >> release_notes.md
fi
# Determine if this is a pre-release
PRERELEASE_FLAG=""
if [[ "$VERSION" == *"alpha"* ]] || [[ "$VERSION" == *"beta"* ]]; then
PRERELEASE_FLAG="--prerelease"
echo "Marking as pre-release (alpha/beta detected)"
fi
# Create GitHub release
gh release create "$VERSION" \
--repo OneSignal/OneSignal-XCFramework \
--title "$VERSION" \
--notes-file release_notes.md \
--target "$BRANCH" \
$PRERELEASE_FLAG
echo "✅ GitHub release created successfully for OneSignal-XCFramework!"
echo "🔗 https://github.com/OneSignal/OneSignal-XCFramework/releases/tag/$VERSION"
- name: ✅ All Steps Complete
run: |
VERSION="${{ steps.extract_version.outputs.version }}"
echo "============================================"
echo "✅ Successfully completed all release steps for version $VERSION"
echo "============================================"
echo "📦 CocoaPods OneSignal: https://cocoapods.org/pods/OneSignal"
echo "📦 CocoaPods OneSignalXCFramework: https://cocoapods.org/pods/OneSignalXCFramework"
echo "🔗 iOS SDK Release: https://github.com/OneSignal/OneSignal-iOS-SDK/releases/tag/$VERSION"
echo "🔗 XCFramework Release: https://github.com/OneSignal/OneSignal-XCFramework/releases/tag/$VERSION"
wrapper_prs:
needs: publish
uses: OneSignal/sdk-actions/.github/workflows/create-wrapper-prs.yml@main
secrets:
GH_PUSH_TOKEN: ${{ secrets.GH_PUSH_TOKEN }}
with:
ios_version: ${{ needs.publish.outputs.sdk_version }}