gowalk-cicd 1.0.183 → 1.0.184

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1225,7 +1225,14 @@ commits completed part transfers with `uploaded: true`, following Apple's
1225
1225
  The IPA endpoint rejected an optional `sourceFileChecksums` SHA_256 object even though
1226
1226
  the generic schema lists that algorithm; the uploader no longer sends that attribute.
1227
1227
  A completed file is reused only when its content-derived filename and size match, and
1228
- any returned file checksum is verified.
1228
+ any returned file checksum is verified. New receipts retain locally computed SHA-256 and
1229
+ MD5 so Apple's returned checksum can be compared with the exact transferred bytes.
1230
+
1231
+ An upload summary can remain `PROCESSING` after Apple exposes a valid eligible build.
1232
+ Completion then requires the unique matching iOS build, marketing version, app and bundle,
1233
+ alongside the completed upload asset and matching checksum. A missing, pending, failed or
1234
+ ambiguous build remains unconfirmed. The receipt retains `upload_resource_state` separately
1235
+ from the verified completion state.
1229
1236
 
1230
1237
  A failed upload emits the typed `apple_build_upload_failed` error annotation with schema
1231
1238
  `gowalk-cicd/apple-build-upload-failed.v2`: `category` (`ipa_invalid`,
@@ -1235,7 +1242,8 @@ A failed upload emits the typed `apple_build_upload_failed` error annotation wit
1235
1242
  the receipt's own identifiers (`cfBundleVersion`, `upload_id`, `file_id`, `state`,
1236
1243
  `provider_status`, `provider_code`, `provider_pointer`). Exception text is never
1237
1244
  published. The job also retains the exact exported IPA as `apple-ipa-<run>-<attempt>`
1238
- (7 days) so a continuation can complete that same upload identity instead of rebuilding
1245
+ (7 days), copied without byte changes to the safe archive member `app.ipa`, so punctuation
1246
+ in the exported filename cannot block retention. A continuation can complete that upload instead of rebuilding
1239
1247
  different bytes under the same number. Build numbers come from `/builds`,
1240
1248
  `/preReleaseVersions` **and** `/apps/{id}/buildUploads`, so an unfinished or refused
1241
1249
  reservation is never reused; delete such a reservation only after reading it back.
package/action/action.yml CHANGED
@@ -825,17 +825,33 @@ runs:
825
825
  # A failed REST upload keeps the exact exported IPA next to its receipt, so a
826
826
  # continuation can resume or complete that same upload identity instead of
827
827
  # rebuilding different bytes under the number the receipt names.
828
- - name: Retain the exported IPA for upload recovery
828
+ - name: Stage the exported IPA for upload recovery
829
+ id: ipa-recovery
829
830
  if: ${{ always() && inputs.archive == 'true' && inputs.upload == 'true'
830
831
  && (steps.upload.outcome != 'success' || inputs.defer-provider-verification == 'true') }}
832
+ shell: bash
833
+ run: |
834
+ shopt -s nullglob
835
+ ipas=("$RUNNER_TEMP"/export/*.ipa)
836
+ if [ "${#ipas[@]}" -ne 1 ]; then
837
+ echo '::error::apple_ipa_recovery_export_count_invalid'
838
+ exit 1
839
+ fi
840
+ retained="$RUNNER_TEMP/apple-ipa-recovery"
841
+ mkdir -p "$retained"
842
+ cp "${ipas[0]}" "$retained/app.ipa"
843
+ cmp -s "${ipas[0]}" "$retained/app.ipa"
844
+
845
+ - name: Retain the exported IPA for upload recovery
846
+ if: ${{ always() && steps.ipa-recovery.outcome == 'success' }}
831
847
  uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4
832
848
  env:
833
849
  NODE_OPTIONS: --require "${{ env.SWIFT_APP_ACTION }}/scripts/artifact_env.cjs"
834
850
  with:
835
851
  name: apple-ipa-${{ github.run_id }}-${{ github.run_attempt }}
836
- path: ${{ runner.temp }}/export/*.ipa
852
+ path: ${{ runner.temp }}/apple-ipa-recovery/app.ipa
837
853
  compression-level: 0 # An IPA is already a ZIP; avoid duplicate compression on the Mac.
838
- if-no-files-found: ignore
854
+ if-no-files-found: error
839
855
  retention-days: 7
840
856
 
841
857
  # The whatsNew backstop. An empty "What's New" makes a version
@@ -24,6 +24,7 @@ function validate(value) {
24
24
  !/^[a-f0-9]{64}$/.test(r.sha256 || '') || r.fileName !== `${r.sha256}.ipa` || !positive(r.fileSize)) {
25
25
  fail('handoff_receipt');
26
26
  }
27
+ if (r.md5 !== undefined && (typeof r.md5 !== 'string' || !/^[a-f0-9]{32}$/.test(r.md5))) fail('handoff_receipt');
27
28
  if (typeof m.enabled !== 'boolean' || typeof m.only_if_empty !== 'boolean' ||
28
29
  typeof m.notes !== 'string' || Buffer.byteLength(m.notes) > 1024 * 1024 || m.notes.includes('\0') ||
29
30
  !/^[A-Za-z0-9-]{2,35}$/.test(m.locale || '') || m.enabled && !id(m.version_id)) fail('handoff_metadata');
@@ -54,7 +54,10 @@ def prepare():
54
54
  def write(path, handoff, receipt):
55
55
  if receipt.get("stage") != "transferred" or "\n" in str(path) or "\r" in str(path):
56
56
  raise ValueError("apple_handoff_transfer_unconfirmed")
57
- handoff = {**handoff, "receipt": {name: receipt[name] for name in FIELDS}}
57
+ fields = {name: receipt[name] for name in FIELDS}
58
+ if "md5" in receipt:
59
+ fields["md5"] = receipt["md5"]
60
+ handoff = {**handoff, "receipt": fields}
58
61
  data = (json.dumps(handoff, sort_keys=True, separators=(",", ":")) + "\n").encode()
59
62
  path.write_bytes(data)
60
63
  digest = hashlib.sha256(data).hexdigest()
@@ -0,0 +1,117 @@
1
+ /* Read-only proof of one transferred IPA, including Apple's separately processed build. */
2
+ 'use strict';
3
+ const identifier = value => typeof value === 'string' && /^[A-Za-z0-9-]{1,64}$/.test(value);
4
+
5
+ function entity(response, fail, code) {
6
+ const row = response?.data;
7
+ if (!row || typeof row !== 'object' || Array.isArray(row) ||
8
+ row.attributes !== undefined && (!row.attributes || typeof row.attributes !== 'object') ||
9
+ row.relationships !== undefined && (!row.relationships || typeof row.relationships !== 'object')) fail(code);
10
+ return row;
11
+ }
12
+
13
+ function collection(response, fail, code) {
14
+ const rows = response?.data, total = response?.meta?.paging?.total;
15
+ if (!Array.isArray(rows) || rows.some(row => !row || typeof row !== 'object' || Array.isArray(row)) ||
16
+ rows.length >= 200 || !response.links || typeof response.links !== 'object' ||
17
+ Array.isArray(response.links) || response.links.next ||
18
+ total !== undefined && (!Number.isSafeInteger(total) || total !== rows.length)) fail(code);
19
+ return rows;
20
+ }
21
+
22
+ function checksum(attributes, receipt, fail) {
23
+ const checksums = attributes.sourceFileChecksums;
24
+ if (checksums !== undefined && (!checksums || typeof checksums !== 'object' || Array.isArray(checksums))) {
25
+ fail('file_checksum_unverified');
26
+ }
27
+ const file = checksums?.file;
28
+ if (file === undefined) return;
29
+ const digest = file?.algorithm === 'SHA_256' ? receipt.sha256 :
30
+ file?.algorithm === 'MD5' ? receipt.md5 : null;
31
+ const width = file?.algorithm === 'SHA_256' ? 64 : 32;
32
+ if (typeof digest !== 'string' || !new RegExp(`^[a-f0-9]{${width}}$`).test(digest)) {
33
+ fail('file_checksum_unverified');
34
+ }
35
+ const values = [digest, digest.toUpperCase(), Buffer.from(digest, 'hex').toString('base64')];
36
+ if (!values.includes(file.hash)) fail('file_checksum_unverified');
37
+ }
38
+
39
+ async function fileProof(receipt, get, fail) {
40
+ const response = await get(`/buildUploads/${receipt.upload_id}/buildUploadFiles`);
41
+ const assets = collection(response, fail, 'file_membership').filter(row => row.attributes?.assetType === 'ASSET');
42
+ if (assets.length !== 1 || assets[0].id !== receipt.file_id) fail('file_membership');
43
+ const file = entity(await get(`/buildUploadFiles/${receipt.file_id}`), fail, 'file_unverified');
44
+ const attrs = file.attributes || {};
45
+ if (file?.id !== receipt.file_id || attrs.assetType !== 'ASSET' ||
46
+ attrs.fileName !== receipt.fileName || attrs.fileSize !== receipt.fileSize) fail('file_unverified');
47
+ if (attrs.assetDeliveryState?.state === 'FAILED' || attrs.assetDeliveryState?.errors?.length) {
48
+ fail('processing_failed');
49
+ }
50
+ if (attrs.assetDeliveryState?.state !== 'COMPLETE') return false;
51
+ checksum(attrs, receipt, fail);
52
+ return true;
53
+ }
54
+
55
+ async function inventoryBuild(receipt, get, fail) {
56
+ const query = new URLSearchParams({'filter[app]': receipt.app_id, 'filter[version]': receipt.cfBundleVersion,
57
+ include: 'preReleaseVersion,app', limit: '200'});
58
+ const response = await get(`/builds?${query}`), rows = collection(response, fail, 'build_inventory_unverified');
59
+ const included = response.included;
60
+ if (!Array.isArray(included) || included.some(row => !row || typeof row !== 'object' || Array.isArray(row))) {
61
+ fail('build_inventory_unverified');
62
+ }
63
+ const ids = new Set(), matches = [];
64
+ for (const row of rows) {
65
+ if (!identifier(row.id) || ids.has(row.id) || row.attributes?.version !== receipt.cfBundleVersion) {
66
+ fail('build_inventory_unverified');
67
+ }
68
+ ids.add(row.id);
69
+ const trainId = row.relationships?.preReleaseVersion?.data?.id;
70
+ const appId = row.relationships?.app?.data?.id;
71
+ const trains = included.filter(item => item.type === 'preReleaseVersions' && item.id === trainId);
72
+ const apps = included.filter(item => item.type === 'apps' && item.id === appId);
73
+ if (!identifier(trainId) || trains.length !== 1 || apps.length !== 1 || appId !== receipt.app_id ||
74
+ apps[0].attributes?.bundleId !== receipt.bundle_id) fail('build_inventory_unverified');
75
+ if (trains[0].attributes?.version === receipt.cfBundleShortVersionString &&
76
+ trains[0].attributes?.platform === 'IOS') matches.push(row.id);
77
+ }
78
+ if (matches.length > 1) fail('build_ambiguous');
79
+ return matches[0] || null;
80
+ }
81
+
82
+ async function buildProof(buildId, receipt, get, fail) {
83
+ const build = entity(await get(`/builds/${buildId}`), fail, 'build_unverified');
84
+ const attrs = build.attributes || {};
85
+ if (build?.id !== buildId || attrs.version !== receipt.cfBundleVersion) fail('build_unverified');
86
+ if (['FAILED', 'INVALID'].includes(attrs.processingState)) fail('processing_failed');
87
+ if (attrs.processingState === 'PROCESSING') return null;
88
+ if (attrs.processingState !== 'VALID' || attrs.buildAudienceType !== 'APP_STORE_ELIGIBLE') {
89
+ fail('build_unverified');
90
+ }
91
+ const app = entity(await get(`/builds/${buildId}/app`), fail, 'app_unverified');
92
+ if (app?.id !== receipt.app_id || app.attributes?.bundleId !== receipt.bundle_id) fail('app_unverified');
93
+ const train = entity(await get(`/builds/${buildId}/preReleaseVersion`), fail, 'train_unverified');
94
+ if (!identifier(train?.id) || train.attributes?.platform !== 'IOS' ||
95
+ train.attributes?.version !== receipt.cfBundleShortVersionString) fail('train_unverified');
96
+ return {build_id: buildId, app_id: app.id, version: receipt.cfBundleShortVersionString,
97
+ build: receipt.cfBundleVersion, upload_id: receipt.upload_id};
98
+ }
99
+
100
+ async function observe(receipt, get, fail) {
101
+ const upload = entity(await get(`/buildUploads/${receipt.upload_id}?include=build`), fail, 'upload_unverified');
102
+ const attrs = upload?.attributes || {}, state = attrs.state?.state;
103
+ if (upload?.id !== receipt.upload_id || attrs.platform !== 'IOS' ||
104
+ attrs.cfBundleVersion !== receipt.cfBundleVersion ||
105
+ attrs.cfBundleShortVersionString !== receipt.cfBundleShortVersionString) fail('upload_unverified');
106
+ if (state === 'FAILED' || attrs.state?.errors?.length) fail('processing_failed');
107
+ if (!['COMPLETE', 'PROCESSING'].includes(state)) return null;
108
+ if (!await fileProof(receipt, get, fail)) return null;
109
+ const relationship = upload.relationships?.build?.data;
110
+ if (relationship && !identifier(relationship.id)) fail('build_unverified');
111
+ const buildId = relationship?.id || await inventoryBuild(receipt, get, fail);
112
+ if (!buildId) return null;
113
+ const proof = await buildProof(buildId, receipt, get, fail);
114
+ return proof && {...proof, upload_resource_state: state};
115
+ }
116
+
117
+ module.exports = {observe};
@@ -0,0 +1,157 @@
1
+ """Read-only exact upload/file/build proof for the legacy synchronous Python entrypoint."""
2
+ import base64
3
+ import re
4
+
5
+ from upload_receipt import UploadError
6
+
7
+
8
+ def refuse(code):
9
+ raise UploadError(code, "Apple upload completion was not independently verified")
10
+
11
+
12
+ def entity(response, code):
13
+ row = response.get("data") if isinstance(response, dict) else None
14
+ if (not isinstance(row, dict) or not isinstance(row.get("attributes", {}), dict)
15
+ or not isinstance(row.get("relationships", {}), dict)):
16
+ refuse(code)
17
+ return row
18
+
19
+
20
+ def collection(response, code):
21
+ if not isinstance(response, dict):
22
+ refuse(code)
23
+ rows, links = response.get("data"), response.get("links")
24
+ total = (response.get("meta") or {}).get("paging", {}).get("total")
25
+ if (not isinstance(rows, list) or any(not isinstance(row, dict)
26
+ or not isinstance(row.get("attributes", {}), dict)
27
+ or not isinstance(row.get("relationships", {}), dict) for row in rows)
28
+ or len(rows) >= 200 or not isinstance(links, dict) or links.get("next")
29
+ or total is not None and (type(total) is not int or total != len(rows))):
30
+ refuse(code)
31
+ return rows
32
+
33
+
34
+ def checksum(attributes, receipt):
35
+ checksums = attributes.get("sourceFileChecksums", {})
36
+ if not isinstance(checksums, dict):
37
+ refuse("file_checksum_unverified")
38
+ if "file" not in checksums:
39
+ return
40
+ file = checksums["file"]
41
+ if not isinstance(file, dict):
42
+ refuse("file_checksum_unverified")
43
+ algorithm = file.get("algorithm")
44
+ digest = receipt.get("sha256") if algorithm == "SHA_256" else receipt.get("md5") if algorithm == "MD5" else None
45
+ width = 64 if algorithm == "SHA_256" else 32
46
+ if not isinstance(digest, str) or not re.fullmatch(r"[a-f0-9]{" + str(width) + "}", digest):
47
+ refuse("file_checksum_unverified")
48
+ values = (digest, digest.upper(), base64.b64encode(bytes.fromhex(digest)).decode())
49
+ if file.get("hash") not in values:
50
+ refuse("file_checksum_unverified")
51
+
52
+
53
+ def file_proof(receipt, api):
54
+ response = api("GET", f"/buildUploads/{receipt['upload_id']}/buildUploadFiles")
55
+ assets = [row for row in collection(response, "file_membership")
56
+ if (row.get("attributes") or {}).get("assetType") == "ASSET"]
57
+ if len(assets) != 1 or assets[0].get("id") != receipt["file_id"]:
58
+ refuse("file_membership")
59
+ file = entity(api("GET", f"/buildUploadFiles/{receipt['file_id']}"), "file_unverified")
60
+ attrs = file.get("attributes") or {}
61
+ if (file.get("id") != receipt["file_id"] or attrs.get("assetType") != "ASSET"
62
+ or any(attrs.get(key) != receipt[key] for key in ("fileName", "fileSize"))):
63
+ refuse("file_unverified")
64
+ state = attrs.get("assetDeliveryState") or {}
65
+ if not isinstance(state, dict):
66
+ refuse("file_unverified")
67
+ if state.get("state") == "FAILED" or state.get("errors"):
68
+ refuse("processing_failed")
69
+ if state.get("state") != "COMPLETE":
70
+ return False
71
+ checksum(attrs, receipt)
72
+ return True
73
+
74
+
75
+ def inventory_build(receipt, api):
76
+ response = api("GET", "/builds", params={"filter[app]": receipt["app_id"],
77
+ "filter[version]": receipt["cfBundleVersion"], "include": "preReleaseVersion,app", "limit": 200})
78
+ rows = collection(response, "build_inventory_unverified")
79
+ included = response.get("included")
80
+ if (not isinstance(included, list) or any(not isinstance(item, dict)
81
+ or not isinstance(item.get("attributes", {}), dict) for item in included)):
82
+ refuse("build_inventory_unverified")
83
+ identifiers, matches = set(), []
84
+ for row in rows:
85
+ build_id = row.get("id")
86
+ if (not isinstance(build_id, str) or not re.fullmatch(r"[A-Za-z0-9-]{1,64}", build_id)
87
+ or build_id in identifiers
88
+ or (row.get("attributes") or {}).get("version") != receipt["cfBundleVersion"]):
89
+ refuse("build_inventory_unverified")
90
+ identifiers.add(build_id)
91
+ relationships = row.get("relationships") or {}
92
+ for name in ("preReleaseVersion", "app"):
93
+ link = relationships.get(name)
94
+ if (not isinstance(link, dict) or not isinstance(link.get("data"), dict)):
95
+ refuse("build_inventory_unverified")
96
+ train_id = ((relationships.get("preReleaseVersion") or {}).get("data") or {}).get("id")
97
+ app_id = ((relationships.get("app") or {}).get("data") or {}).get("id")
98
+ trains = [item for item in included if item.get("type") == "preReleaseVersions" and item.get("id") == train_id]
99
+ apps = [item for item in included if item.get("type") == "apps" and item.get("id") == app_id]
100
+ if (not isinstance(train_id, str) or not re.fullmatch(r"[A-Za-z0-9-]{1,64}", train_id)
101
+ or len(trains) != 1 or len(apps) != 1 or app_id != receipt["app_id"]
102
+ or (apps[0].get("attributes") or {}).get("bundleId") != receipt["bundle_id"]):
103
+ refuse("build_inventory_unverified")
104
+ attrs = trains[0].get("attributes") or {}
105
+ if attrs.get("version") == receipt["cfBundleShortVersionString"] and attrs.get("platform") == "IOS":
106
+ matches.append(build_id)
107
+ if len(matches) > 1:
108
+ refuse("build_ambiguous")
109
+ return matches[0] if matches else None
110
+
111
+
112
+ def build_proof(build_id, receipt, api):
113
+ build = entity(api("GET", f"/builds/{build_id}"), "build_unverified")
114
+ attrs = build.get("attributes") or {}
115
+ if build.get("id") != build_id or attrs.get("version") != receipt["cfBundleVersion"]:
116
+ refuse("build_unverified")
117
+ if attrs.get("processingState") in ("FAILED", "INVALID"):
118
+ refuse("processing_failed")
119
+ if attrs.get("processingState") == "PROCESSING":
120
+ return None
121
+ if attrs.get("processingState") != "VALID" or attrs.get("buildAudienceType") != "APP_STORE_ELIGIBLE":
122
+ refuse("build_unverified")
123
+ app = entity(api("GET", f"/builds/{build_id}/app"), "app_unverified")
124
+ if app.get("id") != receipt["app_id"] or (app.get("attributes") or {}).get("bundleId") != receipt["bundle_id"]:
125
+ refuse("app_unverified")
126
+ train = entity(api("GET", f"/builds/{build_id}/preReleaseVersion"), "train_unverified")
127
+ train_attrs = train.get("attributes") or {}
128
+ if (not isinstance(train.get("id"), str) or not re.fullmatch(r"[A-Za-z0-9-]{1,64}", train["id"])
129
+ or train_attrs.get("platform") != "IOS"
130
+ or train_attrs.get("version") != receipt["cfBundleShortVersionString"]):
131
+ refuse("train_unverified")
132
+ return {"build_id": build_id}
133
+
134
+
135
+ def observe(receipt, api):
136
+ response = api("GET", f"/buildUploads/{receipt['upload_id']}", params={"include": "build"})
137
+ upload = entity(response, "upload_unverified")
138
+ attrs = upload.get("attributes") or {}
139
+ state = attrs.get("state") or {}
140
+ if not isinstance(state, dict):
141
+ refuse("upload_unverified")
142
+ if (upload.get("id") != receipt["upload_id"] or attrs.get("platform") != "IOS"
143
+ or any(attrs.get(key) != receipt[key] for key in ("cfBundleVersion", "cfBundleShortVersionString"))):
144
+ refuse("upload_unverified")
145
+ if state.get("state") == "FAILED" or state.get("errors"):
146
+ refuse("processing_failed")
147
+ if state.get("state") not in ("COMPLETE", "PROCESSING") or not file_proof(receipt, api):
148
+ return None, state.get("state")
149
+ link = (upload.get("relationships") or {}).get("build")
150
+ if link is not None and not isinstance(link, dict):
151
+ refuse("build_unverified")
152
+ relationship = (link or {}).get("data")
153
+ if relationship and (not isinstance(relationship, dict) or not isinstance(relationship.get("id"), str)
154
+ or not re.fullmatch(r"[A-Za-z0-9-]{1,64}", relationship["id"])):
155
+ refuse("build_unverified")
156
+ build_id = relationship["id"] if relationship else inventory_build(receipt, api)
157
+ return (build_proof(build_id, receipt, api) if build_id else None), state.get("state")
@@ -5,6 +5,7 @@ const {parseArgs} = require('node:util');
5
5
  const {setTimeout: delay} = require('node:timers/promises');
6
6
  const github = require('./mobile_release_api.cjs');
7
7
  const apple = require('./reconcile_apple_upload.cjs');
8
+ const provider = require('./apple_upload_proof.cjs');
8
9
  const handoff = require('./apple_upload_handoff.cjs');
9
10
 
10
11
  function credential(env = process.env) {
@@ -15,25 +16,7 @@ function credential(env = process.env) {
15
16
  }
16
17
 
17
18
  async function observe(receipt, get) {
18
- const path = `/buildUploads/${receipt.upload_id}?include=build`, response = await get(path);
19
- const upload = response.data, attrs = upload?.attributes || {};
20
- if (upload?.id !== receipt.upload_id || attrs.cfBundleVersion !== receipt.cfBundleVersion ||
21
- attrs.cfBundleShortVersionString !== receipt.cfBundleShortVersionString) handoff.fail('upload_identity');
22
- if (attrs.state?.state === 'FAILED') handoff.fail('processing_failed');
23
- if (attrs.state?.state !== 'COMPLETE') return null;
24
- const buildId = upload.relationships?.build?.data?.id;
25
- if (!/^[A-Za-z0-9-]{1,64}$/.test(buildId || '')) handoff.fail('build_identity');
26
- const buildPath = `/builds/${buildId}`, build = await get(buildPath);
27
- if (['FAILED', 'INVALID'].includes(build.data?.attributes?.processingState)) handoff.fail('processing_failed');
28
- if (build.data?.attributes?.processingState === 'PROCESSING') return null;
29
- const files = await get(`/buildUploads/${receipt.upload_id}/buildUploadFiles`);
30
- const assets = files.data?.filter(row => row.attributes?.assetType === 'ASSET');
31
- if (!Array.isArray(assets) || files.links?.next || assets.length !== 1 || assets[0].id !== receipt.file_id) {
32
- handoff.fail('file_membership');
33
- }
34
- // Preserve the existing independent complete-file, VALID/eligible build and actual app readbacks.
35
- return apple.verifyApple(receipt, requested => requested === path ? response :
36
- requested === buildPath ? build : get(requested));
19
+ return provider.observe(receipt, get, handoff.fail);
37
20
  }
38
21
 
39
22
  async function verify(value, artifactId, timeout, dependencies = {}) {
@@ -71,7 +54,8 @@ async function main() {
71
54
  handoff.metadata(value);
72
55
  const receiptPath = `${positionals[0]}.upload-receipt.json`;
73
56
  fs.writeFileSync(receiptPath, JSON.stringify({...value.receipt, stage: 'complete', state: 'COMPLETE',
74
- build_id: proof.build_id, processing_seconds: proof.processing_seconds}, null, 2) + '\n');
57
+ build_id: proof.build_id, upload_resource_state: proof.upload_resource_state,
58
+ processing_seconds: proof.processing_seconds}, null, 2) + '\n');
75
59
  if (/[\r\n]/.test(receiptPath)) handoff.fail('receipt_path');
76
60
  if (process.env.GITHUB_OUTPUT) fs.appendFileSync(process.env.GITHUB_OUTPUT,
77
61
  `verified=true\nbuild-id=${proof.build_id}\nproducer-attempt=${proof.producer_attempt}\n` +
@@ -3,6 +3,7 @@
3
3
  const fs = require('node:fs');
4
4
  const crypto = require('node:crypto');
5
5
  const github = require('./mobile_release_api.cjs');
6
+ const provider = require('./apple_upload_proof.cjs');
6
7
 
7
8
  const RECEIPT = 'gowalk-cicd/apple-build-upload-receipt.v1';
8
9
  const OWNER = 'gowalk-cicd/mobile-upload-owner.v1';
@@ -20,6 +21,9 @@ function readReceipt(path) {
20
21
  !/^\d+(\.\d+){1,2}$/.test(data.cfBundleShortVersionString || '') ||
21
22
  !/^[a-f0-9]{64}$/.test(data.sha256 || '') || data.fileName !== `${data.sha256}.ipa` ||
22
23
  !Number.isSafeInteger(data.fileSize) || data.fileSize <= 0) refuse('receipt_invalid');
24
+ if (data.md5 !== undefined && (typeof data.md5 !== 'string' || !/^[a-f0-9]{32}$/.test(data.md5))) {
25
+ refuse('receipt_invalid');
26
+ }
23
27
  return data;
24
28
  }
25
29
 
@@ -69,26 +73,9 @@ async function appleGet(path, key = {pem: process.env.ASC_KEY_P8, id: process.en
69
73
  }
70
74
 
71
75
  async function verifyApple(receipt, get = appleGet) {
72
- const upload = (await get(`/buildUploads/${receipt.upload_id}?include=build`)).data;
73
- const attributes = upload?.attributes || {};
74
- const buildId = upload?.relationships?.build?.data?.id;
75
- if (upload?.id !== receipt.upload_id || attributes.state?.state !== 'COMPLETE' ||
76
- attributes.cfBundleVersion !== receipt.cfBundleVersion ||
77
- attributes.cfBundleShortVersionString !== receipt.cfBundleShortVersionString ||
78
- !/^[A-Za-z0-9-]{1,64}$/.test(buildId || '')) refuse('upload_unverified');
79
- const file = (await get(`/buildUploadFiles/${receipt.file_id}`)).data;
80
- if (file?.id !== receipt.file_id || file.attributes?.assetType !== 'ASSET' ||
81
- file.attributes.fileName !== receipt.fileName ||
82
- file.attributes.fileSize !== receipt.fileSize ||
83
- file.attributes.assetDeliveryState?.state !== 'COMPLETE') refuse('file_unverified');
84
- const build = (await get(`/builds/${buildId}`)).data;
85
- if (build?.id !== buildId || build.attributes?.processingState !== 'VALID' ||
86
- build.attributes?.buildAudienceType !== 'APP_STORE_ELIGIBLE' ||
87
- build.attributes?.version !== receipt.cfBundleVersion) refuse('build_unverified');
88
- const app = (await get(`/builds/${buildId}/app`)).data;
89
- if (app?.id !== receipt.app_id || app.attributes?.bundleId !== receipt.bundle_id) refuse('app_unverified');
90
- return {build_id: buildId, app_id: app.id, version: receipt.cfBundleShortVersionString,
91
- build: receipt.cfBundleVersion, upload_id: receipt.upload_id};
76
+ const proof = await provider.observe(receipt, get, refuse);
77
+ if (!proof) refuse('processing_pending');
78
+ return proof;
92
79
  }
93
80
 
94
81
  async function reconcile(deploymentId, runId, attempt, path, api = github, get = appleGet) {
@@ -18,6 +18,7 @@ import requests
18
18
  import upload_checksums
19
19
  import upload_receipt
20
20
  import apple_upload_handoff
21
+ import apple_upload_proof
21
22
  from upload_receipt import Receipt, UploadError
22
23
 
23
24
  # Provider refusals the uploader classifies itself instead of letting the shared
@@ -53,12 +54,16 @@ def identity(ipa: Path) -> dict:
53
54
  info = plistlib.loads(archive.read(names[0]))
54
55
  except (zipfile.BadZipFile, plistlib.InvalidFileException, KeyError) as exc:
55
56
  raise UploadError("ipa_invalid", "IPA is not a readable app archive") from exc
57
+ sha256, md5 = hashlib.sha256(), hashlib.md5()
56
58
  with ipa.open("rb") as stream:
57
- digest = hashlib.file_digest(stream, "sha256").hexdigest()
59
+ for chunk in iter(lambda: stream.read(1024 * 1024), b""):
60
+ sha256.update(chunk)
61
+ md5.update(chunk)
62
+ digest = sha256.hexdigest()
58
63
  return {"bundle_id": str(info["CFBundleIdentifier"]),
59
64
  "cfBundleVersion": str(info["CFBundleVersion"]),
60
65
  "cfBundleShortVersionString": str(info["CFBundleShortVersionString"]),
61
- "sha256": digest, "fileName": digest + ".ipa", "fileSize": ipa.stat().st_size}
66
+ "sha256": digest, "md5": md5.hexdigest(), "fileName": digest + ".ipa", "fileSize": ipa.stat().st_size}
62
67
 
63
68
 
64
69
  def upload_record(app_id: str, info: dict) -> dict:
@@ -176,17 +181,12 @@ def deliver(ipa: Path, report: Path, timeout: int, handoff: Path | None = None)
176
181
  processing_started = time.monotonic()
177
182
  deadline = processing_started + timeout
178
183
  while True:
179
- current = api("GET", f"/buildUploads/{record['id']}", params={"include": "build"})["data"]
180
- state = ((current.get("attributes") or {}).get("state") or {}).get("state")
181
- build_id = (((current.get("relationships") or {}).get("build") or {}).get("data") or {}).get("id")
182
- if state == "COMPLETE":
183
- return receipt.update("complete", state=state, build_id=build_id,
184
+ proof, state = apple_upload_proof.observe(receipt.data, api)
185
+ if proof:
186
+ return receipt.update("complete", state="COMPLETE", upload_resource_state=state, **proof,
184
187
  processing_seconds=round(time.monotonic() - processing_started, 3))
185
- receipt.update("processing", state=state, build_id=build_id,
188
+ receipt.update("processing", state=state,
186
189
  processing_seconds=round(time.monotonic() - processing_started, 3))
187
- if state == "FAILED":
188
- raise UploadError("processing_failed",
189
- "Apple build upload failed processing; inspect the upload ID's provider errors")
190
190
  if time.monotonic() >= deadline:
191
191
  raise UploadError("processing_pending",
192
192
  "Apple build processing is pending; reuse this upload ID on continuation")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gowalk-cicd",
3
- "version": "1.0.183",
3
+ "version": "1.0.184",
4
4
  "description": "Zero-config GitHub Actions delivery for iOS TestFlight and Android Google Play.",
5
5
  "type": "module",
6
6
  "bin": {
package/remedies.json CHANGED
@@ -2,8 +2,8 @@
2
2
  {
3
3
  "schema": "gowalk-cicd/apple-build-upload-failed.v2",
4
4
  "code": "processing_pending",
5
- "fixed_in": "1.0.164",
6
- "remedy": "Keep the original IPA and apple-build-upload receipt. If Apple later validates the exact upload, run reconcile_apple_upload.cjs in an authorized GitHub Actions recovery job with the original deployment, run, attempt and artifact receipt. It proves the failed owner, completed file, valid build and matching app before marking the deployment uploaded. Rerun the whole original deploy workflow after the readback; never upload a second binary or hand-edit the deployment receipt."
5
+ "fixed_in": "1.0.184",
6
+ "remedy": "Keep the original IPA and apple-build-upload receipt. From 1.0.184 recovery stages unchanged bytes as app.ipa so punctuation in the export filename cannot block retention. A PROCESSING upload summary can complete only after fresh proof of its completed matching asset/checksum and unique valid eligible iOS build, exact app/bundle and marketing version. Future receipts carry local MD5 as well as SHA-256. Run reconcile_apple_upload.cjs only in an authorized Actions recovery job with the original deployment, run, attempt and retained receipt; it never uploads. Read its owner completion back, then rerun the whole original deploy workflow. Missing original bytes or checksum proof remain unverified; never invent the digest, re-upload another binary under the same number or hand-edit the owner."
7
7
  },
8
8
  {
9
9
  "schema": "gowalk-cicd/mobile-release-refused.v1",