Created
July 17, 2025 10:47
-
-
Save cathandnya/42d8cd20a0226753430a5218367757aa to your computer and use it in GitHub Desktop.
get latest build number from app store connect
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
| #!/bin/bash | |
| set -euo pipefail | |
| # filepath: build_number.sh | |
| # 必要な環境変数: APPSTORE_ISSUER_ID, APPSTORE_KEY_ID, APPSTORE_PRIVATE_KEY, APP_ID | |
| # JWT生成 | |
| EXP=$(( $(date +%s) + 1000 )) | |
| PAYLOAD=$(cat <<EOF | |
| { | |
| "iss": "$APPSTORE_ISSUER_ID", | |
| "exp": $EXP, | |
| "aud": "appstoreconnect-v1" | |
| } | |
| EOF | |
| ) | |
| # key.pemを必ず削除するtrapを設定 | |
| cleanup() { | |
| rm -f key.pem | |
| } | |
| trap cleanup EXIT | |
| echo -n "$APPSTORE_PRIVATE_KEY" | base64 --decode > key.pem | |
| if [ $? -ne 0 ]; then | |
| echo "Failed to decode APPSTORE_PRIVATE_KEY" >&2 | |
| exit 1 | |
| fi | |
| JWT=$(jwt encode --alg ES256 --kid "$APPSTORE_KEY_ID" --secret @key.pem "$PAYLOAD") | |
| # echo "Authorization: Bearer $JWT" | |
| BUILD_NUMBER=$(curl -s -H "Authorization: Bearer $JWT" \ | |
| "https://api.appstoreconnect.apple.com/v1/builds?filter%5Bapp%5D=${APP_ID}&limit=1&sort=-version" \ | |
| | jq -r '.data[0].attributes.version') | |
| if [ -z "$BUILD_NUMBER" ] || [ "$BUILD_NUMBER" = "null" ]; then | |
| echo "0" | |
| else | |
| echo "$BUILD_NUMBER" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment