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

Add archive extractor to @actions/tool-cache #1552

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

nikolai-laevskii
Copy link
Contributor

A helper that adds a thin wrapper around toolkit cache methods extractZip, extractTar, extract7z, extractXar and downloadTool. Allows to download archive from remote source, automatically detect its type and apply appropriate utility for extraction. This allows consistent and predictable archive processing which is much necessary within setup-actions.

Basic usage:

import {Archive} from '@actions/tool-cache'

const archive = await Archive.retrieve('https://archiveurl')
const extPath = await archive.extract()

/** Or with additional options **/
const archive = await Archive.retrieve('https://downloadurl', {
  type: 'zip', // archive type can be specified right away
  downloadPath: 'C:\\some\arbitrary\path', // download folder can also be specified
  /* auth and headers parameters work exactly like in downloadTool: */
  auth: 'token',
  headers: {
     accept: 'application/zip'
  }
});

Narrowing down archive types:

import {Archive} from '@actions/tool-cache'

/** Option 1: narrowing down with typeguards **/

const archive = await Archive.retrieve('https://archiveurl')
let extPath: string;

// This will allow to pass parameters specific for extractTar method
if (Archive.isTarArchive(archive)) {
  extPath = await archive.extract(undefined, ['xz', '--strip', '1'])
}

/** Option 2: narrowing down manually, this way autodetection of archive type is disabled **/

const archive = await Archive.retrieve('https://archiveurl', { type: 'tar' })
const extPath  = await archive.extract(undefined, ['xz', '--strip', '1'])

@nikolai-laevskii nikolai-laevskii requested a review from a team as a code owner October 9, 2023 04:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants