|
| 1 | +name: Publish example app |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + tag: |
| 9 | + description: Release tag to publish the example app for, e.g. v6.0.0 |
| 10 | + required: true |
| 11 | + platform: |
| 12 | + description: Platform to build. Defaults to all. |
| 13 | + required: false |
| 14 | + default: all |
| 15 | + type: choice |
| 16 | + options: |
| 17 | + - all |
| 18 | + - ios |
| 19 | + - android |
| 20 | + |
| 21 | +permissions: |
| 22 | + contents: read |
| 23 | + |
| 24 | +defaults: |
| 25 | + run: |
| 26 | + shell: bash |
| 27 | + |
| 28 | +jobs: |
| 29 | + check: |
| 30 | + name: Check release is on main |
| 31 | + runs-on: ubuntu-latest |
| 32 | + env: |
| 33 | + TAG: ${{ github.event.release.tag_name || inputs.tag }} |
| 34 | + outputs: |
| 35 | + on-main: ${{ steps.check.outputs.on-main }} |
| 36 | + sha: ${{ steps.check.outputs.sha }} |
| 37 | + tag: ${{ env.TAG }} |
| 38 | + profile: ${{ steps.check.outputs.profile }} |
| 39 | + steps: |
| 40 | + - id: check |
| 41 | + env: |
| 42 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 43 | + GH_REPO: ${{ github.repository }} |
| 44 | + run: | |
| 45 | + status=$(gh api "repos/$GH_REPO/compare/main...$TAG" --jq .status) |
| 46 | +
|
| 47 | + if [ "$status" = "identical" ] || [ "$status" = "behind" ]; then |
| 48 | + sha=$(gh api "repos/$GH_REPO/commits/$TAG" --jq .sha) |
| 49 | + echo "on-main=true" >> "$GITHUB_OUTPUT" |
| 50 | + echo "sha=$sha" >> "$GITHUB_OUTPUT" |
| 51 | + else |
| 52 | + echo "on-main=false" >> "$GITHUB_OUTPUT" |
| 53 | + echo "::warning::$TAG is not on main ($status), nothing to deploy." |
| 54 | + echo "$TAG is not on main ($status), nothing to deploy." >> "$GITHUB_STEP_SUMMARY" |
| 55 | + fi |
| 56 | +
|
| 57 | + if [ "${TAG#*-}" != "$TAG" ]; then |
| 58 | + echo "profile=preview" >> "$GITHUB_OUTPUT" |
| 59 | + else |
| 60 | + echo "profile=production" >> "$GITHUB_OUTPUT" |
| 61 | + fi |
| 62 | +
|
| 63 | + publish: |
| 64 | + name: Build and submit example app |
| 65 | + needs: check |
| 66 | + if: needs.check.outputs.on-main == 'true' |
| 67 | + runs-on: ubuntu-latest |
| 68 | + concurrency: |
| 69 | + # One queue per channel, so a pending preview run doesn't cancel a production one |
| 70 | + group: publish-example-app-${{ needs.check.outputs.profile }} |
| 71 | + steps: |
| 72 | + - name: Checkout |
| 73 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 74 | + with: |
| 75 | + ref: ${{ needs.check.outputs.sha }} |
| 76 | + |
| 77 | + - name: Setup |
| 78 | + uses: ./.github/actions/setup |
| 79 | + |
| 80 | + - name: Setup Expo |
| 81 | + uses: expo/expo-github-action@c7b66a9c327a43a8fa7c0158e7f30d6040d2481e # v8.2.1 |
| 82 | + with: |
| 83 | + eas-version: 24.12.1 |
| 84 | + token: ${{ secrets.EXPO_TOKEN }} |
| 85 | + |
| 86 | + - name: Check Expo authentication |
| 87 | + working-directory: ./example |
| 88 | + run: | |
| 89 | + if ! eas whoami; then |
| 90 | + echo "::error::Could not authenticate with Expo, check EXPO_TOKEN." |
| 91 | + exit 1 |
| 92 | + fi |
| 93 | +
|
| 94 | + - name: Set example app version from the release tag |
| 95 | + working-directory: ./example |
| 96 | + env: |
| 97 | + TAG: ${{ needs.check.outputs.tag }} |
| 98 | + run: | |
| 99 | + version="${TAG#v}" |
| 100 | + version="${version%%-*}" |
| 101 | +
|
| 102 | + if ! echo "$version" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then |
| 103 | + echo "::error::Could not read a major.minor.patch version from $TAG." |
| 104 | + exit 1 |
| 105 | + fi |
| 106 | +
|
| 107 | + jq --arg version "$version" '.expo.version = $version' app.json > app.json.tmp |
| 108 | + mv app.json.tmp app.json |
| 109 | +
|
| 110 | + - name: Decide between an update and a build |
| 111 | + id: decide |
| 112 | + working-directory: ./example |
| 113 | + env: |
| 114 | + PROFILE: ${{ needs.check.outputs.profile }} |
| 115 | + PLATFORM: ${{ inputs.platform || 'all' }} |
| 116 | + run: | |
| 117 | + platforms="$PLATFORM" |
| 118 | + if [ "$PLATFORM" = "all" ]; then |
| 119 | + platforms="ios android" |
| 120 | + fi |
| 121 | +
|
| 122 | + build=() |
| 123 | + update=() |
| 124 | + for platform in $platforms; do |
| 125 | + hash=$(npx expo-updates fingerprint:generate --platform "$platform" | jq -er .hash) |
| 126 | +
|
| 127 | + existing=$(eas build:list \ |
| 128 | + --platform "$platform" \ |
| 129 | + --channel "$PROFILE" \ |
| 130 | + --fingerprint-hash "$hash" \ |
| 131 | + --status finished \ |
| 132 | + --limit 1 \ |
| 133 | + --json \ |
| 134 | + --non-interactive | jq 'if type == "array" then length else "notanarray" end') |
| 135 | +
|
| 136 | + case "$existing" in |
| 137 | + ''|*[!0-9]*) |
| 138 | + echo "::error::Could not read builds for $platform." |
| 139 | + exit 1 |
| 140 | + ;; |
| 141 | + esac |
| 142 | +
|
| 143 | + echo "$platform: fingerprint $hash, $existing matching build(s)" |
| 144 | + if [ "$existing" -eq 0 ]; then |
| 145 | + build+=("$platform") |
| 146 | + else |
| 147 | + update+=("$platform") |
| 148 | + fi |
| 149 | + done |
| 150 | +
|
| 151 | + # EAS takes a single platform or "all" |
| 152 | + to_platform() { |
| 153 | + case $# in |
| 154 | + 0) echo "" ;; |
| 155 | + 1) echo "$1" ;; |
| 156 | + *) echo all ;; |
| 157 | + esac |
| 158 | + } |
| 159 | +
|
| 160 | + echo "build=$(to_platform "${build[@]}")" >> "$GITHUB_OUTPUT" |
| 161 | + echo "update=$(to_platform "${update[@]}")" >> "$GITHUB_OUTPUT" |
| 162 | + echo "Building: ${build[*]:-none}. Updating: ${update[*]:-none}." |
| 163 | +
|
| 164 | + - name: Publish an update |
| 165 | + # Before the build, so a slow or timed-out build can't hold up the update |
| 166 | + if: steps.decide.outputs.update != '' |
| 167 | + working-directory: ./example |
| 168 | + env: |
| 169 | + PROFILE: ${{ needs.check.outputs.profile }} |
| 170 | + PLATFORM: ${{ steps.decide.outputs.update }} |
| 171 | + TAG: ${{ needs.check.outputs.tag }} |
| 172 | + run: | |
| 173 | + eas update \ |
| 174 | + --channel "$PROFILE" \ |
| 175 | + --platform "$PLATFORM" \ |
| 176 | + --message "$TAG" \ |
| 177 | + --non-interactive |
| 178 | +
|
| 179 | + echo "Published an OTA update for $TAG for $PLATFORM on the $PROFILE channel." >> "$GITHUB_STEP_SUMMARY" |
| 180 | +
|
| 181 | + - name: Build and submit to the app stores |
| 182 | + # Don't let a failed update for one platform skip the other's build |
| 183 | + if: ${{ !cancelled() && steps.decide.outputs.build != '' }} |
| 184 | + working-directory: ./example |
| 185 | + env: |
| 186 | + PROFILE: ${{ needs.check.outputs.profile }} |
| 187 | + PLATFORM: ${{ steps.decide.outputs.build }} |
| 188 | + TAG: ${{ needs.check.outputs.tag }} |
| 189 | + run: | |
| 190 | + eas build \ |
| 191 | + --platform "$PLATFORM" \ |
| 192 | + --profile "$PROFILE" \ |
| 193 | + --auto-submit-with-profile "$PROFILE" \ |
| 194 | + --non-interactive |
| 195 | +
|
| 196 | + echo "Built and submitted $TAG for $PLATFORM using the $PROFILE profile." >> "$GITHUB_STEP_SUMMARY" |
| 197 | +
|
| 198 | + - name: Report failure |
| 199 | + if: failure() || cancelled() |
| 200 | + env: |
| 201 | + TAG: ${{ needs.check.outputs.tag }} |
| 202 | + run: | |
| 203 | + echo "::error::Example app deployment failed for $TAG. The release itself is fine, only the demo app did not update." |
| 204 | + echo "Check EAS and the stores before re-running, a build may still be running or already submitted. Re-running before it finishes starts a second build." >> "$GITHUB_STEP_SUMMARY" |
| 205 | + echo "If the build finished but the store upload failed, resubmit that build with \`eas submit --id <build id>\`. Re-running this workflow will publish an OTA update instead." >> "$GITHUB_STEP_SUMMARY" |
| 206 | + echo "If only the update failed, re-running is safe." >> "$GITHUB_STEP_SUMMARY" |
0 commit comments