GitHub Actions テンプレート
本プラグインにはすぐに使える GitHub Actions ワークフローテンプレートが 2 種類同梱されています。どちらも /deploygate:ci-setup で GitHub Actions を選ぶと .github/workflows/ に配置されます。
必要なシークレット
GitHub リポジトリの Settings → Secrets and variables → Actions で設定します。
| シークレット | 説明 |
|---|---|
DEPLOYGATE_API_TOKEN | プロジェクト API キー(https://deploygate.com/organizations/{PROJECT_NAME}/settings/api_key)。個人トークンではなくプロジェクトキーを使い、CI が個人に依存しないようにします |
DEPLOYGATE_OWNER_NAME | DeployGate のプロジェクト(organization)名 |
iOS ビルドの場合は追加で以下も必要です。
| シークレット | 説明 |
|---|---|
BUILD_CERTIFICATE_BASE64 | .p12 証明書(base64 エンコード) |
P12_PASSWORD | .p12 証明書のパスワード |
KEYCHAIN_PASSWORD | CI 用キーチェーンの任意のパスワード |
ASC_KEY_ID | App Store Connect API Key ID |
ASC_ISSUER_ID | App Store Connect Issuer ID |
ASC_KEY_BASE64 | App Store Connect API Key の .p8(base64 エンコード) |
deploygate-upload.yml
main ブランチへの push ごとに DeployGate へアップロードします。
on:
push:
branches: [main]
テンプレート内には Android と iOS の例がコメントアウトで記載されています。プロジェクトに合う方を有効化して以下をカスタマイズしてください。
- Runner: Android は
ubuntu-latest、iOS はmacos-latest - ビルドステップ: プレースホルダの
echoを実際のビルドコマンドに置き換える - ファイルパス:
file_pathをビルド成果物のパスに書き換える
Android は DeployGate/deploygate-upload-github-action を直接使います。
- name: Upload to DeployGate
uses: DeployGate/deploygate-upload-github-action@v1.1.1
with:
api_token: ${{ secrets.DEPLOYGATE_API_TOKEN }}
owner_name: ${{ secrets.DEPLOYGATE_OWNER_NAME }}
file_path: app/build/outputs/apk/debug/app-debug.apk
message: "${{ github.ref_name }} (${{ github.sha }})"
distribution_name: "Development"
release_note: "${{ github.event.head_commit.message }}"
iOS + Instant Device 用のシミュレータ zip は、GitHub Action が ios_simulator_zip 入力に対応していないため curl で直接アップロードします。
- name: Upload to DeployGate (iOS with simulator zip)
run: |
curl --fail-with-body -s -X POST \
-H "Authorization: Bearer ${{ secrets.DEPLOYGATE_API_TOKEN }}" \
-F "file=@${{ runner.temp }}/MyApp.ipa" \
-F "ios_simulator_zip=@${{ runner.temp }}/MyApp-simulator.zip" \
-F "message=${{ github.ref_name }} (${{ github.sha }})" \
-F "distribution_name=Development" \
"https://deploygate.com/api/users/${{ secrets.DEPLOYGATE_OWNER_NAME }}/apps"
テンプレートには、xcodebuild archive の前段として必要なキーチェーン/App Store Connect API キーの準備手順、および完了時にキーチェーンを削除するクリーンアップ手順も含まれています。
deploygate-pr.yml
プルリクエストごとに配布ページを作成し、push のたびに更新し、PR クローズ時に削除します。
on:
pull_request:
types: [opened, synchronize, closed]
permissions:
contents: read
pull-requests: write
deployments: write
挙動:
opened/synchronizeで アプリをビルドしてアップロード。初回アップロードではPR #<N>: <PR title>というタイトルで新規配布ページが作成されます。以降の push では、PR コメントに隠しマーカー(<!-- deploygate:access_key=... -->)として埋め込まれた配布ページのaccess_keyを読み取り、アップロード時にdistribution_keyフォームパラメータとして渡すことで、同じページを再利用します。- コメント — 配布ページ URL と QR コード(
https://deploygate.com/qrで生成)を含む PR コメントを作成または更新します。PC からは Instant Device でプレビュー、スマホからは QR で直接インストールが可能です。 - タイトル同期 — push 間で PR タイトルが変わった場合は、配布ページタイトルも追随して更新します(
activeとrelease_scopeは現状値を保持)。 - GitHub Deployment — 配布 URL を environment URL とする
deploygateenvironment のデプロイメントを作成し、PR タイムラインに environment 情報が表示されるようにします。 closedで —DELETE /api/distributions/{access_key}で配布ページを削除します。アップロード済みバイナリは保持されます。
アップロードステップは、任意の ios_simulator_zip 添付にも対応できるよう、GitHub Action ではなく curl を使います。
- name: Upload to DeployGate
id: upload
shell: bash
run: |
ARGS=(--fail-with-body -s -X POST \
-H "Authorization: Bearer ${{ secrets.DEPLOYGATE_API_TOKEN }}" \
-F "file=@${{ runner.temp }}/MyApp.ipa" \
-F "message=PR #${{ github.event.pull_request.number }} (${{ github.sha }})" \
-F "release_note=${{ github.event.pull_request.title }}")
if [ -f "${{ runner.temp }}/MyApp-simulator.zip" ]; then
ARGS+=(-F "ios_simulator_zip=@${{ runner.temp }}/MyApp-simulator.zip")
fi
DIST_KEY="${{ steps.find-key.outputs.distribution_key }}"
if [ -n "$DIST_KEY" ]; then
ARGS+=(-F "distribution_key=$DIST_KEY")
else
ARGS+=(-F "distribution_name=PR #${{ github.event.pull_request.number }}: ${{ github.event.pull_request.title }}")
fi
RESPONSE=$(curl "${ARGS[@]}" \
"https://deploygate.com/api/users/${{ secrets.DEPLOYGATE_OWNER_NAME }}/apps")
ios_simulator_zip を使わない Android プロジェクトでは、テンプレートのコメントアウト部分に DeployGate/deploygate-upload-github-action を直接使う簡潔な代替も示されています(ただしシミュレータ zip 入力には非対応)。
カスタマイズチェックリスト
/deploygate:ci-setup でテンプレートを配置した後、マージ前に以下を確認してください。
- リポジトリシークレットを上表のとおり設定した
- iOS ビルドの場合、runner を
macos-latestに変更した - ビルドステップを実際のビルドコマンドに置き換えた
-
file_pathがビルド成果物のパスになっている - iOS の場合:
-scheme/DEVELOPMENT_TEAM、および既存のMatchfile/ fastlane 設定と整合させた -
push.branchesのブランチ名がデフォルトブランチと一致している(初期値main)
関連
/deploygate:ci-setup— これらのテンプレートを導入するスキル- DeployGate Upload GitHub Action — Android の例で利用している元 Action