Skip to content

Commit

Permalink
setup-ovr-platform-util@1.1.2 (#11)
Browse files Browse the repository at this point in the history
- misc cleanup and refactoring
  • Loading branch information
StephenHodgson authored Jul 27, 2024
1 parent bb5e87d commit 8cdc46f
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 143 deletions.
1 change: 0 additions & 1 deletion .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ jobs:
uses: ./

- run: 'ovr-platform-util version'
shell: pwsh
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Setup OVR Platform Util
# setup-ovr-platform-utility

A GitHub Action to setup the [ovr platform utility tool](https://developer.oculus.com/resources/publish-reference-platform-command-line-utility/)
A GitHub Action to setup the [`ovr-platform-utility`](https://developer.oculus.com/resources/publish-reference-platform-command-line-utility/) tool command alias.

## How to use

Expand All @@ -15,8 +15,10 @@ jobs:
steps:
# download and setup ovr platform util
- uses: RageAgainstThePixel/setup-ovr-platform-util@v1

# run commands
- run: 'ovr-platform-util version'
shell: pwsh
```
## Related actions
- [upload-meta-quest-build](https://github.com/RageAgainstThePixel/upload-meta-quest-build)
107 changes: 47 additions & 60 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33948,113 +33948,100 @@ module.exports = parseParams
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
(() => {
const os = __nccwpck_require__(2037);
const semver = __nccwpck_require__(1383);
const path = __nccwpck_require__(1017);
const core = __nccwpck_require__(2186);
const tc = __nccwpck_require__(7784);
const exec = __nccwpck_require__(1514);
const fs = (__nccwpck_require__(7147).promises);

const ovrPlatformUtil = 'ovr-platform-util';
const IS_WINDOWS = process.platform === 'win32'
const IS_MAC = process.platform === 'darwin'
const toolExtension = IS_WINDOWS ? '.exe' : '';
const toolPath = `${ovrPlatformUtil}${toolExtension}`;

const main = async () => {
try {
const fileEx = IS_WINDOWS ? '.exe' : '';
let osPlatform = os.platform();
let pathToModule = undefined;
let pathToToolDir = tc.find(ovrPlatformUtil, '1.98.0');

if (!pathToToolDir) {
let url = undefined;
let downloadPath = undefined;

if (IS_MAC) {
url = 'https://www.oculus.com/download_app/?id=1462426033810370';
} else if (IS_WINDOWS) {
url = 'https://www.oculus.com/download_app/?id=1076686279105243';
} else {
throw Error(`${ovrPlatformUtil} not available for ${osPlatform}`);
}

let fileName = `${ovrPlatformUtil}${fileEx}`;
downloadPath = path.resolve(getTempDirectory(), fileName);

core.debug(`Attempting to download ${ovrPlatformUtil} from ${url} to ${downloadPath}`);

try {
downloadPath = await tc.downloadTool(url, downloadPath);
} catch (error) {
throw error;
}

core.debug(`Successfully downloaded ${ovrPlatformUtil} to ${downloadPath}`);

if (IS_MAC) {
await exec.exec(`chmod +x ${downloadPath}`);
}

const downloadVersion = await getVersion(downloadPath);
core.debug(`Setting tool cache: ${downloadPath} | ${fileName} | ${ovrPlatformUtil} | ${downloadVersion}`);
pathToToolDir = await tc.cacheFile(downloadPath, fileName, ovrPlatformUtil, downloadVersion);
pathToModule = getExecutable(pathToToolDir);
} else {
pathToModule = getExecutable(pathToToolDir);
await exec.exec(pathToModule, 'self-update');
}

core.debug(`${ovrPlatformUtil} -> ${pathToModule}`);
core.addPath(pathToToolDir);
core.exportVariable(ovrPlatformUtil, pathToModule);

await exec.exec(pathToModule, 'help');
core.info(`Setting up ${ovrPlatformUtil}...`);
await setup_ovrPlatformUtil();
} catch (error) {
core.setFailed(error);
}
}

main();

async function setup_ovrPlatformUtil() {
let toolDirectory = tc.find(ovrPlatformUtil, '*');
let tool = undefined;
if (!toolDirectory) {
const url = getDownloadUrl();
const archiveDownloadPath = path.resolve(getTempDirectory(), toolPath);
core.debug(`Attempting to download ${ovrPlatformUtil} from ${url} to ${archiveDownloadPath}`);
const archivePath = await tc.downloadTool(url, archiveDownloadPath);
core.debug(`Successfully downloaded ${ovrPlatformUtil} to ${archivePath}`);
if (IS_MAC) {
await exec.exec(`chmod +x ${archivePath}`);
}
const downloadVersion = await getVersion(archivePath);
core.debug(`Setting tool cache: ${archivePath} | ${toolPath} | ${ovrPlatformUtil} | ${downloadVersion}`);
toolDirectory = await tc.cacheFile(archivePath, toolPath, ovrPlatformUtil, downloadVersion);
tool = getExecutable(toolDirectory);
} else {
tool = getExecutable(toolDirectory);
fs.access(tool);
core.debug(`Found ${tool} in ${toolDirectory}`);
await exec.exec(tool, 'self-update');
}
core.debug(`${ovrPlatformUtil} -> ${toolDirectory}`)
core.addPath(toolDirectory);
await exec.exec(ovrPlatformUtil, 'help');
}

function getDownloadUrl() {
if (IS_MAC) {
return 'https://www.oculus.com/download_app/?id=1462426033810370';
} else if (IS_WINDOWS) {
return 'https://www.oculus.com/download_app/?id=1076686279105243';
} else {
throw Error(`${ovrPlatformUtil} not available for ${process.platform}`);
}
}

function getTempDirectory() {
const tempDirectory = process.env['RUNNER_TEMP'] || ''
return tempDirectory
}

function getExecutable(dir) {
const fileEx = IS_WINDOWS ? '.exe' : '';
const moduleName = `${ovrPlatformUtil}${fileEx}`;
return path.resolve(dir, moduleName);
function getExecutable(directory) {
return path.resolve(directory, toolPath);
}

async function getVersion(module) {
async function getVersion(tool) {
const semVerRegEx = new RegExp(/([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)?/);
let output = '';

await exec.exec(module, 'version', {
await exec.exec(tool, 'version', {
listeners: {
stdout: (data) => {
output += data.toString();
}
}
});

const match = output.match(semVerRegEx)[0];

if (!match) {
throw Error("Failed to find a valid version match");
}

const lastPeriodIndex = match.lastIndexOf('.');
const semVerStr = match.substring(0, lastPeriodIndex) + '+' + match.substring(lastPeriodIndex + 1);
const version = semver.clean(semVerStr);

if (!version) {
throw Error("Failed to find a valid version");
}

return version
}

})();

module.exports = __webpack_exports__;
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.

36 changes: 22 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
{
"name": "setup-ovr-platform-util",
"version": "1.1.1",
"version": "1.1.2",
"description": "A GitHub Action to setup the ovr platform utility tool",
"author": "RageAgainstThePixel",
"repository": {
"type": "git",
"url": "git+https://github.com/RageAgainstThePixel/setup-ovr-platform-util.git"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/RageAgainstThePixel/setup-ovr-platform-util/issues"
},
"homepage": "https://github.com/RageAgainstThePixel/setup-ovr-platform-util#readme",
"keywords": [
"oculus",
"ovr",
"platform",
"utility",
"setup",
"github",
"action"
],
"main": "src/index.js",
"dependencies": {
"@actions/core": "^1.10.1",
Expand All @@ -15,16 +34,5 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "ncc build src/index.js -o dist --source-map --license licenses.txt"
},
"repository": {
"type": "git",
"url": "git+https://github.com/RageAgainstThePixel/setup-ovr-platform-util.git"
},
"keywords": [],
"author": "Stephen Hodgson",
"license": "MIT",
"bugs": {
"url": "https://github.com/RageAgainstThePixel/setup-ovr-platform-util/issues"
},
"homepage": "https://github.com/RageAgainstThePixel/setup-ovr-platform-util#readme"
}
}
}
Loading

0 comments on commit 8cdc46f

Please sign in to comment.