Skip to content

Commit cd2a5ec

Browse files
refactor file content print
1 parent 76c5aec commit cd2a5ec

File tree

4 files changed

+64
-76
lines changed

4 files changed

+64
-76
lines changed

dist/index.js

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -58369,8 +58369,10 @@ exports.log = log;
5836958369
exports.DeepEqual = DeepEqual;
5837058370
exports.matchRegexPattern = matchRegexPattern;
5837158371
exports.getFirstPathWithGlob = getFirstPathWithGlob;
58372+
exports.getFileContents = getFileContents;
5837258373
const core = __nccwpck_require__(2186);
5837358374
const glob = __nccwpck_require__(8090);
58375+
const fs = __nccwpck_require__(7147);
5837458376
function log(message, type = 'info') {
5837558377
if (type == 'info' && !core.isDebug()) {
5837658378
return;
@@ -58445,6 +58447,24 @@ async function getFirstPathWithGlob(globPattern) {
5844558447
}
5844658448
return files[0];
5844758449
}
58450+
async function getFileContents(filePath, printContent = true) {
58451+
let fileContents = '';
58452+
if (printContent) {
58453+
core.startGroup(`${filePath} content:`);
58454+
}
58455+
const fileHandle = await fs.promises.open(filePath, fs.constants.O_RDONLY);
58456+
try {
58457+
fileContents = await fs.promises.readFile(fileHandle, 'utf8');
58458+
}
58459+
finally {
58460+
await fileHandle.close();
58461+
if (printContent) {
58462+
core.info(fileContents);
58463+
core.endGroup();
58464+
}
58465+
}
58466+
return fileContents;
58467+
}
5844858468

5844958469

5845058470
/***/ }),
@@ -58608,14 +58628,7 @@ async function GetProjectDetails(credential, xcodeVersion) {
5860858628
infoPlistPath = `${projectDirectory}/Info.plist`;
5860958629
}
5861058630
core.info(`Info.plist path: ${infoPlistPath}`);
58611-
const infoPlistHandle = await fs.promises.open(infoPlistPath, fs.constants.O_RDONLY);
58612-
let infoPlistContent;
58613-
try {
58614-
infoPlistContent = await fs.promises.readFile(infoPlistHandle, 'utf8');
58615-
}
58616-
finally {
58617-
await infoPlistHandle.close();
58618-
}
58631+
let infoPlistContent = await (0, utilities_1.getFileContents)(infoPlistPath, false);
5861958632
const infoPlist = plist.parse(infoPlistContent);
5862058633
let cFBundleShortVersionString = infoPlist['CFBundleShortVersionString'];
5862158634
if (cFBundleShortVersionString) {
@@ -58652,6 +58665,9 @@ async function GetProjectDetails(credential, xcodeVersion) {
5865258665
else {
5865358666
projectRef.entitlementsPath = entitlementsPath;
5865458667
}
58668+
if (projectRef.entitlementsPath) {
58669+
await (0, utilities_1.getFileContents)(projectRef.entitlementsPath);
58670+
}
5865558671
if (projectRef.isAppStoreUpload()) {
5865658672
projectRef.appId = await (0, AppStoreConnectClient_1.GetAppId)(projectRef);
5865758673
if (projectRef.autoIncrementBuildNumber) {
@@ -58743,14 +58759,7 @@ async function GetProjectDetails(credential, xcodeVersion) {
5874358759
}
5874458760
}
5874558761
}
58746-
const plistHandle = await fs.promises.open(infoPlistPath, fs.constants.O_RDONLY);
58747-
try {
58748-
infoPlistContent = await fs.promises.readFile(plistHandle, 'utf8');
58749-
}
58750-
finally {
58751-
await plistHandle.close();
58752-
}
58753-
core.info(`------- Info.plist content: -------\n${infoPlistContent}\n-----------------------------------`);
58762+
infoPlistContent = await (0, utilities_1.getFileContents)(infoPlistPath);
5875458763
return projectRef;
5875558764
}
5875658765
async function checkSimulatorsAvailable(platform) {
@@ -58952,16 +58961,7 @@ async function getExportOptions(projectRef) {
5895258961
if (!exportOptionsPath) {
5895358962
throw new Error(`Invalid path for export-option-plist: ${exportOptionsPath}`);
5895458963
}
58955-
const exportOptionsHandle = await fs.promises.open(exportOptionsPath, fs.constants.O_RDONLY);
58956-
try {
58957-
const exportOptionContent = await fs.promises.readFile(exportOptionsHandle, 'utf8');
58958-
core.info(`----- Export options content: -----\n${exportOptionContent}\n-----------------------------------`);
58959-
const exportOptions = plist.parse(exportOptionContent);
58960-
projectRef.exportOption = exportOptions['method'];
58961-
}
58962-
finally {
58963-
await exportOptionsHandle.close();
58964-
}
58964+
await (0, utilities_1.getFileContents)(exportOptionsPath);
5896558965
projectRef.exportOptionsPath = exportOptionsPath;
5896658966
}
5896758967
async function getDefaultEntitlementsMacOS(projectRef) {
@@ -58981,7 +58981,6 @@ async function getDefaultEntitlementsMacOS(projectRef) {
5898158981
case 'app-store-connect':
5898258982
defaultEntitlements = {
5898358983
'com.apple.security.app-sandbox': true,
58984-
'com.apple.security.files.user-selected.read-only': true,
5898558984
};
5898658985
break;
5898758986
default:
@@ -59029,16 +59028,6 @@ async function ArchiveXcodeProject(projectRef) {
5902959028
archiveArgs.push(`AD_HOC_CODE_SIGNING_ALLOWED=YES`, `-allowProvisioningUpdates`);
5903059029
}
5903159030
if (entitlementsPath) {
59032-
core.debug(`Entitlements path: ${entitlementsPath}`);
59033-
const entitlementsHandle = await fs.promises.open(entitlementsPath, fs.constants.O_RDONLY);
59034-
try {
59035-
const entitlementsContent = await fs.promises.readFile(entitlementsHandle, 'utf8');
59036-
core.startGroup(`----- Entitlements content: -----\n${entitlementsContent}\n-----------------------------------`);
59037-
}
59038-
finally {
59039-
await entitlementsHandle.close();
59040-
core.endGroup();
59041-
}
5904259031
archiveArgs.push(`CODE_SIGN_ENTITLEMENTS=${entitlementsPath}`);
5904359032
}
5904459033
if (platform === 'iOS') {

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utilities.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
import core = require('@actions/core');
33
import glob = require('@actions/glob');
4+
import fs = require('fs');
45

56
export function log(message: string, type: 'info' | 'warning' | 'error' = 'info') {
67
if (type == 'info' && !core.isDebug()) { return; }
@@ -67,4 +68,27 @@ export async function getFirstPathWithGlob(globPattern: string): Promise<string>
6768
throw new Error(`No file found at: ${globPattern}`);
6869
}
6970
return files[0];
70-
}
71+
}
72+
73+
export async function getFileContents(filePath: string, printContent: boolean = true): Promise<string> {
74+
let fileContents: string = '';
75+
76+
if (printContent) {
77+
core.startGroup(`${filePath} content:`);
78+
}
79+
80+
const fileHandle = await fs.promises.open(filePath, fs.constants.O_RDONLY);
81+
82+
try {
83+
fileContents = await fs.promises.readFile(fileHandle, 'utf8');
84+
} finally {
85+
await fileHandle.close();
86+
87+
if (printContent) {
88+
core.info(fileContents);
89+
core.endGroup();
90+
}
91+
}
92+
93+
return fileContents;
94+
}

src/xcode.ts

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
DeepEqual,
1212
log,
1313
matchRegexPattern,
14-
getFirstPathWithGlob
14+
getFirstPathWithGlob,
15+
getFileContents
1516
} from './utilities';
1617
import { SemVer } from 'semver';
1718
import core = require('@actions/core');
@@ -193,15 +194,7 @@ export async function GetProjectDetails(credential: AppleCredential, xcodeVersio
193194
}
194195

195196
core.info(`Info.plist path: ${infoPlistPath}`);
196-
const infoPlistHandle = await fs.promises.open(infoPlistPath, fs.constants.O_RDONLY);
197-
let infoPlistContent: string;
198-
199-
try {
200-
infoPlistContent = await fs.promises.readFile(infoPlistHandle, 'utf8');
201-
} finally {
202-
await infoPlistHandle.close();
203-
}
204-
197+
let infoPlistContent: string = await getFileContents(infoPlistPath, false);
205198
const infoPlist = plist.parse(infoPlistContent) as any;
206199
let cFBundleShortVersionString: string = infoPlist['CFBundleShortVersionString'];
207200

@@ -256,6 +249,10 @@ export async function GetProjectDetails(credential: AppleCredential, xcodeVersio
256249
projectRef.entitlementsPath = entitlementsPath;
257250
}
258251

252+
if (projectRef.entitlementsPath) {
253+
await getFileContents(projectRef.entitlementsPath);
254+
}
255+
259256
if (projectRef.isAppStoreUpload()) {
260257
projectRef.appId = await GetAppId(projectRef);
261258

@@ -354,15 +351,7 @@ export async function GetProjectDetails(credential: AppleCredential, xcodeVersio
354351
}
355352
}
356353

357-
const plistHandle = await fs.promises.open(infoPlistPath, fs.constants.O_RDONLY);
358-
359-
try {
360-
infoPlistContent = await fs.promises.readFile(plistHandle, 'utf8');
361-
} finally {
362-
await plistHandle.close();
363-
}
364-
365-
core.info(`------- Info.plist content: -------\n${infoPlistContent}\n-----------------------------------`);
354+
infoPlistContent = await getFileContents(infoPlistPath);
366355
return projectRef;
367356
}
368357

@@ -594,18 +583,13 @@ async function getExportOptions(projectRef: XcodeProject): Promise<void> {
594583
exportOptionsPath = exportOptionPlistInput;
595584
}
596585
core.info(`Export options path: ${exportOptionsPath}`);
586+
597587
if (!exportOptionsPath) {
598588
throw new Error(`Invalid path for export-option-plist: ${exportOptionsPath}`);
599589
}
600-
const exportOptionsHandle = await fs.promises.open(exportOptionsPath, fs.constants.O_RDONLY);
601-
try {
602-
const exportOptionContent = await fs.promises.readFile(exportOptionsHandle, 'utf8');
603-
core.info(`----- Export options content: -----\n${exportOptionContent}\n-----------------------------------`);
604-
const exportOptions = plist.parse(exportOptionContent);
605-
projectRef.exportOption = exportOptions['method'];
606-
} finally {
607-
await exportOptionsHandle.close();
608-
}
590+
591+
await getFileContents(exportOptionsPath);
592+
609593
projectRef.exportOptionsPath = exportOptionsPath;
610594
}
611595

@@ -701,15 +685,6 @@ export async function ArchiveXcodeProject(projectRef: XcodeProject): Promise<Xco
701685
);
702686
}
703687
if (entitlementsPath) {
704-
core.debug(`Entitlements path: ${entitlementsPath}`);
705-
const entitlementsHandle = await fs.promises.open(entitlementsPath, fs.constants.O_RDONLY);
706-
try {
707-
const entitlementsContent = await fs.promises.readFile(entitlementsHandle, 'utf8');
708-
core.startGroup(`----- Entitlements content: -----\n${entitlementsContent}\n-----------------------------------`);
709-
} finally {
710-
await entitlementsHandle.close();
711-
core.endGroup();
712-
}
713688
archiveArgs.push(`CODE_SIGN_ENTITLEMENTS=${entitlementsPath}`);
714689
}
715690
if (platform === 'iOS') {

0 commit comments

Comments
 (0)