@@ -57464,7 +57464,7 @@ exports.UnauthorizedError = void 0;
5746457464exports.GetAppId = GetAppId;
5746557465exports.GetLatestBundleVersion = GetLatestBundleVersion;
5746657466exports.UpdateTestDetails = UpdateTestDetails;
57467- exports.ListCertificates = ListCertificates ;
57467+ exports.GetCertificate = GetCertificate ;
5746857468const app_store_connect_api_1 = __nccwpck_require__(9073);
5746957469const utilities_1 = __nccwpck_require__(5739);
5747057470const core = __nccwpck_require__(2186);
@@ -57749,13 +57749,14 @@ async function UpdateTestDetails(project, whatsNew) {
5774957749function normalizeVersion(version) {
5775057750 return version.split('.').map(part => parseInt(part, 10).toString()).join('.');
5775157751}
57752- async function ListCertificates (project, certificateType) {
57752+ async function GetCertificate (project, certificateType = null ) {
5775357753 await getOrCreateClient(project);
57754- const certificateQuery = {
57755- query: {
57756- "filter[certificateType]": certificateType,
57757- }
57758- };
57754+ const certificateQuery = {};
57755+ if (certificateType) {
57756+ certificateQuery.query = {
57757+ 'filter[certificateType]': [certificateType],
57758+ };
57759+ }
5775957760 (0, utilities_1.log)(`GET /certificates?${JSON.stringify(certificateQuery.query)}`);
5776057761 const { data: response, error: responseError } = await appStoreConnectClient.api.CertificatesService.certificatesGetCollection(certificateQuery);
5776157762 if (responseError) {
@@ -57764,10 +57765,17 @@ async function ListCertificates(project, certificateType) {
5776457765 }
5776557766 const responseJson = JSON.stringify(response, null, 2);
5776657767 if (!response || !response.data || response.data.length === 0) {
57767- throw new Error(`No certificates found! ${responseJson}`) ;
57768+ return null ;
5776857769 }
5776957770 (0, utilities_1.log)(responseJson);
57770- return response.data;
57771+ const validCerts = response.data.filter(certificate => {
57772+ if (!certificate.attributes) {
57773+ return false;
57774+ }
57775+ const isExpired = new Date(certificate.attributes.expirationDate) < new Date();
57776+ return certificate.attributes.activated && !isExpired;
57777+ });
57778+ return validCerts.length === 0 ? null : validCerts[0];
5777157779}
5777257780
5777357781
@@ -57782,6 +57790,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
5778257790exports.AppleCredential = void 0;
5778357791exports.ImportCredentials = ImportCredentials;
5778457792exports.RemoveCredentials = RemoveCredentials;
57793+ exports.ImportCertificate = ImportCertificate;
5778557794const core = __nccwpck_require__(2186);
5778657795const exec = __nccwpck_require__(1514);
5778757796const uuid = __nccwpck_require__(5840);
@@ -57933,6 +57942,15 @@ async function RemoveCredentials() {
5793357942 core.error(`Failed to remove app store connect key!\n${error.stack}`);
5793457943 }
5793557944}
57945+ async function ImportCertificate(certificate) {
57946+ const tempCredential = core.getState('tempCredential');
57947+ if (!tempCredential) {
57948+ throw new Error('Missing tempCredential state');
57949+ }
57950+ const keychainPath = `${temp}/${tempCredential}.keychain-db`;
57951+ const certificatePath = `${temp}/${certificate.attributes.name}.cer`;
57952+ core.info('Importing certificate...');
57953+ }
5793657954
5793757955
5793857956/***/ }),
@@ -58017,6 +58035,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
5801758035exports.GetProjectDetails = GetProjectDetails;
5801858036exports.ArchiveXcodeProject = ArchiveXcodeProject;
5801958037exports.ExportXcodeArchive = ExportXcodeArchive;
58038+ exports.isAppBundleNotarized = isAppBundleNotarized;
5802058039exports.ValidateApp = ValidateApp;
5802158040exports.UploadApp = UploadApp;
5802258041const XcodeProject_1 = __nccwpck_require__(1981);
@@ -58427,17 +58446,18 @@ async function ExportXcodeArchive(projectRef) {
5842758446 if (!projectRef.isAppStoreUpload()) {
5842858447 const notarizeInput = core.getInput('notarize') || 'true';
5842958448 projectRef.executablePath = await getFirstPathWithGlob(`${projectRef.exportPath}/**/*.app`);
58430- const notarize = notarizeInput === 'true';
58431- core.debug(`Notarize? ${notarize}`);
58432- if (notarize) {
58449+ if (notarizeInput === 'true') {
5843358450 await signMacOSAppBundle(projectRef);
5843458451 if (!projectRef.isSteamBuild) {
5843558452 projectRef.executablePath = await createMacOSInstallerPkg(projectRef);
5843658453 }
5843758454 else {
58438- const zipPath = path.join(projectRef.exportPath, projectRef.executablePath.replace('.app', '.zip'));
58439- await (0, exec_1.exec)('ditto', ['-c', '-k', '--sequesterRsrc', '--keepParent', projectRef.executablePath, zipPath]);
58440- await notarizeArchive(projectRef, zipPath, projectRef.executablePath);
58455+ const isNotarized = await isAppBundleNotarized(projectRef.executablePath);
58456+ if (!isNotarized) {
58457+ const zipPath = path.join(projectRef.exportPath, projectRef.executablePath.replace('.app', '.zip'));
58458+ await (0, exec_1.exec)('ditto', ['-c', '-k', '--sequesterRsrc', '--keepParent', projectRef.executablePath, zipPath]);
58459+ await notarizeArchive(projectRef, zipPath, projectRef.executablePath);
58460+ }
5844158461 }
5844258462 }
5844358463 }
@@ -58458,6 +58478,16 @@ async function ExportXcodeArchive(projectRef) {
5845858478 core.setOutput('executable', projectRef.executablePath);
5845958479 return projectRef;
5846058480}
58481+ async function isAppBundleNotarized(appPath) {
58482+ let output = '';
58483+ const exitCode = await (0, exec_1.exec)('stapler', ['validate', appPath], {
58484+ listeners: {
58485+ stdout: (data) => { output += data.toString(); }
58486+ },
58487+ ignoreReturnCode: true
58488+ });
58489+ return exitCode === 0 && output.includes('The validate action worked!');
58490+ }
5846158491async function getFirstPathWithGlob(globPattern) {
5846258492 const globber = await glob.create(globPattern);
5846358493 const files = await globber.glob();
@@ -58474,7 +58504,6 @@ async function signMacOSAppBundle(projectRef) {
5847458504 throw new Error(`Not a valid app bundle: ${appPath}`);
5847558505 }
5847658506 const signAppBundlePath = __nccwpck_require__.ab + "sign-app-bundle.sh";
58477- core.info(`Signing app bundle: ${appPath}`);
5847858507 let codesignOutput = '';
5847958508 const codesignExitCode = await (0, exec_1.exec)('sh', [__nccwpck_require__.ab + "sign-app-bundle.sh", appPath, projectRef.entitlementsPath], {
5848058509 listeners: {
@@ -58485,10 +58514,8 @@ async function signMacOSAppBundle(projectRef) {
5848558514 ignoreReturnCode: true
5848658515 });
5848758516 if (codesignExitCode !== 0) {
58488- (0, utilities_1.log)(codesignOutput, 'error');
5848958517 throw new Error(`Failed to code sign the app!`);
5849058518 }
58491- core.info(codesignOutput);
5849258519}
5849358520async function createMacOSInstallerPkg(projectRef) {
5849458521 core.info('Creating macOS installer pkg...');
@@ -58513,6 +58540,11 @@ async function createMacOSInstallerPkg(projectRef) {
5851358540 catch (error) {
5851458541 throw new Error(`Failed to create the pkg at: ${pkgPath}!`);
5851558542 }
58543+ const developerIdInstallerCert = await (0, AppStoreConnectClient_1.GetCertificate)(projectRef, 'MAC_INSTALLER_DISTRIBUTION');
58544+ core.info(`Found Developer ID Installer certificate: [${developerIdInstallerCert.id}] ${developerIdInstallerCert.attributes.name}`);
58545+ const certPath = path.join(process.env.RUNNER_TEMP, 'developer_id_installer.cer');
58546+ await fs.promises.writeFile(certPath, developerIdInstallerCert.attributes.certificateContent);
58547+ core.info(`Saved Developer ID Installer certificate to: ${certPath}`);
5851658548 const signPkgPath = __nccwpck_require__.ab + "sign-app-pkg.sh";
5851758549 core.info(`Signing pkg: ${pkgPath}`);
5851858550 let codesignOutput = '';
0 commit comments