Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- fix input paths resolving
  • Loading branch information
StephenHodgson authored Nov 1, 2024
1 parent 75589f8 commit 24ff9b2
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 58 deletions.
80 changes: 52 additions & 28 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30552,33 +30552,49 @@ const main = async () => {
if (process.platform !== `win32`) {
throw new Error(`This action can only run on Windows runner.`);
}
const projectPath = core.getInput(`project-path`, { required: true });
const globber = await glob.create(path.join(projectPath, `**/*.sln`));
const files = await globber.glob();
if (files.length === 0) {
throw new Error(`No solution file found.`);
}
const buildPath = files[0];
core.info(`Building ${buildPath}`);
let projectPath = core.getInput(`project-path`, { required: true });
core.debug(`project-path: "${projectPath}"`);
if (!projectPath.endsWith(`.sln`)) {
projectPath = path.join(projectPath, `**/*.sln`);
}
let buildPath = projectPath;
if (projectPath.includes('*')) {
const globber = await glob.create(projectPath, { matchDirectories: false });
const files = await globber.glob();
core.debug(`Found solution files:`);
files.forEach(file => core.debug(` - "${file}"`));
if (files.length === 0) {
throw new Error(`No solution file found.`);
}
buildPath = files[0];
}
core.info(`Building ${buildPath}...`);
projectPath = path.dirname(buildPath);
try {
await fs.promises.access(buildPath, fs.constants.R_OK);
}
catch (error) {
throw new Error(`Solution file not found: "${buildPath}"`);
}
const appPackagesPath = path.join(projectPath, `AppPackages`);
if (fs.existsSync(appPackagesPath)) {
core.info(`Cleaning AppPackages directory: ${appPackagesPath}`);
core.info(`Cleaning AppPackages directory: ${appPackagesPath}...`);
await fs.promises.rm(appPackagesPath, { recursive: true, force: true });
}
let projectName = path.basename(buildPath, `.sln`);
core.info(`projectName: "${projectName}"`);
core.debug(`projectName: "${projectName}"`);
const configuration = core.getInput(`configuration`, { required: true });
const buildArgs = [
`/t:Build`,
`/p:Configuration=${configuration}`
];
const architecture = core.getInput(`architecture`);
if (architecture) {
core.info(`architecture: "${architecture}"`);
core.debug(`architecture: "${architecture}"`);
buildArgs.push(`/p:Platform=${architecture}`);
}
const packageType = core.getInput(`package-type`, { required: true });
core.info(`package-type: "${packageType}"`);
core.debug(`package-type: "${packageType}"`);
switch (packageType) {
case `upload`:
buildArgs.push(`/p:UapAppxPackageBuildMode=StoreUpload`, `/p:GenerateAppInstallerFile=false`, `/p:AppxPackageSigningEnabled=false`, `/p:BuildAppxUploadPackageForUap=true`);
Expand All @@ -30593,7 +30609,7 @@ const main = async () => {
}
const additionalArgs = core.getInput(`additional-args`);
if (additionalArgs) {
core.info(`additional-args: "${additionalArgs}"`);
core.debug(`additional-args: "${additionalArgs}"`);
buildArgs.push(...additionalArgs.split(` `));
}
if (!core.isDebug()) {
Expand All @@ -30603,7 +30619,7 @@ const main = async () => {
windowsVerbatimArguments: true
});
const outputDirectory = path.join(projectPath, `AppPackages`);
core.info(`outputDirectory: ${outputDirectory}`);
core.debug(`outputDirectory: ${outputDirectory}`);
core.setOutput(`output-directory`, outputDirectory);
const patterns = [
`${outputDirectory}/**/*.appx`,
Expand All @@ -30620,8 +30636,8 @@ const main = async () => {
core.warning(`No executables found.`);
return;
}
core.info(`Found executables:`);
executables.forEach(executable => core.info(` - "${executable}"`));
core.debug(`Found executables:`);
executables.forEach(executable => core.debug(` - "${executable}"`));
let executable;
switch (packageType) {
case `upload`:
Expand All @@ -30631,7 +30647,7 @@ const main = async () => {
executable = executables.find(file => file.endsWith(`.appx`) || file.endsWith(`.msix`));
break;
}
core.info(`Found executable: "${executable}"`);
core.debug(`Found executable: "${executable}"`);
core.setOutput(`executable`, executable);
}
catch (error) {
Expand All @@ -30641,18 +30657,26 @@ const main = async () => {
main();
async function getCertificatePath(projectPath) {
let certificatePath = core.getInput(`certificate-path`) || `${projectPath}/**/*.pfx`;
const certificateGlobber = await glob.create(certificatePath);
const certificateFiles = await certificateGlobber.glob();
switch (certificateFiles.length) {
case 0:
throw new Error(`No certificate file found. Please set the 'certificate-path' input.`);
default:
if (certificateFiles.length > 1) {
core.warning(`More than one certificate file found, using the first one found:\n${certificateFiles.join(`\n`)}`);
}
certificatePath = certificateFiles[0];
core.debug(`certificatePath: "${certificatePath}"`);
if (!certificatePath.endsWith(`.pfx`)) {
certificatePath = path.join(certificatePath, `**/*.pfx`);
}
if (certificatePath.includes(`*`)) {
const certificateGlobber = await glob.create(certificatePath);
const certificateFiles = await certificateGlobber.glob();
core.debug(`Found certificate files:`);
certificateFiles.forEach(file => core.debug(` - "${file}"`));
if (certificateFiles.length === 0) {
throw new Error(`No certificate file found: "${certificatePath}"`);
}
certificatePath = certificateFiles[0];
}
try {
await fs.promises.access(certificatePath, fs.constants.R_OK);
}
catch (error) {
throw new Error(`Certificate file not found: "${certificatePath}"`);
}
await fs.promises.access(certificatePath, fs.constants.R_OK);
return certificatePath;
}
async function getCertificateThumbprint(certificatePath) {
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-uwp-builder",
"version": "1.0.2",
"version": "1.0.3",
"description": "A GitHub Action to build Unity exported UWP projects.",
"author": "buildalon",
"license": "MIT",
Expand Down
74 changes: 48 additions & 26 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,46 @@ import fs = require('fs');
const main = async () => {
try {
if (process.platform !== `win32`) { throw new Error(`This action can only run on Windows runner.`); }
const projectPath = core.getInput(`project-path`, { required: true });
const globber = await glob.create(path.join(projectPath, `**/*.sln`));
const files = await globber.glob();
if (files.length === 0) { throw new Error(`No solution file found.`); }
const buildPath = files[0];
core.info(`Building ${buildPath}`);
let projectPath = core.getInput(`project-path`, { required: true });
core.debug(`project-path: "${projectPath}"`);
if (!projectPath.endsWith(`.sln`)) {
projectPath = path.join(projectPath, `**/*.sln`);
}
let buildPath = projectPath;
if (projectPath.includes('*')) {
const globber = await glob.create(projectPath, { matchDirectories: false });
const files = await globber.glob();
core.debug(`Found solution files:`);
files.forEach(file => core.debug(` - "${file}"`));
if (files.length === 0) { throw new Error(`No solution file found.`); }
buildPath = files[0];
}
core.info(`Building ${buildPath}...`);
projectPath = path.dirname(buildPath);
try {
await fs.promises.access(buildPath, fs.constants.R_OK);
} catch (error) {
throw new Error(`Solution file not found: "${buildPath}"`);
}
const appPackagesPath = path.join(projectPath, `AppPackages`);
if (fs.existsSync(appPackagesPath)) {
core.info(`Cleaning AppPackages directory: ${appPackagesPath}`);
core.info(`Cleaning AppPackages directory: ${appPackagesPath}...`);
await fs.promises.rm(appPackagesPath, { recursive: true, force: true });
}
let projectName = path.basename(buildPath, `.sln`);
core.info(`projectName: "${projectName}"`);
core.debug(`projectName: "${projectName}"`);
const configuration = core.getInput(`configuration`, { required: true });
const buildArgs = [
`/t:Build`,
`/p:Configuration=${configuration}`
];
const architecture = core.getInput(`architecture`);
if (architecture) {
core.info(`architecture: "${architecture}"`);
core.debug(`architecture: "${architecture}"`);
buildArgs.push(`/p:Platform=${architecture}`);
}
const packageType = core.getInput(`package-type`, { required: true });
core.info(`package-type: "${packageType}"`);
core.debug(`package-type: "${packageType}"`);
switch (packageType) {
case `upload`:
buildArgs.push(
Expand All @@ -56,7 +71,7 @@ const main = async () => {
}
const additionalArgs = core.getInput(`additional-args`);
if (additionalArgs) {
core.info(`additional-args: "${additionalArgs}"`);
core.debug(`additional-args: "${additionalArgs}"`);
buildArgs.push(...additionalArgs.split(` `));
}
if (!core.isDebug()) {
Expand All @@ -66,7 +81,7 @@ const main = async () => {
windowsVerbatimArguments: true
});
const outputDirectory = path.join(projectPath, `AppPackages`);
core.info(`outputDirectory: ${outputDirectory}`);
core.debug(`outputDirectory: ${outputDirectory}`);
core.setOutput(`output-directory`, outputDirectory);
const patterns = [
`${outputDirectory}/**/*.appx`,
Expand All @@ -83,8 +98,8 @@ const main = async () => {
core.warning(`No executables found.`);
return;
}
core.info(`Found executables:`);
executables.forEach(executable => core.info(` - "${executable}"`));
core.debug(`Found executables:`);
executables.forEach(executable => core.debug(` - "${executable}"`));
let executable: string;
switch (packageType) {
case `upload`:
Expand All @@ -94,7 +109,7 @@ const main = async () => {
executable = executables.find(file => file.endsWith(`.appx`) || file.endsWith(`.msix`));
break;
}
core.info(`Found executable: "${executable}"`);
core.debug(`Found executable: "${executable}"`);
core.setOutput(`executable`, executable);
} catch (error) {
core.setFailed(error);
Expand All @@ -105,18 +120,25 @@ main();

async function getCertificatePath(projectPath: string): Promise<string> {
let certificatePath = core.getInput(`certificate-path`) || `${projectPath}/**/*.pfx`;
const certificateGlobber = await glob.create(certificatePath);
const certificateFiles = await certificateGlobber.glob();
switch (certificateFiles.length) {
case 0:
throw new Error(`No certificate file found. Please set the 'certificate-path' input.`);
default:
if (certificateFiles.length > 1) {
core.warning(`More than one certificate file found, using the first one found:\n${certificateFiles.join(`\n`)}`);
}
certificatePath = certificateFiles[0];
core.debug(`certificatePath: "${certificatePath}"`);
if (!certificatePath.endsWith(`.pfx`)) {
certificatePath = path.join(certificatePath, `**/*.pfx`);
}
if (certificatePath.includes(`*`)) {
const certificateGlobber = await glob.create(certificatePath);
const certificateFiles = await certificateGlobber.glob();
core.debug(`Found certificate files:`);
certificateFiles.forEach(file => core.debug(` - "${file}"`));
if (certificateFiles.length === 0) {
throw new Error(`No certificate file found: "${certificatePath}"`);
}
certificatePath = certificateFiles[0];
}
try {
await fs.promises.access(certificatePath, fs.constants.R_OK);
} catch (error) {
throw new Error(`Certificate file not found: "${certificatePath}"`);
}
await fs.promises.access(certificatePath, fs.constants.R_OK);
return certificatePath;
}

Expand Down

0 comments on commit 24ff9b2

Please sign in to comment.