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 #6

Closed
wants to merge 4 commits into from
Closed

Conversation

nikolai-laevskii
Copy link

This helper 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 { retrieveArchive } from '@actions/helpers/archive-extractor'

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

/** Or with additional options **/
const archive = await retrieveArchive('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 { retrieveArchive, isTarArchive } from '@actions/helpers/archive-extractor'

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

const archive = await retrieveArchive('https://archiveurl')
let extPath: string;

// This will allow to pass parameters specific for extractTar method
if (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 retrieveArchive('https://archiveurl', { type: 'tar' })
const extPath  = await archive.extract(undefined, ['xz', '--strip', '1'])

@nikolai-laevskii
Copy link
Author

actions#1552

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.

3 participants