|
| 1 | +name: Mobile-CI |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + branch: |
| 7 | + description: "Branch to build" |
| 8 | + required: true |
| 9 | + default: "main" |
| 10 | + workflow_id: |
| 11 | + description: "Codemagic workflow ID" |
| 12 | + required: true |
| 13 | + default: "ios-workflow" |
| 14 | + type: choice |
| 15 | + options: |
| 16 | + - ios-workflow |
| 17 | + - android-workflow |
| 18 | + |
| 19 | +env: |
| 20 | + CODEMAGIC_API_TOKEN: ${{ secrets.CODEMAGIC_API_TOKEN }} |
| 21 | + APP_ID: "6731d2f427e7c816080c3674" |
| 22 | + |
| 23 | +jobs: |
| 24 | + trigger-mobile-build: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + steps: |
| 27 | + - name: Trigger Codemagic Build |
| 28 | + id: trigger_build |
| 29 | + run: | |
| 30 | + RESPONSE=$(curl -X POST \ |
| 31 | + --header "Content-Type: application/json" \ |
| 32 | + --header "x-auth-token: $CODEMAGIC_API_TOKEN" \ |
| 33 | + --data '{ |
| 34 | + "appId": "${{ env.APP_ID }}", |
| 35 | + "workflowId": "${{ github.event.inputs.workflow_id }}", |
| 36 | + "branch": "${{ github.event.inputs.branch }}" |
| 37 | + }' \ |
| 38 | + https://api.codemagic.io/builds) |
| 39 | +
|
| 40 | + BUILD_ID=$(echo $RESPONSE | jq -r '.buildId') |
| 41 | + echo "build_id=$BUILD_ID" >> $GITHUB_OUTPUT |
| 42 | + echo "build_id=$BUILD_ID" |
| 43 | +
|
| 44 | + - name: Wait for build and check status |
| 45 | + id: check_status |
| 46 | + run: | |
| 47 | + while true; do |
| 48 | + RESPONSE=$(curl -X GET \ |
| 49 | + --header "Content-Type: application/json" \ |
| 50 | + --header "x-auth-token: $CODEMAGIC_API_TOKEN" \ |
| 51 | + https://api.codemagic.io/builds/${{ steps.trigger_build.outputs.build_id }}) |
| 52 | +
|
| 53 | + STATUS=$(echo $RESPONSE | jq -r '.build.status') |
| 54 | +
|
| 55 | + if [ "$STATUS" = "finished" ]; then |
| 56 | + SUCCESS=$(echo $RESPONSE | jq -r '.success') |
| 57 | + BUILD_URL=$(echo $RESPONSE | jq -r '.buildUrl') |
| 58 | + echo "status=$STATUS" >> $GITHUB_OUTPUT |
| 59 | + echo "success=$SUCCESS" >> $GITHUB_OUTPUT |
| 60 | + echo "build_url=$BUILD_URL" >> $GITHUB_OUTPUT |
| 61 | + break |
| 62 | + elif [ "$STATUS" = "failed" ]; then |
| 63 | + echo "status=failed" >> $GITHUB_OUTPUT |
| 64 | + break |
| 65 | + fi |
| 66 | +
|
| 67 | + sleep 60 |
| 68 | + done |
| 69 | +
|
| 70 | + - name: Slack Notification |
| 71 | + uses: 8398a7/action-slack@v3 |
| 72 | + if: always() |
| 73 | + with: |
| 74 | + status: ${{ steps.check_status.outputs.success == 'true' && 'success' || 'failure' }} |
| 75 | + fields: repo,message,commit,author,action,eventName,ref,workflow,job,took |
| 76 | + text: | |
| 77 | + Mobile CI Build Result |
| 78 | + Branch: ${{ github.event.inputs.branch }} |
| 79 | + Workflow: ${{ github.event.inputs.workflow_id }} |
| 80 | + Build URL: ${{ steps.check_status.outputs.build_url }} |
| 81 | + env: |
| 82 | + SLACK_WEBHOOK_URL: ${{ secrets.RELEASE_SLACK_WEBHOOK }} |
0 commit comments