|
| 1 | +# Publishes TugboatCaptureRuntime to CocoaPods trunk. |
| 2 | +# |
| 3 | +# Merging a PR does not publish by itself. This workflow: |
| 4 | +# 1. On push to main, dispatches itself when trunk does not have s.version. |
| 5 | +# 2. On workflow_dispatch or tag apple-runtime-v*, lints and pod trunk push. |
| 6 | +# |
| 7 | +# Flutter must not pin a version that is not on trunk yet. After a successful |
| 8 | +# push, pin_flutter waits for trunk and opens a Flutter pin PR if needed. |
| 9 | +name: Publish Apple runtime |
| 10 | + |
| 11 | +on: |
| 12 | + push: |
| 13 | + branches: |
| 14 | + - main |
| 15 | + tags: |
| 16 | + - 'apple-runtime-v[0-9]+.[0-9]+.[0-9]+' |
| 17 | + workflow_dispatch: |
| 18 | + |
| 19 | +concurrency: |
| 20 | + group: publish-apple-${{ github.ref }} |
| 21 | + cancel-in-progress: false |
| 22 | + |
| 23 | +jobs: |
| 24 | + tag_main: |
| 25 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 26 | + runs-on: ubuntu-latest |
| 27 | + permissions: |
| 28 | + contents: write |
| 29 | + actions: write |
| 30 | + steps: |
| 31 | + - name: Checkout |
| 32 | + uses: actions/checkout@v4 |
| 33 | + with: |
| 34 | + fetch-depth: 0 |
| 35 | + - name: Resolve version |
| 36 | + id: version |
| 37 | + env: |
| 38 | + GH_TOKEN: ${{ github.token }} |
| 39 | + run: | |
| 40 | + set -euo pipefail |
| 41 | + version="$(bash tool/ci/apple-runtime-version.sh)" |
| 42 | + tag="apple-runtime-v${version}" |
| 43 | + echo "version=${version}" >> "$GITHUB_OUTPUT" |
| 44 | + echo "tag=${tag}" >> "$GITHUB_OUTPUT" |
| 45 | + echo "TugboatCaptureRuntime version: ${version}" |
| 46 | + if bash tool/ci/cocoapods-pod-has-version.sh "${version}"; then |
| 47 | + echo "CocoaPods trunk already has TugboatCaptureRuntime ${version}." |
| 48 | + echo "should_publish=false" >> "$GITHUB_OUTPUT" |
| 49 | + exit 0 |
| 50 | + fi |
| 51 | + echo "should_publish=true" >> "$GITHUB_OUTPUT" |
| 52 | + - name: Create tag and dispatch publish |
| 53 | + if: steps.version.outputs.should_publish == 'true' |
| 54 | + env: |
| 55 | + GH_TOKEN: ${{ github.token }} |
| 56 | + VERSION: ${{ steps.version.outputs.version }} |
| 57 | + TAG: ${{ steps.version.outputs.tag }} |
| 58 | + run: | |
| 59 | + set -euo pipefail |
| 60 | + git fetch --tags origin |
| 61 | + if git rev-parse "refs/tags/${TAG}" >/dev/null 2>&1; then |
| 62 | + echo "Tag ${TAG} already exists." |
| 63 | + else |
| 64 | + git config user.name "github-actions[bot]" |
| 65 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 66 | + git tag -a "${TAG}" -m "TugboatCaptureRuntime ${VERSION}" |
| 67 | + git push origin "${TAG}" |
| 68 | + fi |
| 69 | + for attempt in 1 2 3 4 5 6 7 8; do |
| 70 | + if gh workflow run publish-apple.yml --ref "${TAG}"; then |
| 71 | + echo "Dispatched publish-apple.yml on ${TAG}." |
| 72 | + exit 0 |
| 73 | + fi |
| 74 | + echo "Dispatch failed (attempt ${attempt}); waiting for tag/workflow to appear." |
| 75 | + sleep 5 |
| 76 | + done |
| 77 | + echo "::error::Could not dispatch publish-apple.yml on ${TAG}." |
| 78 | + exit 1 |
| 79 | +
|
| 80 | + publish: |
| 81 | + if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/apple-runtime-v') |
| 82 | + runs-on: macos-latest |
| 83 | + permissions: |
| 84 | + contents: read |
| 85 | + steps: |
| 86 | + - name: Checkout |
| 87 | + uses: actions/checkout@v4 |
| 88 | + - name: Verify version |
| 89 | + id: version |
| 90 | + run: | |
| 91 | + set -euo pipefail |
| 92 | + version="$(bash tool/ci/apple-runtime-version.sh)" |
| 93 | + echo "version=${version}" >> "$GITHUB_OUTPUT" |
| 94 | + if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then |
| 95 | + echo "Publishing TugboatCaptureRuntime ${version} from workflow_dispatch." |
| 96 | + exit 0 |
| 97 | + fi |
| 98 | + expected_tag="apple-runtime-v${version}" |
| 99 | + if [[ "${GITHUB_REF_NAME}" != "${expected_tag}" ]]; then |
| 100 | + echo "::error::Git tag ${GITHUB_REF_NAME} must be ${expected_tag} to publish TugboatCaptureRuntime ${version}." |
| 101 | + exit 1 |
| 102 | + fi |
| 103 | + - name: Lint podspec |
| 104 | + run: bash tool/ci/lint-apple-runtime.sh |
| 105 | + - name: Publish to CocoaPods trunk |
| 106 | + env: |
| 107 | + VERSION: ${{ steps.version.outputs.version }} |
| 108 | + COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN }} |
| 109 | + run: | |
| 110 | + set -euo pipefail |
| 111 | + if [[ -z "${COCOAPODS_TRUNK_TOKEN}" ]]; then |
| 112 | + echo "COCOAPODS_TRUNK_TOKEN is not configured. Skipping trunk publish." |
| 113 | + echo "Create a CocoaPods trunk session and add the token as a repository secret." |
| 114 | + exit 0 |
| 115 | + fi |
| 116 | + if bash tool/ci/cocoapods-pod-has-version.sh "${VERSION}"; then |
| 117 | + echo "TugboatCaptureRuntime ${VERSION} is already on CocoaPods trunk." |
| 118 | + exit 0 |
| 119 | + fi |
| 120 | + pod trunk push TugboatCaptureRuntime.podspec --allow-warnings --verbose |
| 121 | +
|
| 122 | + pin_flutter: |
| 123 | + if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/apple-runtime-v') |
| 124 | + needs: publish |
| 125 | + runs-on: ubuntu-latest |
| 126 | + permissions: |
| 127 | + contents: write |
| 128 | + pull-requests: write |
| 129 | + steps: |
| 130 | + - name: Checkout |
| 131 | + uses: actions/checkout@v4 |
| 132 | + with: |
| 133 | + fetch-depth: 0 |
| 134 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 135 | + - name: Open Flutter Apple pin PR |
| 136 | + env: |
| 137 | + GH_TOKEN: ${{ github.token }} |
| 138 | + run: bash tool/ci/open-flutter-apple-pin-pr.sh |
0 commit comments