Skip to content

Commit

Permalink
setup-ovr-platform-util@v1.0.3
Browse files Browse the repository at this point in the history
- added auto-update
- refactoring and optimization
  • Loading branch information
StephenHodgson committed Sep 11, 2024
1 parent 910f01e commit afebf6b
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 39 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ jobs:
# run commands
- run: 'ovr-platform-util version'
```
### inputs
| Name | Description | Required |
| ---- | ----------- | -------- |
| `auto-update` | Automatically update the ovr-platform-util tool. | Defaults to `true`. |
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ description: 'A GitHub Action to setup the ovr-platform-util tool command alias.
branding:
icon: 'terminal'
color: 'red'
inputs:
self-update:
description: 'Automatically perform self update of ovr-platform-util tool.'
required: false
default: 'true'
runs:
using: 'node20'
main: 'dist/index.js'
32 changes: 14 additions & 18 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33273,27 +33273,20 @@ async function setup_ovrPlatformUtil() {
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);
tool = await getExecutable(toolDirectory);
}
else {
tool = getExecutable(toolDirectory);
fs.promises.access(tool);
core.debug(`Found ${tool} in ${toolDirectory}`);
await exec.exec(tool, ['self-update']);
await new Promise(resolve => setTimeout(resolve, 1000));
}
core.debug(`${ovrPlatformUtil} -> ${toolDirectory}`);
core.addPath(toolDirectory);
try {
await exec.exec(ovrPlatformUtil, ['help']);
}
catch (error) {
if (error.code === 'EBUSY') {
core.warning(`Waiting for ${tool} to be released...`);
tool = await getExecutable(toolDirectory);
const selfUpdate = (core.getInput('self-update') || 'true') === 'true';
if (selfUpdate) {
await exec.exec(tool, ['self-update']);
await new Promise(resolve => setTimeout(resolve, 1000));
await exec.exec(ovrPlatformUtil, ['help']);
await fs.promises.access(tool, fs.constants.X_OK);
}
}
core.debug(`${ovrPlatformUtil} -> ${toolDirectory}`);
core.addPath(toolDirectory);
await exec.exec(ovrPlatformUtil, ['help']);
}
function getDownloadUrl() {
if (IS_MAC) {
Expand All @@ -33310,8 +33303,11 @@ function getTempDirectory() {
const tempDirectory = process.env['RUNNER_TEMP'] || '';
return tempDirectory;
}
function getExecutable(directory) {
return path.join(directory, toolPath);
async function getExecutable(directory) {
const tool = path.join(directory, toolPath);
await fs.promises.access(tool, fs.constants.X_OK);
core.debug(`Found ${tool} in ${directory}`);
return tool;
}
async function getVersion(tool) {
const semVerRegEx = new RegExp(/([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)?/);
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": "setup-ovr-platform-util",
"version": "1.0.2",
"version": "1.0.3",
"description": "A GitHub Action to setup the ovr-platform-util tool command alias.",
"author": "buildalon",
"repository": {
Expand Down
31 changes: 14 additions & 17 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,19 @@ async function setup_ovrPlatformUtil(): Promise<void> {
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);
tool = await getExecutable(toolDirectory);
} else {
tool = getExecutable(toolDirectory);
fs.promises.access(tool);
core.debug(`Found ${tool} in ${toolDirectory}`);
await exec.exec(tool, ['self-update']);
await new Promise(resolve => setTimeout(resolve, 1000));
}
core.debug(`${ovrPlatformUtil} -> ${toolDirectory}`)
core.addPath(toolDirectory);
try {
await exec.exec(ovrPlatformUtil, ['help']);
} catch (error) {
if (error.code === 'EBUSY') {
core.warning(`Waiting for ${tool} to be released...`);
tool = await getExecutable(toolDirectory);
const selfUpdate = (core.getInput('self-update') || 'true') === 'true';
if (selfUpdate) {
await exec.exec(tool, ['self-update']);
await new Promise(resolve => setTimeout(resolve, 1000));
await exec.exec(ovrPlatformUtil, ['help']);
await fs.promises.access(tool, fs.constants.X_OK);
}
}
core.debug(`${ovrPlatformUtil} -> ${toolDirectory}`)
core.addPath(toolDirectory);
await exec.exec(ovrPlatformUtil, ['help']);
}

function getDownloadUrl(): string {
Expand All @@ -73,8 +67,11 @@ function getTempDirectory(): string {
return tempDirectory
}

function getExecutable(directory: string): string {
return path.join(directory, toolPath);
async function getExecutable(directory: string): Promise<string> {
const tool = path.join(directory, toolPath);
await fs.promises.access(tool, fs.constants.X_OK);
core.debug(`Found ${tool} in ${directory}`);
return tool;
}

async function getVersion(tool: string): Promise<string> {
Expand Down

0 comments on commit afebf6b

Please sign in to comment.