-
Notifications
You must be signed in to change notification settings - Fork 24
ci: resolve build number from TestFlight API instead of run number #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
f0e5661
8bf5e24
6b7b1de
316b15b
9373bc4
fe2109b
0145ba3
c0ea9ab
503e974
673ce6e
63df015
b9a57d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,22 +10,54 @@ permissions: | |
|
|
||
| jobs: | ||
| prepare: | ||
| name: Parse tag version | ||
| name: Parse tag and resolve build number | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| version: ${{ steps.parse.outputs.version }} | ||
| build-number: ${{ steps.tfbuild.outputs.build-number }} | ||
| steps: | ||
| - name: Strip v prefix from tag | ||
| id: parse | ||
| run: | | ||
| TAG="${GITHUB_REF_NAME}" | ||
| echo "version=${TAG#v}" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Resolve build number from TestFlight | ||
| id: tfbuild | ||
| env: | ||
| API_KEY_BASE64: ${{ secrets.APP_STORE_CONNECT_PRIVATE_KEY }} | ||
| API_KEY_ID: ${{ secrets.APP_STORE_CONNECT_KEY_ID }} | ||
| API_ISSUER_ID: ${{ secrets.APP_STORE_CONNECT_ISSUER_ID }} | ||
| APP_ID: ${{ vars.APP_STORE_APP_ID_IOS }} | ||
| VERSION: ${{ steps.parse.outputs.version }} | ||
| run: | | ||
| KEY_FILE=$(mktemp) | ||
| echo "$API_KEY_BASE64" | base64 --decode > "$KEY_FILE" | ||
|
|
||
| NOW=$(date +%s) | ||
| EXP=$((NOW + 1200)) | ||
| HEADER=$(printf '{"alg":"ES256","kid":"%s","typ":"JWT"}' "$API_KEY_ID" | base64 -w 0 | tr -d '=' | tr '+/' '-_') | ||
| PAYLOAD=$(printf '{"iss":"%s","iat":%d,"exp":%d,"aud":"appstoreconnect-v1"}' "$API_ISSUER_ID" "$NOW" "$EXP" | base64 -w 0 | tr -d '=' | tr '+/' '-_') | ||
| SIGNATURE=$(printf '%s.%s' "$HEADER" "$PAYLOAD" | openssl dgst -binary -sha256 -sign "$KEY_FILE" | base64 -w 0 | tr -d '=' | tr '+/' '-_') | ||
| JWT="${HEADER}.${PAYLOAD}.${SIGNATURE}" | ||
| rm -f "$KEY_FILE" | ||
|
|
||
| RESPONSE=$(curl -sf \ | ||
| -H "Authorization: Bearer $JWT" \ | ||
| "https://api.appstoreconnect.apple.com/v1/builds?filter[app]=${APP_ID}&filter[preReleaseVersion.version]=${VERSION}&sort=-version&limit=1&fields[builds]=version" \ | ||
| || echo '{}') | ||
|
|
||
| LATEST=$(echo "$RESPONSE" | jq -r '.data[0].attributes.version // "0"') | ||
| NEXT=$((LATEST + 1)) | ||
| echo "build-number=$NEXT" >> "$GITHUB_OUTPUT" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set +e
echo "Without --globoff:"
curl -sS -o /dev/null 'https://example.invalid/v1/builds?filter[app]=123' 2>&1
echo "exit=$?"
echo
echo "With --globoff:"
curl --globoff -sS -o /dev/null --connect-timeout 1 'https://example.invalid/v1/builds?filter[app]=123' 2>&1
echo "exit=$?"Repository: netbirdio/ios-client Length of output: 296 🏁 Script executed: cat -n .github/workflows/release.yml | sed -n '40,60p'Repository: netbirdio/ios-client Length of output: 1264 Do not mask TestFlight lookup failures as build number The URL contains 🛠️ Proposed fix to fail closed and disable curl globbing- RESPONSE=$(curl -sf \
+ RESPONSE=$(curl --globoff -fsS \
-H "Authorization: Bearer $JWT" \
"https://api.appstoreconnect.apple.com/v1/builds?filter[app]=${APP_ID}&filter[preReleaseVersion.version]=${VERSION}&sort=-version&limit=1&fields[builds]=version" \
- || echo '{}')
+ )
- LATEST=$(echo "$RESPONSE" | jq -r '.data[0].attributes.version // "0"')
+ LATEST=$(jq -r '.data[0].attributes.version // "0"' <<< "$RESPONSE")
+ if ! [[ "$LATEST" =~ ^[0-9]+$ ]]; then
+ echo "::error::Latest TestFlight build number is not numeric: '$LATEST'"
+ exit 1
+ fi
NEXT=$((LATEST + 1))🤖 Prompt for AI Agents |
||
| echo "Latest build for $VERSION: $LATEST → next: $NEXT" | ||
|
|
||
| build: | ||
| name: Build and Upload Release | ||
| needs: prepare | ||
| uses: ./.github/workflows/build-upload.yml | ||
| with: | ||
| ref: ${{ github.ref }} | ||
| version: ${{ needs.prepare.outputs.version }} | ||
| build-number: ${{ needs.prepare.outputs.build-number }} | ||
| secrets: inherit | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -39,15 +39,14 @@ jobs: | |||||||||||||||||||||||||||||||||||||||||
| uses: actions/github-script@v7 | ||||||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||||||
| script: | | ||||||||||||||||||||||||||||||||||||||||||
| core.setOutput('build-number', '${{ github.run_number }}'); | ||||||||||||||||||||||||||||||||||||||||||
| core.setOutput('should-build', 'false'); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| function parseCommand(body) { | ||||||||||||||||||||||||||||||||||||||||||
| const line = body.split('\n').find(l => l.trim().startsWith('/testflight')) || ''; | ||||||||||||||||||||||||||||||||||||||||||
| const versionMatch = line.match(/version=([0-9]+\.[0-9]+\.[0-9]+)/); | ||||||||||||||||||||||||||||||||||||||||||
| if (versionMatch) core.setOutput('version-override', versionMatch[1]); | ||||||||||||||||||||||||||||||||||||||||||
| const buildMatch = line.match(/build-number=([0-9]+)/); | ||||||||||||||||||||||||||||||||||||||||||
| if (buildMatch) core.setOutput('build-number', buildMatch[1]); | ||||||||||||||||||||||||||||||||||||||||||
| if (buildMatch) core.setOutput('build-number-override', buildMatch[1]); | ||||||||||||||||||||||||||||||||||||||||||
| const netbirdMatch = line.match(/netbird-ref=([a-zA-Z0-9._\/-]+)/); | ||||||||||||||||||||||||||||||||||||||||||
| if (netbirdMatch) core.setOutput('netbird-ref', netbirdMatch[1]); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -149,6 +148,41 @@ jobs: | |||||||||||||||||||||||||||||||||||||||||
| echo "version=$NEXT" >> "$GITHUB_OUTPUT" | ||||||||||||||||||||||||||||||||||||||||||
| echo "Tag: $LATEST_TAG → next: $NEXT" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| - name: Resolve build number from TestFlight | ||||||||||||||||||||||||||||||||||||||||||
| id: tfbuild | ||||||||||||||||||||||||||||||||||||||||||
| if: steps.pre.outputs.should-build == 'true' && steps.pre.outputs.build-number-override == '' | ||||||||||||||||||||||||||||||||||||||||||
| env: | ||||||||||||||||||||||||||||||||||||||||||
| API_KEY_BASE64: ${{ secrets.APP_STORE_CONNECT_PRIVATE_KEY }} | ||||||||||||||||||||||||||||||||||||||||||
| API_KEY_ID: ${{ secrets.APP_STORE_CONNECT_KEY_ID }} | ||||||||||||||||||||||||||||||||||||||||||
| API_ISSUER_ID: ${{ secrets.APP_STORE_CONNECT_ISSUER_ID }} | ||||||||||||||||||||||||||||||||||||||||||
| APP_ID: ${{ vars.APP_STORE_APP_ID_IOS }} | ||||||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||||||
| VERSION="${{ steps.pre.outputs.version-override }}" | ||||||||||||||||||||||||||||||||||||||||||
| if [ -z "$VERSION" ]; then | ||||||||||||||||||||||||||||||||||||||||||
| VERSION="${{ steps.derive.outputs.version }}" | ||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| KEY_FILE=$(mktemp) | ||||||||||||||||||||||||||||||||||||||||||
| echo "$API_KEY_BASE64" | base64 --decode > "$KEY_FILE" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| NOW=$(date +%s) | ||||||||||||||||||||||||||||||||||||||||||
| EXP=$((NOW + 1200)) | ||||||||||||||||||||||||||||||||||||||||||
| HEADER=$(printf '{"alg":"ES256","kid":"%s","typ":"JWT"}' "$API_KEY_ID" | base64 -w 0 | tr -d '=' | tr '+/' '-_') | ||||||||||||||||||||||||||||||||||||||||||
| PAYLOAD=$(printf '{"iss":"%s","iat":%d,"exp":%d,"aud":"appstoreconnect-v1"}' "$API_ISSUER_ID" "$NOW" "$EXP" | base64 -w 0 | tr -d '=' | tr '+/' '-_') | ||||||||||||||||||||||||||||||||||||||||||
| SIGNATURE=$(printf '%s.%s' "$HEADER" "$PAYLOAD" | openssl dgst -binary -sha256 -sign "$KEY_FILE" | base64 -w 0 | tr -d '=' | tr '+/' '-_') | ||||||||||||||||||||||||||||||||||||||||||
| JWT="${HEADER}.${PAYLOAD}.${SIGNATURE}" | ||||||||||||||||||||||||||||||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||||||||||||||||||||||
| rm -f "$KEY_FILE" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| RESPONSE=$(curl -sf \ | ||||||||||||||||||||||||||||||||||||||||||
| -H "Authorization: Bearer $JWT" \ | ||||||||||||||||||||||||||||||||||||||||||
| "https://api.appstoreconnect.apple.com/v1/builds?filter[app]=${APP_ID}&filter[preReleaseVersion.version]=${VERSION}&sort=-version&limit=1&fields[builds]=version" \ | ||||||||||||||||||||||||||||||||||||||||||
| || echo '{}') | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| LATEST=$(echo "$RESPONSE" | jq -r '.data[0].attributes.version // "0"') | ||||||||||||||||||||||||||||||||||||||||||
| NEXT=$((LATEST + 1)) | ||||||||||||||||||||||||||||||||||||||||||
| echo "build-number=$NEXT" >> "$GITHUB_OUTPUT" | ||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set +e
echo "Without --globoff:"
curl -sS -o /dev/null 'https://example.invalid/v1/builds?filter[app]=123' 2>&1
echo "exit=$?"
echo
echo "With --globoff:"
curl --globoff -sS -o /dev/null --connect-timeout 1 'https://example.invalid/v1/builds?filter[app]=123' 2>&1
echo "exit=$?"Repository: netbirdio/ios-client Length of output: 296 Add The URL contains square brackets ( Proposed fix- RESPONSE=$(curl -sf \
+ RESPONSE=$(curl --globoff -fsS \
-H "Authorization: Bearer $JWT" \
"https://api.appstoreconnect.apple.com/v1/builds?filter[app]=${APP_ID}&filter[preReleaseVersion.version]=${VERSION}&sort=-version&limit=1&fields[builds]=version" \
- || echo '{}')
+ )
- LATEST=$(echo "$RESPONSE" | jq -r '.data[0].attributes.version // "0"')
+ LATEST=$(jq -r '.data[0].attributes.version // "0"' <<< "$RESPONSE")
+ if ! [[ "$LATEST" =~ ^[0-9]+$ ]]; then
+ echo "::error::Latest TestFlight build number is not numeric: '$LATEST'"
+ exit 1
+ fi
NEXT=$((LATEST + 1))📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
| echo "Latest build for $VERSION: $LATEST → next: $NEXT" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| - name: Finalize outputs | ||||||||||||||||||||||||||||||||||||||||||
| id: finalize | ||||||||||||||||||||||||||||||||||||||||||
| uses: actions/github-script@v7 | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -157,9 +191,15 @@ jobs: | |||||||||||||||||||||||||||||||||||||||||
| core.setOutput('ref', '${{ steps.pre.outputs.ref }}'); | ||||||||||||||||||||||||||||||||||||||||||
| core.setOutput('should-build', '${{ steps.pre.outputs.should-build }}'); | ||||||||||||||||||||||||||||||||||||||||||
| core.setOutput('upload', '${{ steps.pre.outputs.upload }}'); | ||||||||||||||||||||||||||||||||||||||||||
| core.setOutput('build-number', '${{ steps.pre.outputs.build-number }}'); | ||||||||||||||||||||||||||||||||||||||||||
| core.setOutput('netbird-ref', '${{ steps.pre.outputs.netbird-ref }}'); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const buildNumber = | ||||||||||||||||||||||||||||||||||||||||||
| '${{ steps.pre.outputs.build-number-override }}' || | ||||||||||||||||||||||||||||||||||||||||||
| '${{ steps.tfbuild.outputs.build-number }}' || | ||||||||||||||||||||||||||||||||||||||||||
| '${{ github.run_number }}'; | ||||||||||||||||||||||||||||||||||||||||||
| core.setOutput('build-number', buildNumber); | ||||||||||||||||||||||||||||||||||||||||||
| core.info(`build-number: ${buildNumber}`); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const override = '${{ steps.pre.outputs.version-override }}'; | ||||||||||||||||||||||||||||||||||||||||||
| const derived = '${{ steps.derive.outputs.version }}'; | ||||||||||||||||||||||||||||||||||||||||||
| core.setOutput('version', override || derived); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.