fix(ci): bitrise.yml 동기화 잡의 응답 파싱 오류 수정 #42
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: Bitrise Trigger | |
| # Picke's Workspace 의 Bitrise 앱(cc46a893)은 GitHub OAuth 연결이 없어 | |
| # 수신 webhook 을 못 쓴다(UID already taken). 그래서 이 Action 이 push/tag/PR 시 | |
| # Bitrise build API 를 직접 호출해 파이프라인을 트리거한다. | |
| on: | |
| push: | |
| branches: | |
| - develop | |
| - 'release-stg-*' | |
| tags: | |
| - 'v*' | |
| pull_request: | |
| branches: | |
| - '*' | |
| jobs: | |
| # Bitrise 앱은 저장소가 아니라 bitrise.io 에 저장된 bitrise.yml 을 실행한다. | |
| # 그래서 저장소의 bitrise.yml 을 고쳐 push 해도 CI 에 반영되지 않는다(2026-07-30 확인). | |
| # UI 에서 "repository 의 bitrise.yml 사용" 으로 바꾸기 전까지, push 마다 저장본을 | |
| # 저장소 내용으로 덮어써 둘을 강제로 일치시킨다. | |
| # PR 에서는 돌리지 않는다 — 머지되지 않은 CI 설정이 전체에 적용되면 안 된다. | |
| sync-config: | |
| if: github.event_name == 'push' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Sync bitrise.yml to Bitrise | |
| env: | |
| BITRISE_TOKEN: ${{ secrets.BITRISE_API_TOKEN }} | |
| APP_SLUG: cc46a893-15b6-40b5-a5ea-2cbb4948c4ec | |
| run: | | |
| set -euo pipefail | |
| python3 -c "import json;print(json.dumps({'app_config_datastore_yaml':open('bitrise.yml').read()}))" > /tmp/payload.json | |
| curl -fsSL -X POST "https://api.bitrise.io/v0.1/apps/${APP_SLUG}/bitrise.yml" \ | |
| -H "Authorization: ${BITRISE_TOKEN}" \ | |
| -H "Content-Type: application/json" \ | |
| --data-binary @/tmp/payload.json \ | |
| -o /tmp/resp.json | |
| # 검증 경고가 있으면 드러낸다(설정이 조용히 깨진 채 배포되는 것 방지). | |
| # 업로드는 위 curl 로 이미 끝났으므로, 이 출력이 실패해도 잡을 죽이지 않는다. | |
| python3 - <<'PY' || echo "⚠️ 응답 파싱 실패(업로드 자체는 성공)" | |
| import json | |
| # warnings 키가 있으면서 값이 null 인 응답이 실제로 온다 → get 의 기본값이 안 먹는다. | |
| d = json.load(open("/tmp/resp.json")) or {} | |
| w = (d.get("warnings") or {}).get("config") or [] | |
| if w: | |
| print("⚠️ Bitrise 설정 경고:") | |
| for x in w: | |
| print(" -", x) | |
| else: | |
| print("✅ bitrise.yml 동기화 완료 — 경고 없음") | |
| PY | |
| trigger: | |
| runs-on: ubuntu-latest | |
| # 동기화가 끝난 뒤 트리거해야 새 설정으로 빌드된다. PR 에서는 sync-config 가 | |
| # skip 되므로 always() 로 그대로 진행시킨다. | |
| needs: [sync-config] | |
| if: always() && (needs.sync-config.result == 'success' || needs.sync-config.result == 'skipped') | |
| steps: | |
| - name: Trigger Bitrise pipeline | |
| env: | |
| BITRISE_TOKEN: ${{ secrets.BITRISE_API_TOKEN }} | |
| APP_SLUG: cc46a893-15b6-40b5-a5ea-2cbb4948c4ec | |
| # 값은 env 로 전달(직접 ${{ }} 보간 시 커밋메시지 셸 인젝션 위험 방지) | |
| EVENT_NAME: ${{ github.event_name }} | |
| REF_TYPE: ${{ github.ref_type }} | |
| REF_NAME: ${{ github.ref_name }} | |
| HEAD_REF: ${{ github.head_ref }} | |
| PR_NUMBER: ${{ github.event.number }} | |
| COMMIT_HASH: ${{ github.sha }} | |
| PUSH_MSG: ${{ github.event.head_commit.message }} | |
| PR_TITLE: ${{ github.event.pull_request.title }} | |
| run: | | |
| set -euo pipefail | |
| # 페이로드는 단일 jq 호출로 구성. commit_message 는 제목(첫 줄)만 사용 — | |
| # 멀티라인/제어문자로 JSON 이 깨지는 것을 방지(Bitrise UI 는 제목을 표시). | |
| if [ "$EVENT_NAME" = "pull_request" ]; then | |
| PIPELINE="run-tests" | |
| PAYLOAD=$(jq -nc \ | |
| --arg branch "$HEAD_REF" --argjson pr "${PR_NUMBER:-0}" \ | |
| --arg pipeline "$PIPELINE" --arg msg "$(printf '%s' "$PR_TITLE" | head -n1)" --arg hash "$COMMIT_HASH" \ | |
| '{hook_info:{type:"bitrise"}, build_params:{branch:$branch, pull_request_id:$pr, pipeline_id:$pipeline, commit_message:$msg, commit_hash:$hash}}') | |
| elif [ "$REF_TYPE" = "tag" ]; then | |
| PIPELINE="deploy-live" | |
| PAYLOAD=$(jq -nc \ | |
| --arg tag "$REF_NAME" --arg pipeline "$PIPELINE" \ | |
| --arg msg "$(printf '%s' "$PUSH_MSG" | head -n1)" --arg hash "$COMMIT_HASH" \ | |
| '{hook_info:{type:"bitrise"}, build_params:{tag:$tag, pipeline_id:$pipeline, commit_message:$msg, commit_hash:$hash}}') | |
| else | |
| PIPELINE="deploy-stg" | |
| PAYLOAD=$(jq -nc \ | |
| --arg branch "$REF_NAME" --arg pipeline "$PIPELINE" \ | |
| --arg msg "$(printf '%s' "$PUSH_MSG" | head -n1)" --arg hash "$COMMIT_HASH" \ | |
| '{hook_info:{type:"bitrise"}, build_params:{branch:$branch, pipeline_id:$pipeline, commit_message:$msg, commit_hash:$hash}}') | |
| fi | |
| echo "▶ Bitrise 트리거: $PIPELINE" | |
| curl -fsSL -X POST "https://api.bitrise.io/v0.1/apps/${APP_SLUG}/builds" \ | |
| -H "Authorization: ${BITRISE_TOKEN}" \ | |
| -H "Content-Type: application/json" \ | |
| -d "$PAYLOAD" \ | |
| | python3 -c "import sys,json;d=json.load(sys.stdin);print('build #',d.get('build_number'),d.get('build_url',''))" |