|
| 1 | +name: Publish to CocoaPods |
| 2 | + |
| 3 | +# NOTE: CocoaPods Trunk is planned to become read-only by end of 2025. |
| 4 | +# This automation will work only until then. SPM is the primary distribution channel. |
| 5 | +# This workflow serves as a short-term sync for legacy CocoaPods users. |
| 6 | + |
| 7 | +on: |
| 8 | + push: |
| 9 | + tags: |
| 10 | + - 'v*' # Triggers when you push a version tag (e.g. v2.0.1, v2.4.0-beta.1) |
| 11 | + release: |
| 12 | + types: [published] # Also triggers when a GitHub Release is published |
| 13 | + |
| 14 | +jobs: |
| 15 | + publish: |
| 16 | + name: Publish Podspec to CocoaPods |
| 17 | + runs-on: macos-latest |
| 18 | + steps: |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@v3 |
| 21 | + with: |
| 22 | + fetch-depth: 0 # Fetch all history for tags |
| 23 | + |
| 24 | + - name: Set up Ruby |
| 25 | + uses: ruby/setup-ruby@v1 |
| 26 | + with: |
| 27 | + ruby-version: '3.0' |
| 28 | + bundler-cache: false # We're installing CocoaPods directly |
| 29 | + |
| 30 | + - name: Install CocoaPods |
| 31 | + run: gem install cocoapods |
| 32 | + |
| 33 | + - name: Extract version from tag or podspec |
| 34 | + id: get_version |
| 35 | + run: | |
| 36 | + if [ "${{ github.event_name }}" == "release" ]; then |
| 37 | + VERSION="${{ github.event.release.tag_name }}" |
| 38 | + VERSION=${VERSION#v} |
| 39 | + elif [[ "${{ github.ref }}" == refs/tags/* ]]; then |
| 40 | + VERSION="${GITHUB_REF#refs/tags/}" |
| 41 | + VERSION=${VERSION#v} |
| 42 | + else |
| 43 | + # Branch push: use version from podspec (for testing workflow) |
| 44 | + VERSION=$(grep -E "s\.version\s*=" ContentstackSwift.podspec | sed -E "s/.*['\"]([^'\"]+)['\"].*/\1/") |
| 45 | + fi |
| 46 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 47 | + echo "Extracted version: $VERSION" |
| 48 | +
|
| 49 | + - name: Verify podspec version matches tag |
| 50 | + run: | |
| 51 | + PODSPEC_VERSION=$(grep -E "s\.version\s*=" ContentstackSwift.podspec | sed -E "s/.*['\"]([^'\"]+)['\"].*/\1/") |
| 52 | + TAG_VERSION="${{ steps.get_version.outputs.version }}" |
| 53 | + if [ "$PODSPEC_VERSION" != "$TAG_VERSION" ]; then |
| 54 | + echo "Error: Podspec version ($PODSPEC_VERSION) does not match tag version ($TAG_VERSION)" |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | + echo "✓ Podspec version matches tag: $PODSPEC_VERSION" |
| 58 | +
|
| 59 | + - name: Lint Podspec |
| 60 | + run: pod lib lint ContentstackSwift.podspec --allow-warnings |
| 61 | + |
| 62 | + - name: Publish to CocoaPods |
| 63 | + if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'release' |
| 64 | + run: pod trunk push ContentstackSwift.podspec --allow-warnings |
| 65 | + env: |
| 66 | + COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN }} |
| 67 | + |
0 commit comments