-
Notifications
You must be signed in to change notification settings - Fork 0
114 lines (110 loc) · 5.91 KB
/
Copy pathbitrise-trigger.yml
File metadata and controls
114 lines (110 loc) · 5.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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"
# -f 는 4xx 본문을 버려서 Bitrise 가 알려준 거절 이유가 사라진다. 그러면
# 뒤이은 파싱만 JSONDecodeError 로 죽고 원인은 로그에 안 남는다(run 30545402690).
# 상태코드와 본문을 함께 남기고, 실패 시 본문·페이로드를 그대로 노출한다.
http=$(curl -sS -o /tmp/build_resp.json -w '%{http_code}' \
-X POST "https://api.bitrise.io/v0.1/apps/${APP_SLUG}/builds" \
-H "Authorization: ${BITRISE_TOKEN}" \
-H "Content-Type: application/json" \
-d "$PAYLOAD")
if [ "$http" != "200" ] && [ "$http" != "201" ]; then
echo "❌ Bitrise 트리거 실패 (HTTP $http)"
echo "--- 응답 ---"; cat /tmp/build_resp.json; echo
echo "--- 보낸 페이로드 ---"; echo "$PAYLOAD"
exit 1
fi
python3 -c "import json;d=json.load(open('/tmp/build_resp.json'));print('build #',d.get('build_number'),d.get('build_url',''))"