Skip to content

[email protected] #25

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
43 changes: 21 additions & 22 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ jobs:
matrix:
os: [macos-latest]
unity-version: [2021.x, 2022.3.x, 6000.x]
build-target:
- iOS
- StandaloneOSX
- VisionOS
build-target: [iOS, StandaloneOSX, VisionOS]
exclude:
- os: macos-latest
unity-version: 2021.x
build-target: VisionOS
- os: macos-latest
unity-version: 2022.3.x
build-target: VisionOS
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -49,28 +49,27 @@ jobs:
unity-version: ${{ matrix.unity-version }}
architecture: 'arm64'
- name: Find Unity Template Path and Version
shell: bash
run: |
$rootPath = $env:UNITY_EDITOR_PATH -replace "Editor.*", ""
Write-Host "ROOT_PATH=$rootPath"
$templatePath = Get-ChildItem -Recurse -Filter "com.unity.template.3d*.tgz" -Path $rootPath | Select-Object -First 1 | Select-Object -ExpandProperty FullName
Write-Host "TEMPLATE_PATH=$templatePath"
echo "TEMPLATE_PATH=$templatePath" >> $env:GITHUB_ENV
$projectPath = "${{ github.workspace }}/UnityProject"
echo "UNITY_PROJECT_PATH=$projectPath" >> $env:GITHUB_ENV
rootPath=${UNITY_EDITOR_PATH/Editor*/}
echo "ROOT_PATH=$rootPath"
templatePath=$(find "$rootPath" -type f -name "com.unity.template.3d*.tgz" | head -n 1)
echo "TEMPLATE_PATH=$templatePath"
echo "TEMPLATE_PATH=$templatePath" >> $GITHUB_ENV
projectPath="${{ github.workspace }}/UnityProject"
echo "UNITY_PROJECT_PATH=$projectPath" >> $GITHUB_ENV

# Read version from package.json instead of git tags
$packageJsonPath = "${{ github.workspace }}/package.json"
$packageJson = Get-Content -Raw -Path $packageJsonPath | ConvertFrom-Json
$version = $packageJson.version
packageJsonPath="${{ github.workspace }}/package.json"
version=$(jq -r '.version' "$packageJsonPath")

if ($version -match '^\d+\.\d+\.\d+$') {
Write-Host "Version from package.json: $version"
} else {
Write-Host "Version: $version is not a valid version string"
exit 1
}
echo "VERSION=$version" >> $env:GITHUB_ENV
shell: pwsh
if [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Version from package.json: $version"
else
echo "Version: $version is not a valid version string"
exit 1
fi
echo "VERSION=$version" >> $GITHUB_ENV
- uses: RageAgainstThePixel/activate-unity-license@v1
with:
license: 'Personal'
Expand Down
135 changes: 84 additions & 51 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57500,7 +57500,7 @@ function checkAuthError(error) {
}
async function GetAppId(project) {
if (project.appId) {
return project;
return project.appId;
}
await getOrCreateClient(project);
const { data: response, error } = await appStoreConnectClient.api.AppsService.appsGetCollection({
Expand All @@ -57517,7 +57517,7 @@ async function GetAppId(project) {
throw new Error(`No apps found for bundle id ${project.bundleId}`);
}
project.appId = response.data[0].id;
return project;
return project.appId;
}
async function GetLatestBundleVersion(project) {
await getOrCreateClient(project);
Expand Down Expand Up @@ -57548,7 +57548,7 @@ function reMapPlatform(project) {
async function getLastPreReleaseVersionAndBuild(project) {
var _a, _b, _c, _d, _e;
if (!project.appId) {
project = await GetAppId(project);
project.appId = await GetAppId(project);
}
const preReleaseVersionRequest = {
query: {
Expand Down Expand Up @@ -58004,6 +58004,10 @@ async function GetProjectDetails(credential, xcodeVersion) {
let projectPath = undefined;
const globber = await glob.create(projectPathInput);
const files = await globber.glob();
if (!files || files.length === 0) {
throw new Error(`No project found at: ${projectPathInput}`);
}
core.debug(`Files found during search: ${files.join(', ')}`);
const excludedProjects = ['GameAssembly', 'UnityFramework', 'Pods'];
for (const file of files) {
if (file.endsWith('.xcodeproj')) {
Expand All @@ -58017,7 +58021,7 @@ async function GetProjectDetails(credential, xcodeVersion) {
}
}
if (!projectPath) {
throw new Error('Invalid project-path! Unable to find .xcodeproj');
throw new Error(`Invalid project-path! Unable to find .xcodeproj in ${projectPathInput}. ${files.length} files were found but none matched.\n${files.join(', ')}`);
}
core.debug(`Resolved Project path: ${projectPath}`);
await fs.promises.access(projectPath, fs.constants.R_OK);
Expand Down Expand Up @@ -58054,14 +58058,33 @@ async function GetProjectDetails(credential, xcodeVersion) {
await infoPlistHandle.close();
}
const infoPlist = plist.parse(infoPlistContent);
const cFBundleShortVersionString = infoPlist['CFBundleShortVersionString'];
let cFBundleShortVersionString = infoPlist['CFBundleShortVersionString'];
if (cFBundleShortVersionString) {
const semverRegex = /^(?<major>\d+)\.(?<minor>\d+)\.(?<revision>\d+)/;
const match = cFBundleShortVersionString.match(semverRegex);
if (match) {
const { major, minor, revision } = match.groups;
cFBundleShortVersionString = `${major}.${minor}.${revision}`;
infoPlist['CFBundleShortVersionString'] = cFBundleShortVersionString.toString();
try {
core.info(`Updating Info.plist with CFBundleShortVersionString: ${cFBundleShortVersionString}`);
await fs.promises.writeFile(infoPlistPath, plist.build(infoPlist));
}
catch (error) {
throw new Error(`Failed to update Info.plist!\n${error}`);
}
}
else {
throw new Error(`Invalid CFBundleShortVersionString format: ${cFBundleShortVersionString}`);
}
}
core.info(`CFBundleShortVersionString: ${cFBundleShortVersionString}`);
const cFBundleVersion = infoPlist['CFBundleVersion'];
core.info(`CFBundleVersion: ${cFBundleVersion}`);
const projectRef = new XcodeProject_1.XcodeProject(projectPath, projectName, platform, destination, bundleId, projectDirectory, cFBundleShortVersionString, cFBundleVersion, scheme, credential, xcodeVersion);
await getExportOptions(projectRef);
if (projectRef.isAppStoreUpload() && core.getInput('auto-increment-build-number') === 'true') {
projectRef.credential.appleId = await getAppId(projectRef);
projectRef.appId = await (0, AppStoreConnectClient_1.GetAppId)(projectRef);
let bundleVersion = -1;
try {
bundleVersion = await (0, AppStoreConnectClient_1.GetLatestBundleVersion)(projectRef);
Expand All @@ -58073,7 +58096,7 @@ async function GetProjectDetails(credential, xcodeVersion) {
}
if (projectRef.bundleVersion <= bundleVersion) {
projectRef.bundleVersion = bundleVersion + 1;
core.debug(`Auto Incremented bundle version ==> ${projectRef.bundleVersion}`);
core.info(`Auto Incremented bundle version ==> ${projectRef.bundleVersion}`);
infoPlist['CFBundleVersion'] = projectRef.bundleVersion.toString();
try {
await fs.promises.writeFile(infoPlistPath, plist.build(infoPlist));
Expand Down Expand Up @@ -58609,42 +58632,6 @@ async function ValidateApp(projectRef) {
throw new Error(`Failed to validate app: ${JSON.stringify(JSON.parse(output), null, 2)}`);
}
}
async function getAppId(projectRef) {
const providersArgs = [
'altool',
'--list-apps',
'--apiKey', projectRef.credential.appStoreConnectKeyId,
'--apiIssuer', projectRef.credential.appStoreConnectIssuerId,
'--output-format', 'json'
];
let output = '';
if (!core.isDebug()) {
core.info(`[command]${xcrun} ${providersArgs.join(' ')}`);
}
const exitCode = await (0, exec_1.exec)(xcrun, providersArgs, {
listeners: {
stdout: (data) => {
output += data.toString();
}
},
ignoreReturnCode: true,
silent: !core.isDebug()
});
const response = JSON.parse(output);
const outputJson = JSON.stringify(response, null, 2);
if (exitCode > 0) {
(0, utilities_1.log)(outputJson, 'error');
throw new Error(`Failed to list providers`);
}
const app = response.applications.find((app) => app.ExistingBundleIdentifier === projectRef.bundleId);
if (!app) {
throw new Error(`App not found with bundleId: ${projectRef.bundleId}`);
}
if (!app.AppleID) {
throw new Error(`AppleID not found for app: ${JSON.stringify(app, null, 2)}`);
}
return app.AppleID;
}
async function UploadApp(projectRef) {
const platforms = {
'iOS': 'ios',
Expand All @@ -58656,7 +58643,7 @@ async function UploadApp(projectRef) {
'altool',
'--upload-package', projectRef.executablePath,
'--type', platforms[projectRef.platform],
'--apple-id', projectRef.credential.appleId,
'--apple-id', projectRef.appId,
'--bundle-id', projectRef.bundleId,
'--bundle-version', projectRef.bundleVersion,
'--bundle-short-version-string', projectRef.versionString,
Expand Down Expand Up @@ -60704,14 +60691,57 @@ const main = async () => {
let xcodeVersionString = core.getInput('xcode-version');
if (xcodeVersionString) {
core.info(`Setting xcode version to ${xcodeVersionString}`);
if (core.isDebug()) {
await exec.exec('xcodes', ['list']);
let xcodeVersionOutput = '';
const installedExitCode = await exec.exec('xcodes', ['installed'], {
listeners: {
stdout: (data) => {
xcodeVersionOutput += data.toString();
}
}
});
if (installedExitCode !== 0) {
throw new Error('Failed to get installed Xcode versions!');
}
if (xcodeVersionString.includes('latest')) {
await exec.exec('xcodes', ['install', '--latest', '--select']);
const installedXcodeVersions = xcodeVersionOutput.split('\n').map(line => {
const match = line.match(/(\d+\.\d+(\s\w+)?)/);
return match ? match[1] : null;
}).filter(Boolean);
core.debug(`Installed Xcode versions:\n ${installedXcodeVersions.join('\n')}`);
if (installedXcodeVersions.length === 0 ||
!xcodeVersionString.includes('latest')) {
if (installedXcodeVersions.length === 0 ||
!installedXcodeVersions.includes(xcodeVersionString)) {
const xcodesUsername = process.env.XCODES_USERNAME;
const xcodesPassword = process.env.XCODES_PASSWORD;
if (!xcodesUsername || !xcodesPassword) {
throw new Error(`Xcode version ${xcodeVersionString} is not installed! Please set XCODES_USERNAME and XCODES_PASSWORD to download it.`);
}
core.info(`Downloading missing Xcode version ${xcodeVersionString}...`);
const installExitCode = await exec.exec('xcodes', ['install', xcodeVersionString, '--select'], {
env: {
XCODES_USERNAME: xcodesUsername,
XCODES_PASSWORD: xcodesPassword
}
});
if (installExitCode !== 0) {
throw new Error(`Failed to install Xcode version ${xcodeVersionString}!`);
}
}
else {
core.info(`Selecting installed Xcode version ${xcodeVersionString}...`);
const selectExitCode = await exec.exec('xcodes', ['select', xcodeVersionString]);
if (selectExitCode !== 0) {
throw new Error(`Failed to select Xcode version ${xcodeVersionString}!`);
}
}
}
else {
await exec.exec('xcodes', ['install', xcodeVersionString, '--select']);
core.info(`Selecting latest installed Xcode version ${xcodeVersionString}...`);
xcodeVersionString = installedXcodeVersions[installedXcodeVersions.length - 1];
const selectExitCode = await exec.exec('xcodes', ['select', xcodeVersionString]);
if (selectExitCode !== 0) {
throw new Error(`Failed to select Xcode version ${xcodeVersionString}!`);
}
}
}
let xcodeVersionOutput = '';
Expand All @@ -60726,10 +60756,13 @@ const main = async () => {
if (!xcodeVersionMatch) {
throw new Error('Failed to get Xcode version!');
}
xcodeVersionString = xcodeVersionMatch.groups.version;
if (!xcodeVersionString) {
const selectedXcodeVersionString = xcodeVersionMatch.groups.version;
if (!selectedXcodeVersionString) {
throw new Error('Failed to parse Xcode version!');
}
if (xcodeVersionString !== selectedXcodeVersionString) {
throw new Error(`Selected Xcode version ${selectedXcodeVersionString} does not match requested version ${xcodeVersionString}!`);
}
let projectRef = await (0, xcode_1.GetProjectDetails)(credential, semver.coerce(xcodeVersionString));
projectRef = await (0, xcode_1.ArchiveXcodeProject)(projectRef);
projectRef = await (0, xcode_1.ExportXcodeArchive)(projectRef);
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unity-xcode-builder",
"version": "1.2.0",
"version": "1.2.1",
"description": "A GitHub Action to build, archive, and upload Unity exported xcode projects.",
"author": "RageAgainstThePixel",
"license": "MIT",
Expand Down
8 changes: 4 additions & 4 deletions src/AppStoreConnectClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ function checkAuthError(error: any) {
}
}

export async function GetAppId(project: XcodeProject): Promise<XcodeProject> {
if (project.appId) { return project; }
export async function GetAppId(project: XcodeProject): Promise<string> {
if (project.appId) { return project.appId; }
await getOrCreateClient(project);
const { data: response, error } = await appStoreConnectClient.api.AppsService.appsGetCollection({
query: { 'filter[bundleId]': [project.bundleId] }
Expand All @@ -65,7 +65,7 @@ export async function GetAppId(project: XcodeProject): Promise<XcodeProject> {
throw new Error(`No apps found for bundle id ${project.bundleId}`);
}
project.appId = response.data[0].id;
return project;
return project.appId;
}

export async function GetLatestBundleVersion(project: XcodeProject): Promise<number> {
Expand Down Expand Up @@ -97,7 +97,7 @@ function reMapPlatform(project: XcodeProject): ('IOS' | 'MAC_OS' | 'TV_OS' | 'VI
}

async function getLastPreReleaseVersionAndBuild(project: XcodeProject): Promise<PreReleaseVersionWithBuild> {
if (!project.appId) { project = await GetAppId(project); }
if (!project.appId) { project.appId = await GetAppId(project); }
const preReleaseVersionRequest: PreReleaseVersionsGetCollectionData = {
query: {
'filter[app]': [project.appId],
Expand Down
1 change: 0 additions & 1 deletion src/AppleCredential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class AppleCredential {
signingIdentity?: string;
provisioningProfileUUID?: string;
bearerToken?: string;
appleId?: string;
ascPublicId?: string;
}

Expand Down
2 changes: 1 addition & 1 deletion src/XcodeProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class XcodeProject {
projectPath: string;
projectName: string;
bundleId: string;
appId: string;
projectDirectory: string;
credential: AppleCredential;
platform: string;
Expand All @@ -40,7 +41,6 @@ export class XcodeProject {
exportOption: string;
exportOptionsPath: string;
entitlementsPath: string;
appId: string;
versionString: string;
bundleVersion: number;
scheme: string;
Expand Down
Loading
Loading