From e861c572e4bcf5fc6e016e4b90bc06cb3f05c555 Mon Sep 17 00:00:00 2001 From: Radu M Date: Fri, 4 Jun 2021 15:22:59 -0700 Subject: [PATCH] Add support for .tgz and .tar.xz archives Signed-off-by: Radu M --- README.md | 12 +++++----- package-lock.json | 2 +- package.json | 2 +- src/configurator.ts | 21 ++++++++++++++++-- test/action.ts | 54 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 8698e9b..230e2a3 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ jobs: pathInArchive: "windows-amd64/helm.exe", } steps: - - uses: engineerd/configurator@v0.0.7 + - uses: engineerd/configurator@v0.0.8 with: name: ${{ matrix.config.name }} url: ${{ matrix.config.url }} @@ -115,7 +115,7 @@ jobs: pathInArchive: "windows-amd64/helm.exe", } steps: - - uses: engineerd/configurator@v0.0.7 + - uses: engineerd/configurator@v0.0.8 with: name: ${{ matrix.config.name }} pathInArchive: ${{ matrix.config.pathInArchive }} @@ -138,7 +138,7 @@ jobs: kind: runs-on: ubuntu-latest steps: - - uses: engineerd/configurator@v0.0.7 + - uses: engineerd/configurator@v0.0.8 with: name: "kind" fromGitHubReleases: "true" @@ -165,7 +165,7 @@ jobs: kind: runs-on: ubuntu-latest steps: - - uses: engineerd/configurator@v0.0.7 + - uses: engineerd/configurator@v0.0.8 with: name: "kind" url: "https://github.com/kubernetes-sigs/kind/releases/download/v0.8.1/kind-linux-amd64" @@ -185,7 +185,7 @@ jobs: kind: runs-on: ubuntu-latest steps: - - uses: engineerd/configurator@v0.0.7 + - uses: engineerd/configurator@v0.0.8 with: name: "h3" url: "https://get.helm.sh/helm-v3.3.0-linux-amd64.tar.gz" @@ -206,7 +206,7 @@ jobs: kind: runs-on: windows-latest steps: - - uses: engineerd/configurator@v0.0.7 + - uses: engineerd/configurator@v0.0.8 with: name: "h3.exe" url: "https://get.helm.sh/helm-v3.3.0-windows-amd64.zip" diff --git a/package-lock.json b/package-lock.json index f94ed19..b06651e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "configurator", - "version": "0.0.7", + "version": "0.0.8", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 4c7fddc..5aec6ad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "configurator", - "version": "0.0.7", + "version": "0.0.8", "private": true, "description": "A GitHub Action that configures statically compiled tools", "main": "lib/main.js", diff --git a/src/configurator.ts b/src/configurator.ts index 2db180d..6ad3e62 100644 --- a/src/configurator.ts +++ b/src/configurator.ts @@ -6,7 +6,7 @@ import * as path from "path"; import * as os from "os"; import { getTag } from "./release"; import Mustache from "mustache"; -import { v4 as uuidv4 } from 'uuid'; +import { v4 as uuidv4 } from "uuid"; const NameInput: string = "name"; const URLInput: string = "url"; @@ -81,7 +81,10 @@ export class Configurator { ); const rawVersion = tag.startsWith("v") ? tag.substr(1) : tag; - downloadURL = Mustache.render(this.urlTemplate, { version: tag, rawVersion: rawVersion }); + downloadURL = Mustache.render(this.urlTemplate, { + version: tag, + rawVersion: rawVersion, + }); } else { downloadURL = this.url; } @@ -105,6 +108,16 @@ export class Configurator { await this.moveToPath(path.join(archivePath, this.pathInArchive)); break; + case ArchiveType.TarXz: + archivePath = await tc.extractTar(downloadPath, tempDir, "x"); + await this.moveToPath(path.join(archivePath, this.pathInArchive)); + break; + + case ArchiveType.Tgz: + archivePath = await tc.extractTar(downloadPath, tempDir); + await this.moveToPath(path.join(archivePath, this.pathInArchive)); + break; + case ArchiveType.Zip: archivePath = await tc.extractZip(downloadPath, tempDir); await this.moveToPath(path.join(archivePath, this.pathInArchive)); @@ -180,6 +193,8 @@ export class Configurator { export function getArchiveType(downloadURL: string): ArchiveType { if (downloadURL.endsWith(ArchiveType.TarGz)) return ArchiveType.TarGz; + if (downloadURL.endsWith(ArchiveType.TarXz)) return ArchiveType.TarXz; + if (downloadURL.endsWith(ArchiveType.Tgz)) return ArchiveType.Tgz; if (downloadURL.endsWith(ArchiveType.Zip)) return ArchiveType.Zip; if (downloadURL.endsWith(ArchiveType.SevenZ)) return ArchiveType.SevenZ; @@ -205,6 +220,8 @@ export function binPath(): string { export enum ArchiveType { None = "", TarGz = ".tar.gz", + TarXz = ".tar.xz", + Tgz = ".tgz", Zip = ".zip", SevenZ = ".7z", } diff --git a/test/action.ts b/test/action.ts index 4c707e3..7b45290 100644 --- a/test/action.ts +++ b/test/action.ts @@ -47,6 +47,20 @@ describe("test archive type", () => { assert.equal(cfg.ArchiveType.TarGz, cfg.getArchiveType(c.url)); }); + it("correctly chooses the TAR.XZ archive type", () => { + const archiveTypeTarInput = { + INPUT_NAME: "some-binary", + INPUT_PATHINARCHIVE: "some-path", + INPUT_URL: + "https://github.com//releases/download//some-tar-archive.tar.xz", + }; + for (const key in archiveTypeTarInput) + process.env[key] = archiveTypeTarInput[key]; + + let c = cfg.getConfig(); + assert.equal(cfg.ArchiveType.TarXz, cfg.getArchiveType(c.url)); + }); + it("correctly chooses the ZIP archive type", () => { const archiveTypeZipInput = { INPUT_NAME: "some-binary", @@ -116,6 +130,46 @@ describe("test URL download", async () => { assert.equal(fs.existsSync(path.join(cfg.binPath(), c.name)), true); }); + it("correctly downloads .tar.xz files", async () => { + if (process.platform === "win32") { + // there seems to be an error with the tar utility on Windows - skipping the test for now + return; + } + + const input = { + INPUT_URL: + "https://github.com/bytecodealliance/wasmtime/releases/download/v0.27.0/wasmtime-v0.27.0-x86_64-linux.tar.xz", + INPUT_NAME: "wasmtime", + INPUT_PATHINARCHIVE: "wasmtime-v0.27.0-x86_64-linux/wasmtime", + }; + for (const key in input) process.env[key] = input[key]; + + let c = cfg.getConfig(); + await c.configure(); + + assert.equal(fs.existsSync(path.join(cfg.binPath(), c.name)), true); + }); + + it("correctly downloads .tgz files", async () => { + if (process.platform === "win32") { + // there seems to be an error with the tar utility on Windows - skipping the test for now + return; + } + + const input = { + INPUT_URL: + "https://github.com/vmware-tanzu/buildkit-cli-for-kubectl/releases/download/v0.1.3/linux-v0.1.3.tgz", + INPUT_NAME: "kubectl-buildkit", + INPUT_PATHINARCHIVE: "kubectl-buildkit", + }; + for (const key in input) process.env[key] = input[key]; + + let c = cfg.getConfig(); + await c.configure(); + + assert.equal(fs.existsSync(path.join(cfg.binPath(), c.name)), true); + }); + it("correctly downloads .zip files", async () => { const input = { INPUT_URL: "https://get.helm.sh/helm-v3.0.0-beta.3-windows-amd64.zip",