Skip to content

Commit

Permalink
setup-ovr-platform-util@v1.0.3 (#4)
Browse files Browse the repository at this point in the history
- added `self-update` option
- refactoring and optimization
  • Loading branch information
StephenHodgson authored Sep 11, 2024
1 parent 910f01e commit 09140cf
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 28 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 |
| ---- | ----------- | -------- |
| `self-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'
34 changes: 22 additions & 12 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33273,25 +33273,32 @@ 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));
tool = await getExecutable(toolDirectory);
const selfUpdate = (core.getInput('self-update') || 'true') === 'true';
if (selfUpdate) {
await exec.exec(tool, ['self-update']);
await checkToolAccess(tool);
}
}
core.debug(`${ovrPlatformUtil} -> ${toolDirectory}`);
core.addPath(toolDirectory);
await exec.exec(ovrPlatformUtil, ['help']);
}
async function checkToolAccess(tool, retries = 5) {
await new Promise(resolve => setTimeout(resolve, 1000));
try {
await exec.exec(ovrPlatformUtil, ['help']);
await fs.promises.access(tool, fs.constants.X_OK);
}
catch (error) {
if (error.code === 'EBUSY') {
core.warning(`Waiting for ${tool} to be released...`);
await new Promise(resolve => setTimeout(resolve, 1000));
await exec.exec(ovrPlatformUtil, ['help']);
core.warning(`Failed to access ${tool}, retrying...`);
await checkToolAccess(tool, retries - 1);
}
else {
throw error;
}
}
}
Expand All @@ -33310,8 +33317,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
34 changes: 22 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,30 @@ 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));
tool = await getExecutable(toolDirectory);
const selfUpdate = (core.getInput('self-update') || 'true') === 'true';
if (selfUpdate) {
await exec.exec(tool, ['self-update']);
await checkToolAccess(tool);
}
}
core.debug(`${ovrPlatformUtil} -> ${toolDirectory}`)
core.addPath(toolDirectory);
await exec.exec(ovrPlatformUtil, ['help']);
}

async function checkToolAccess(tool: string, retries = 5): Promise<void> {
await new Promise(resolve => setTimeout(resolve, 1000));
try {
await exec.exec(ovrPlatformUtil, ['help']);
await fs.promises.access(tool, fs.constants.X_OK);
} catch (error) {
if (error.code === 'EBUSY') {
core.warning(`Waiting for ${tool} to be released...`);
await new Promise(resolve => setTimeout(resolve, 1000));
await exec.exec(ovrPlatformUtil, ['help']);
core.warning(`Failed to access ${tool}, retrying...`);
await checkToolAccess(tool, retries - 1);
} else {
throw error;
}
}
}
Expand All @@ -73,8 +80,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 09140cf

Please sign in to comment.