Publish to CocoaPods #4
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: Publish to CocoaPods | |
on: | |
push: | |
branches: [ main ] | |
paths: | |
- 'Roboflow.podspec' | |
workflow_dispatch: | |
inputs: | |
force_tag: | |
description: 'Allow republish of existing tag (use with caution)' | |
type: boolean | |
required: false | |
default: false | |
jobs: | |
publish: | |
runs-on: macos-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Fetch all tags | |
- name: Setup Xcode | |
uses: maxim-lobanov/[email protected] | |
with: | |
xcode-version: 'latest-stable' | |
- name: Setup Ruby | |
uses: ruby/setup-ruby@v1 | |
with: | |
ruby-version: '3.2' | |
bundler-cache: false | |
- name: Install CocoaPods | |
run: | | |
gem install cocoapods | |
pod --version | |
- name: Extract version from podspec | |
id: get_version | |
run: | | |
VERSION=$(pod ipc spec Roboflow.podspec | jq -r '.version') | |
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT | |
echo "Detected version: $VERSION" | |
- name: Validate podspec | |
run: | | |
echo "Setting up iOS simulator..." | |
xcrun simctl list devices | |
echo "" | |
echo "Linting pod..." | |
pod lib lint --allow-warnings | |
- name: Create and push tag | |
run: | | |
echo "Creating tag for version ${{ steps.get_version.outputs.VERSION }}..." | |
git config user.name github-actions | |
git config user.email [email protected] | |
# Check if tag already exists remotely | |
if git ls-remote --tags origin | grep -q "refs/tags/${{ steps.get_version.outputs.VERSION }}$"; then | |
if [[ "${{ github.event.inputs.force_tag }}" == "true" ]]; then | |
echo "Tag ${{ steps.get_version.outputs.VERSION }} already exists. Force push enabled, overwriting..." | |
git tag -f "${{ steps.get_version.outputs.VERSION }}" | |
git push origin "${{ steps.get_version.outputs.VERSION }}" --force | |
echo "Force pushed tag: ${{ steps.get_version.outputs.VERSION }}" | |
else | |
echo "Error: Tag ${{ steps.get_version.outputs.VERSION }} already exists and force push is not enabled." | |
echo "To overwrite, run the workflow manually with 'Allow republish of existing tag' option checked." | |
exit 1 | |
fi | |
else | |
git tag "${{ steps.get_version.outputs.VERSION }}" | |
git push origin "${{ steps.get_version.outputs.VERSION }}" | |
echo "Created and pushed new tag: ${{ steps.get_version.outputs.VERSION }}" | |
fi | |
- name: Publish to CocoaPods | |
env: | |
COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN }} | |
run: | | |
echo "DRY RUN Publishing version ${{ steps.get_version.outputs.VERSION }} to CocoaPods..." | |
echo "pod trunk push" | |
echo "Successfully published to CocoaPods!" |