Skip to content
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

Fix archives that are wrapped in a directory #11

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{

Check warning on line 1 in .markdownlint.json

View workflow job for this annotation

GitHub Actions / Lint Codebase

File ignored by default.
"default": true,
"MD033": false,
"MD041": false
}
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
This action provides downloading and caching distribution of the requested Kit
CLI, and adding it to the PATH

## Simplify handoffs between data scientists, app devs, and DevOps.
## Simplify handoffs between data scientists, app devs, and DevOps

[![LICENSE](https://img.shields.io/badge/License-Apache%202.0-yellow.svg)](https://github.com/myscale/myscaledb/blob/main/LICENSE)
[![Discord](https://img.shields.io/discord/1098133460310294528?logo=Discord)](https://discord.gg/Tapeh8agYy)
Expand All @@ -24,8 +24,6 @@ create a unified package for models, their dependencies, configurations, and
environments. The ModelKit is portable and uses open standards for compatibility
with the tools you already use.

https://github.com/jozu-ai/kitops/assets/10517533/8f7539e1-b0d2-43c4-abfe-31841d4c68bd

## Usage

See [action.yml](action.yml)
Expand All @@ -44,7 +42,7 @@ See [action.yml](action.yml)
token: ''
```

#### Basic
### Basic

```YAML
steps:
Expand All @@ -58,7 +56,7 @@ steps:
kit version
```

#### Pin a kit version
### Pin a kit version

```YAML
steps:
Expand Down Expand Up @@ -92,7 +90,7 @@ detailed examples please refer to
> version when you `cd` into the repository. Additionally, this `.node-version`
> file is used by GitHub Actions in any `actions/setup-node` actions.

1. Clone this reposutory
1. Clone this repository

1. :hammer_and_wrench: Install the dependencies

Expand Down
32 changes: 28 additions & 4 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

45 changes: 40 additions & 5 deletions src/installer/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,51 @@ export async function getExecutableTargetDir(): Promise<string> {
async function extract(archive: string, dest: string): Promise<string> {
const basename = path.basename(archive)
const extname = path.extname(basename)
let extractedPath = ''
if (extname === '.zip') {
return await ghToolCache.extractZip(archive, dest)
extractedPath = await ghToolCache.extractZip(archive, dest)
}
if (basename.endsWith('.tar.gz') || basename.endsWith('.tgz')) {
return await ghToolCache.extractTar(archive, dest)
extractedPath = await ghToolCache.extractTar(archive, dest)
}
throw new Error(
`No way to extract ${archive}:
Unknown file type "${basename}" - Supported formats are .zip and .tar.gz`
ghCore.debug(`Extracted to ${extractedPath}`)
if (extractedPath === '') {
throw new Error(
`Failed to extract ${archive}:
Unknown file type "${basename}" - Supported formats are .zip and .tar.gz`
)
}

const extractedDir = path.dirname(extractedPath)
const files = fs.readdirSync(extractedDir, {
withFileTypes: true,
recursive: true
})
const kitExecutable = files.filter(
file => file.isFile() && file.name === getExecutableBinaryName()
)
if (kitExecutable.length === 0) {
throw new Error(
`Failed to find executable binary in extracted archive: ${archive}`
)
}
// In some cases, the extracted binary is in a subdirectory of the extracted archive
// In this case, move the binary to the root of the extracted archive
ghCore.debug(
`Checking if extracted binary is in a subdirectory for ${kitExecutable[0].name} on path ${kitExecutable[0].path}`
)
if (kitExecutable[0].path === extractedPath) {
Comment on lines +78 to +96
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to still not work:

  • In the files.filter() call, won't checking file => isFile() prevent getting any dirs (assuming you want to match the wrapping directory)
  • Checking file.name === getExecutableBinaryName() also might not work; in the case of wrapped dirs on macos, the dir name is kit-darwin-amd64 or similar (i.e. not kit). On windows, the binary name is kit.exe which will never match a dir.

Testing locally, I'm seeing failures (in both case, ::error::Failed to find executable binary in extracted archive: <longname>):

  • With latest, the jozu-bin dir contains
    /var/[...]/jozu-bin
    ├── LICENSE
    ├── README.md
    └── kit
    
  • With v0.1.3, the jozu-bin dir contains
    /var/[...]/jozu-bin
    └── kitops-darwin-arm64
        ├── LICENSE
        ├── README.md
        └── kit
    

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking locally, I don't know if

  const extractedDir = path.dirname(extractedPath)

is correct -- on my system, extractedPath is /var/[...]/T/jozu-bin, so taking the dirname gives /var/[...]/T/, which will not contain the extracted files.

return extractedPath
} else {
ghCore.debug(
`Moving ${path.join(kitExecutable[0].path, kitExecutable[0].name)} to ${path.join(extractedPath, kitExecutable[0].name)}`
)
fs.renameSync(
path.join(kitExecutable[0].path, kitExecutable[0].name),
path.join(extractedPath, kitExecutable[0].name)
)
return extractedPath
}
}

function filterAssetsByOS(file: KitArchiveFile): boolean {
Expand Down
Loading